Geertjan's Blog

  • October 26, 2006

Easy extensions to your development environment...

Geertjan Wielenga
Product Manager
...even for beginners. Before beginning to work on documentation for NetBeans module development, I'd always assumed that creating modules (i.e., plugins) for NetBeans was hard, requiring some kind of advanced knowledge of Java and NetBeans. However, since then, I've discovered that's not the case at all. In fact, creating a plugin for NetBeans is many times simpler than, for example, creating a web application. And I don't mean the part where you use a wizard to create the project structure (which is easy in all cases), but the part where things actually become useful... the functionality itself.

I realized this very concretely again, today. We're using a DocBook module (made by Jesse and Tim), which integrates DocBook into NetBeans. For example, a DocBook book is recognized as a project, there are templates for chapters, and you can use a menu item to convert either the whole book or individual chapters to HTML. However, there are things missing. There are always things missing! In this case, filling in the gaps was easy. Whenever I wanted to make a piece of text bold, for whatever reason, I had to manually add the <command> tag before the selection and the </command> afterwards. Too much work! I'd much rather right-click on a word, or a selection of words, and choose "Make Bold". Well, that's exactly what I now have. And...

...it took no more than three lines of code:

JTextComponent editor = Registry.getMostActiveComponent();
String selection = editor.getSelectedText();
editor.replaceSelection("<command>" + selection + "</command>");

A lot of other stuff was needed, but in each case it was generated by the IDE. For example, the Java class that provides the menu item was generated by a wizard. It contained skeleton methods, including "performAction". And the above three lines was all I needed to stick in that "performAction". The wizard also added registration entries into the XML Layer file, so that the menu item appears in the right-click popup menu for files of the MIME type that I'm using for the DocBook chapters. And then I just installed the whole module again, into the same development IDE I had been using to write the DocBook chapters. And then, straight away, I was able to use the module I had made.

Pretty cool. I'm hoping more and more non-module developers who are NetBeans users begin realizing the power of module development in NetBeans. In many cases, creating a little module like the above could be a standard part of the development process. You might be creating a web application, for example, and then think: "Wouldn't it be cool if NetBeans was able to do XYZ?" And then, without thinking further about it, you'd use the same Java development skills you needed for creating the web application to create a module to provide the functionality you're missing. Not all functionality can be provided by a small module like this one, of course. But, on the other hand, you'd be surprised how much can be done in this way, with small modules created on the fly in the middle of some totally random development process.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.