Skip to Content

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:
      Eclipse4.png
    • Now right-click on one of these instances and choose Refactor->Rename and you will see this:
      Eclipse5.png
    • 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:
      Eclipse6.png
      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:
      Eclipse7.png
      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:
      Eclipse8.png
      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:
      Eclipse1.png
      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:
      Eclipse2.png

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:

Eclipse3.png

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.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Jason Moors

    Hi Gareth,

    Interesting blog, agree with the sentiment, as developers we need to know how to use the tools at our disposal. I watched an entertaining talk by Paul Irish where he said you need to be rabid about your tools… select a few tools and know them well.

    http://randsinrepose.com/archives/the-foamy-rules-for-rabid-tools/

    Having been a Java developer for more years than I care to remember, and used multiple incarnations of Eclipse and NDWS, I find myself moving away more and more from Eclipse. I now use Sublime and number of plugins, and if I need to integrate with SAP, then it’s only light touch, check in/out and activate files etc.

    I think it’s biggest problem is isn’t responsiveness, even with a top spec macbook it still hangs.

    Thanks,

    Jason

    (0) 
    1. Gareth Ryan Post author

      Thanks for the comments Jason.

      I’m not sure if it is sheer bloody-mindedness or morbid curiosity but over the years I’ve put a lot of time into figuring out how best to use NWDS/Eclipse.  Don’t get me wrong, it still drives me round the bend on a daily basis!

      Your comment about responsiveness is a fair one – I run a quad-core i7-3740QM with 8Gb laptop and I still have issues on too often an occasion.  I know there are memory tweaks you can perform but I’ve never really had great success with these, in terms of fully eradicating the issues.

      I’ve tried Sublime over and over again and just can’t get to a point I’m happy with it – I suspect because I’d have to go back to first principles and re-learn the tool from scratch and I’ve already invested too much time in Eclipse for that!

      Cheers,

      Gareth.

      (0) 

Leave a Reply