Intro.

I’ve used Eclipse in one form or another for a long, long time now.  Mostly in it’s NDS/NWDS guise it has always had a certain number of “features” that can drive you round the bend.  Often, the easy way to fix many issues is by performing a simple re-start of the software itself – my colleagues often have me shouting at them if they come to me with an NWDS issue and haven’t restarted it before asking for help ????

Anyway, I thought I’d add a few hints and tips that make my life easier with NWDS/Eclipse and could be useful as more and more people turn to it for UI5 development.  Really, for me it is all about simplicity when typing code and I’ve got into a nice workflow with how I use NWDS/Eclipse for editing Java/JavaScript type files.  Of course, like with many things YMMV…

As a certain global burger chain used to say, have it your way

If you’ve spent any time at all looking at the Windows->Preferences options of Eclipse/NWDS you will see there are lots of settings to meddle with.  Many are Eclipse centric but also, as you add other software such as SAPUI5, ABAP, HANA, CE, etc plus other random plugins you quickly get a lot of options to make the software work your way.  I’d recommend you take a decent chunk of time to work through all of the options and see what they can do.  Here’s my starter for 10:-

  • Under General->Editors->Text Editors increase the “Undo history size” from 200 to 500.  This usually works even after a file has been saved and can get you out of disasters!
  • Under General->Keys put some effort into setting your personal shortcut keys.  As you use Eclipse more and more, you’ll quickly get the benefit of being able to quickly use the keyboard to achieve common tasks and functions, instead of reaching for the mouse and navigating around menus.  One of my favourites to assign a simple shortcut (instead of the default) is the Refactor->Rename option:
    • In Java or JavaScript, click on a defined variable and Eclipse will highlight instances of it (here I’ve clicked on the first “hdrHTML” instance:
    • Now right-click on one of these instances and choose Refactor->Rename and you will see this:
    • You can now simply delete, change and update the object name and when you hit enter, all identified instances are changed as one – it’s like an intelligent search and replace
  • Refactor->Extract Function(JavaScript)/Extract Method(Java)
    • This is a step on from the above rename option, which allows you to pull out code where you have say a complex single line and create sub-functions that are simpler to edit, debug and code.  Say I start with this pretty basic Java class:

      This is pretty odd code I’ve just written to prove a point, it makes no real logical sense!  The final else-if condition is a bit more complex than the others and could benefit from being a standalone method in it’s own right.  So I select it, hit right-click and choose Refactor-Extract Method:

      I give the new method a name, choose visibility and set parameter names and hit the OK button (I can hit Preview > too if I want to see what Eclipse is going to try and do first but I find just doing it and relying on Undo is just as good ???? )  I’m left with this new & improved code:

      Ok, in this particular scenario it isn’t the greatest improvement but if you had a real-life example with more complex nested code, or you were editing a simple bit of code and it was quickly becoming more complex and difficult to read, this is a great way of modularising and tidying things up.
  • For both Java & JavaScript nodes:
    • Editor->Content Assist – choose “Insert best guessed arguments”/”Guess filled function arguments”.  This means that the code complete will try to guess the correct object to insert when you use auto-complete, at the same time I also lower the Auto-Activation delay down to 10ms as I just prefer it to kick in almost instantly:

      This means I can type something like:
      String myStr = new String("Some text"); myOtherObject.setStri

      When I then press CTRL-space, it will auto complete with the correct object name – a small thing but a great help when you are writing lots of code:

      myOtherObject.setString(myStr);
    • Editor->Save Actions – activate the “Perform the selected actions on save” option and as a minimum, I’d recommend you select to “Format source code” (you can change how this works elsewhere in the preferences.)  For Java I also perform an “Organize imports” – you can extend this function with other actions you want performed whenever you save a file.  With the increased undo buffer mentioned above, it allows you to quickly change, save and then undo code as needed
    • Editor->Typing – activate both “Semicolons” & “Braces” underneath “Automatically insert at correct position”, which at first will feel a little strange as you can essentially hit the ; button anywhere in your line of code and it appears auto-magically at the end but once you are used to it, I feel it greatly increases speed when coding:

Aside from these couple of Preferences tweaks, given UI5 makes use of ResourceBundles as properties files, I remembered a plugin I used years ago to help out with translations in an SAP CRM ISA WebShop installation I worked on – you can download it from here.  It is a simple tool but for me, makes working with ResourceBundles that bit less painful as it gives a much nicer UI to handling the files.  Download the zip from Sourceforge, extract and copy the correct folder into the plugins folder within your Eclipse installation.  You are then able to right click on your “i18n.properties” file and Open With -> Resource Bundle Editor, which gives you this view:

Wrap-up

Whilst I appreciate many will simply not like the complex nature of Eclipse and its many “features” I find with perseverance you can make it work in a really productive manner.  Sublime Text is another favourite tool but for me, NWDS supports CE, PO, BPM, BRM, WD, ABAP, etc. hence I’d prefer to put efforts into making it work as I want, instead of using different tools for different jobs.

One final tip – don’t forget to use the File->Export->General->Preferences option to save your Eclipse pref’s locally and apply them to any installations you use.

Hope some of this is useful.

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !