X

Geertjan's Blog

  • June 16, 2007

Extending the NetBeans API Wizards (Part 1)

Geertjan Wielenga
Product Manager
Discovered a very cool thing—it is extremely easy to add functionality to the NetBeans API wizards. Here's one example. I added an "Enable Visual Library" checkbox to the New Window Component wizard:

When that checkbox is selected, the Visual Library API is declared in the project.xml file, a simple GraphScene implementation class is added to the generated files, and the TopComponent constructor is extended to create the scene (together with a satelitte view). As soon as the wizard is complete, the module can be installed (i.e., nothing extra needs to be done) and one immediately has a simple implementation of a scene, as can be seen here:

How to do this (and other similar changes)? Check out the apisupport/project module from the NetBeans sources. Then find the wizard you want to change. Then... this is the cool bit... you suddenly realize that an entire framework has been set up for you. For example, don't know how to programmatically add dependencies to the project.xml file? It really is simple:

fileChanges.add(fileChanges.addModuleDependency("org.netbeans.api.visual"));

The above would add the Visual Library as a dependency in the project.xml file. How does that work? I don't know. I don't care. I don't need to know or care. I just looked in the iterator, found similar entries for other dependencies, and then just added my own. Similar utility methods exist for adding entries to the layer.xml file and all other supporting resources. Just look through the iterator, find something similar to what you want to do, and then just add your little piece of code.

Of course, the big problem is distribution. Once I've changed the sources in this way, if I want to share this changed wizard with someone else, I need to change the version of the apisupport/project module and then make that incremented version available to others. Since the module is not limited to the file-level wizards, but also the project-level wizards, and everything else, that's a lot to distribute just for a change to a file-level wizard. One other cool thing is that the apisupport/project module is self-contained. It doesn't depend on any other modules in the NetBeans sources. So distributing it as a single NBM file is possible. But, aside from these concerns relating to distribution, I've definitely found a very useful area to explore. Adding new wizards is easy too. Just copy some other wizard, rewrite the (very readable and well structured) code and then bob's your auntie.

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.Captcha