Skip navigation

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! 🙂

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: