Friday Sep 06, 2013

Eclipse Formatter for NetBeans IDE (Part 2)

Judging by the many comments received, after I announced the work being done on the Eclipse Formatter for NetBeans IDE, in my blog and via e-mail, as well as via Twitter, there's really quite a lot of interest in this plugin. NetBeans users working in scenarios where some of their colleagues use Eclipse will find this plugin particularly useful since now organization-wide formatting rules can be shared for the first time ever.

While vacationing in France (near Joncy, which is a tiny place more or less near Buxy, which is itself a tiny place too, the past week, as well as the coming week), I've managed to make a bit of progress. Based on the comments I've received so far, users want this combination of support for Eclipse formatting in NetBeans IDE:

  • Global Eclipse Formatter. In the Options window, the user should be able to define (i.e., by selecting on disk) an Eclipse formatter XML file which, when formatting is done (via Source | Format and the keybinding Alt-Shift-F, as well as via related actions, such as Refactor | Inspect & Transform, and on saving), the Eclipse formatter should be used instead of the NetBeans formatter.

  • Project-Level Eclipse Formatter. In the Project Properties dialog of each project, the user should be able to define an Eclipse formatter to be used for the project, i.e., overriding the global Eclipse formatter.

  • NetBeans Formatter. The user should be able to (1) globally, i.e., via the Options winow, switch off the global Eclipse formatter, so that the NetBeans formatter is used instead and (2) for each project, the user should be able to switch off either the global or the project-level Eclipse formatter, so that the NetBeans formatter is used when formatting is done for a particular project.

In short, the user should be able to switch on/off and override the Eclipse formatter, globally and on project-level.

These, as I understand them, are the requirements. And, once configured, the formatter (whatever it happens to be for the current context) should behave absolutely seamlessly in exactly the same way, without complicated manoeuvres and additional steps.

Global Support

So, using these requirements, here's the Options window showing how/where to define the global Eclipse formatter:

Note that one can disable the global Eclipse formatter, via "Define global Eclipse formatter". Once that checkbox is unchecked, the NetBeans formatter is used globally, instead of the Eclipse formatter defined above. However, even though it is disabled, the global Eclipse formatter is still available, it simply needs to be reenabled to become active again.

There's also the "Show Debug Information" checkbox which, when checked, shows a balloon message (and note that all balloon messages are gathered into the new Notifications window in NetBeans IDE 7.4) whenever a formatting action is performed, showing which formatter was used to do the formatting. Handy to debug things when you're not getting the formatting results you'd like, to see which of your various formatters has been most recently used.

Finally, note that the text area above, as well as in the screenshot below, is not editable. It only serves to show the content of the selected Eclipse formatter XML file.

Project-Level Support

For each project, the Project Properties dialog lets you specify (1) whether a different Eclipse formatter should be used for this particular project or (2) whether for this particular project the NetBeans formatter should be used instead of the global Eclipse formatter:

Note that the two checkboxes in the screenshot above cannot be checked at the same time. I.e., if one is checked when you check the other one, the first is automatically unchecked. Makes sense because either you're overriding the global Eclipse formatter with your local one or you're wanting to use the NetBeans formatter, not both at the same time.


All of the above actually works right now. Just my bandwidth is too low (remember, I'm in Joncy, somewhere in the middle of France, with cows, wine, and medieval churches, i.e., bandwith is not a primary concern in these parts of the world) to upload it to the Plugin Portal. Hence, you're welcome to try the Eclipse formatter in NetBeans IDE, but note that none of the screenshots above are reflected in the plugin you'll find here, currently:

The above link points, at the time of writing, to the 1.2 version of the plugin, which is used exactly as defined in the original blog entry about this plugin.

Nonetheless, at random times of the day I can get on-line, so looking forward to any comments anyone might have on my progress.

Update 31 October 2013: See part 3 here.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« September 2013 »