Skip navigation

Monthly Archives: August 2006

Projects are at the heart of Netbeans and there are tonnes of Project types in Netbeans for different types of programming needs in Java. You have a project type in Netbeans for writing a Java Application, one for a class library and some project types for web applications and if you ever get so lucky (like me) to code some netbeans modules, you will be using project types for creating netbeans modules! Whats more, you can create your own project types.

Anybody who even dreams of writing custom project types in Netbeans has to read the excellent Pov Ray support in Netbeans tutorial series by Tim Boudreau. In Part 4 of the 10 part series, Tim creates a custom project for rendering Pov Ray files in Netbeans, and creates a file type for a Pov Ray file (*.pov, *.inc). So far so good. But when I ran the code (whatever I had written as per Tim’s instuctions till Part 4), I got this little itch.

You see, imagine this…. “A Pov Ray project user will typically create Pov Ray files – and for that he has to right click on the Pov Ray project node, Select “New” -> File/Folder option and then navigate to the “Other” files category and finally click on the Pov Ray file type to create a Pov Ray file”. Hmm.. too many steps.

Now when I do normal Java Applications in Netbeans, whenever I want to create a new File or Folder (mostly a Java class), the IDE displays a list of typical file types (Java class being one of them). That was missing from my Pov Ray project. I wanted to register the Pov Ray file type as a “favourite” file type for my Pov Ray project, so that it would appear in the “New” menu.

After some javadoc hunting, I found out how to go about this. The interface “org.netbeans.spi.project.ui.PrivilegedTemplates” is the solution. As the JavaDoc states, an implementation of this interface provides “List of templates which should be in the initial “privileged” list when making a new file.”

Create a class which implements the PriviledgedTemplates class. For my project, I wrote a PovrayFileTypes class as shown below. Watch the getPriviledgedTemplates() method. It states the file templates that should be priviledged for the project type.

1 package org.netbeans.examples.modules.povproject; 2 3 import org.netbeans.spi.project.ui.PrivilegedTemplates; 4 5 /** 6 * 7 * @author Rohan Ranade 8 */ 9 public class PovrayFileTypes implements PrivilegedTemplates { 10 11 public String[] getPrivilegedTemplates() { 12 String[] trialTypes = { Templates/XML/XMLDocument.xml, 13 Templates/XML/emptyDTD.dtd, 14 Templates/Other/PovrayTemplate.pov, 15 }; 16 17 return trialTypes; 18 } 19 20 }

Now add this to the project’s lookup: 

1 private Lookup lkp; 2 public Lookup getLookup() { 3 if(lkp == null) { 4 lkp = Lookups.fixed(new Object[] { 5 this, 6 state, 7 new ActionProviderImpl(), 8 loadProperties(), 9 new Info(), 10 logicalView, 11 new MainFileProviderImpl(this), 12 new PovrayFileTypes() 13 }); 14 } 15 16 return lkp; 17 }

Wallah! My Pov Ray file type is now one of the favourites.

One happy user, and one even happier developer! 🙂



Just yesterday, I forwarded my Review Comment Assistant Netbeans plugin (look at the previous post for a description) to Sathish, my team’s Tech Lead. However, after installing the plugin, his Netbeans 5.0 wouldnt start. The splash screen used to come up and then just vanish.

We looked at the startup log and found an issue with my plugin. Now fixing that would take some time, but I wanted to get Sathish’s Netbeans up and running fast. In other words, I wanted to stop Netbeans from loading my plugin during startup.

This is what I did to disable the plugin from loading:

  1. Go to <user_home>/.netbeans/config/Modules
  2. Find <plugin_name>.xml and open it in your editor and change the “enabled” property. The plugin name for my case was com-sun-sps-devtools-commentator and so I fired up gedit and opened com-sun-sps-devtools-commentator.xml and modified the “enabled” property (marked in red box in the figure below) to make it false.
  3. Ran Netbeans, it started without a problem.

When modules are installed by a user, they are typically installed in the <userhome>/.netbeans/modules directory. But a good question is, How are modules registered? How does Netbeans know which modules to load?

Well, Netbeans has a concept of a System Filesystem (more about it here). When modules are installed, an entry of the module is kept in the .netbeans/config/modules directory. This directory is scanned by Netbeans during startup to load all user-installed modules. Changing the enabled property to false, stopped Netbeans from loading my problematic module.

Back to fixing my plugin 🙂 !

I was playing around with the Netbeans API, and used it to create a little review comment collector plugin to record review comments in code.

My team (The N1 Service Provisioning System development team – uses an in house tool developed by one of the team members to do code reviews. This tool is used as a central place to put in all code review comments as the review passes through several phases before check in.

However, the process of entering review comments was getting really out of hand for me. Every review entry would be something like this:

File :
Line: 291
Code: public static void main(String args[]) {
1. Do this
2. Do that

Lot of work to be done for something so simple. Netbeans to the rescue!

Here’s what I do in Netbeans now (with the help of my plugin):

1. Right click on the line where I want to put a review comment:

2. This throws up a dialog box for entering comments:

3. After entering the comments, I press ‘OK’ and the comments get recorded in the Comment Collector Window (top left) and an annotation appears on the line on which the comment was added:

4. I do this for all the files which I have to review. All the comments have now been collected in the Collector window. I now hit the “Export” button to get the whole list of comments ready to copy and paste into our internal review tool.

Time invested on this plugin : 1 day
Time saved : Much much more than 1 day 🙂

Point : Developing Netbeans Plugins is a piece of cake. Thanks to the efforts of the Netbeans team who have done a fabulous job of documenting things and producing a bunch of 5 star tutorials. Just go to !