Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Adding New Tabs to the Project Properties Dialog in NetBeans IDE

DZone's Guide to

Adding New Tabs to the Project Properties Dialog in NetBeans IDE

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}