Saturday Nov 03, 2012

Maven Hierarchical View for NetBeans IDE 7.2

Started working on an oft-heard request from Kirk Pepperdine for an integrated view for multimodule builds for Maven projects in NetBeans IDE, as explained here. I suddenly had some kind of brainwave and solved all the remaining problems I had, by delegating to the LogicalViewProvider's node, instead of the project's node, which means I inherit all the icons, actions, package nodes, and anything else that was originally defined within the original project, in this case for the open source JAnnocessor project:

Above, you can see that the Maven submodules can either be edited in-line, i.e., within the parent project, or separately, by opening them in the traditional NetBeans way.

Get the module here:

Some people out there might be interested in how this is achieved. First, hide the original ModulesNodeFactory in the layer. Then create the following class, which creates what you see in the screenshot above:

import java.util.ArrayList;
import java.util.List;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.spi.project.SubprojectProvider;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;

@NodeFactory.Registration(projectType = "org-netbeans-modules-maven", position = 400)
public class ModulesNodeFactory2 implements NodeFactory {

    public NodeList<?> createNodes(Project prjct) {
        return new MavenModulesNodeList(prjct);

    private class MavenModulesNodeList implements NodeList<Project> {

        private final Project project;

        public MavenModulesNodeList(Project prjct) {
            this.project = prjct;

        public List<Project> keys() {
            return new ArrayList<Project> (project.getLookup().

        public Node node(final Project project) {
            Node node = project.getLookup().
            return new FilterNode(node, new FilterNode.Children(node));

        public void addChangeListener(ChangeListener cl) {

        public void removeChangeListener(ChangeListener cl) {

        public void addNotify() {

        public void removeNotify() {

Considering that there's only about three actual statements above, it's pretty amazing how much can be achieved with so little code. The NetBeans APIs really are very cool.

Hope you like it, Kirk!


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« November 2012 »