Geertjan is a DZone Zone Leader and has posted 437 posts at DZone. You can read more from them at their website. View Full User Profile

Adding New Tabs to the Project Properties Dialog in NetBeans IDE

02.15.2010
| 3723 views |
  • submit to reddit

Let's extend the Project Properties dialog of an existing project type in NetBeans IDE (or any application on the NetBeans Platform that makes use of the NetBeans IDE's project system):

To achieve the above, we'll create a small NetBeans module with this structure:

Now, for the code. We'll be using the @ProjectCustomizer.CompositeCategoryProvider.Registration annotation for generating layer.xml entries at compile time, which is a new annotation in NetBeans Platform 6.8, therefore the following applies to NetBeans Platform 6.8 only:

import java.util.ResourceBundle;
import javax.swing.JComponent;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;

public class AdditionalJ2SECompositePanelProvider implements ProjectCustomizer.CompositeCategoryProvider {

    private static final String MURPHY1 = "Murphy1";
    private static final String MURPHY2 = "Murphy2";

    @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-java-j2seproject", position = 100)
    public static AdditionalJ2SECompositePanelProvider createMurphy1() {
        return new AdditionalJ2SECompositePanelProvider(MURPHY1);
    }

    @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-java-j2seproject", position = 200)
    public static AdditionalJ2SECompositePanelProvider createMurphy2() {
        return new AdditionalJ2SECompositePanelProvider(MURPHY2);
    }
    private String name;

    private AdditionalJ2SECompositePanelProvider(String name) {
        this.name = name;
    }

    @Override
    public Category createCategory(Lookup lkp) {
        ResourceBundle bundle = NbBundle.getBundle(AdditionalJ2SECompositePanelProvider.class);
        ProjectCustomizer.Category toReturn = null;
        if (MURPHY1.equals(name)) {
            toReturn = ProjectCustomizer.Category.create(
                    MURPHY1,
                    bundle.getString("LBL_Config_Murphy1"),
                    null);
        } else {
            toReturn = ProjectCustomizer.Category.create(
                    MURPHY2,
                    bundle.getString("LBL_Config_Murphy2"), // NOI18N
                    null);
        }
        return toReturn;
    }

    @Override
    public JComponent createComponent(Category category, Lookup lkp) {
        String nm = category.getName();
           if (MURPHY1.equals(nm)) {
            return new NewJPanel1();
        } else {
            return new NewJPanel2();
        }
    }

}
 

Reference is made above to the Bundle file, containing these keys:

LBL_Config_Murphy1=Murphy 1
LBL_Config_Murphy2=Murphy 2

Read the related Javadoc, i.e., the ProjectCustomizer class.

Believe it or not, with very little coding (and no painful layer.xml registrations)... you're done! Run the application and look in the Project Properties dialog of a Java project in NetBeans IDE, since that's the project type for which the above has been registered. There you should see your new tabs.

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Adam Metzler replied on Mon, 2010/02/15 - 2:27pm

This is excelent! This would be great to add a License panel to the project properties, though I have long thought it should also be in the project creation wizard too. I have long for this as I sometimes for get to add the license in the project.properties and then after creating a couple of classes I notice no license header and have to go back and copy and paste, errrh!

Mark Petrovic replied on Tue, 2010/08/03 - 9:37am

Very helpful. I'm new at this: is there a recommended way to add options to the JPanel's (like text field entries or booleans)? And what is the recommended way to get a reference to the JPanel input elements when it comes time to retrieve those properties?

Mark Petrovic replied on Tue, 2010/08/03 - 10:13am

Is using the annotations method mutually exclusive of manually editing, for other purposes, an instance of the layers file? Is there an annotations method for adding new Actions to a J2SE project?

Javier Ortiz replied on Fri, 2012/07/20 - 11:23am

I'm trying to reuse stuff I did with the OptionsPanel wizard in the IDE. It was working fine there but I realized this should be better handled at a project level. So I basiaclly replaced  new NewJPanel1() with new RandoopSettingsPanel(new RandoopSettingsOptionsPanelController()) (the panel created by the wizard. Everything shows fine but for some reason the controller is not storing the property changes when closing the properties window. I guess I'm missing some piping that was hidden with the annotations. Any idea?

Matt Coleman replied on Thu, 2012/08/23 - 12:42am

wow..u can now add more tabs..way cool technique

graphic artist buffalo

Mateo Gomez replied on Thu, 2012/08/23 - 12:50am in response to: Mark Petrovic

yes,,.i hope this can work out coz it be much convenient to add in the jpanel

 mexican dessert recipes

Mateo Gomez replied on Thu, 2012/08/23 - 12:52am

hi Sean,

this is such a wonderful project..i will be checking out your blog.

  mexican dessert recipes

Xavier Figueroa replied on Wed, 2013/02/06 - 7:33pm

Excellent post !

Can you tell me What is the content of NewJPanel1.java and NewJPanel2.java?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.