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:

http://plugins.netbeans.org/plugin/45180/?show=true

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.netbeans.spi.project.ui.support.NodeFactory;
import org.netbeans.spi.project.ui.support.NodeList;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;

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

    @Override
    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;
        }

        @Override
        public List<Project> keys() {
            return new ArrayList<Project> (project.getLookup().
                lookup(SubprojectProvider.class).getSubprojects());
        }

        @Override
        public Node node(final Project project) {
            Node node = project.getLookup().
                lookup(LogicalViewProvider.class).createLogicalView();
            return new FilterNode(node, new FilterNode.Children(node));
        }

        @Override
        public void addChangeListener(ChangeListener cl) {
        }

        @Override
        public void removeChangeListener(ChangeListener cl) {
        }

        @Override
        public void addNotify() {
        }

        @Override
        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!

Comments:

Oho. Very very nice. Good job.

Posted by guest on November 03, 2012 at 06:49 AM PDT #

Hi Geertjan,

This looks very promising, but in my 7.2.1 IDE, the following dependencies are not met:

Some plugins require plugin Project API to be installed.
The plugin Project API is requested in version >= 1.47.1 but only 1.46.1 was found. The following plugin is affected:       MavenModulesNodeFactory
Some plugins require plugin Project UI API to be installed.
The plugin Project UI API is requested in version >= 1.61.1.8 but only 1.57.1.8 was found. The following plugin is affected:       MavenModulesNodeFactory
Some plugins require plugin File System API to be installed.
The plugin File System API is requested in version >= 8.1.1 but only 7.62.1 was found. The following plugin is affected:       MavenModulesNodeFactory
Some plugins require plugin Datasystems API to be installed.
The plugin Datasystems API is requested in version >= 7.39.1 but only 7.37.3 was found. The following plugin is affected:       MavenModulesNodeFactory
Some plugins require plugin Nodes API to be installed.
The plugin Nodes API is requested in version >= 7.29.1 but only 7.28.1 was found. The following plugin is affected:       MavenModulesNodeFactory
Some plugins require plugin Utilities API to be installed.
The plugin Utilities API is requested in version >= 8.26.1 but only 8.25.2 was found. The following plugin is affected:       MavenModulesNodeFactory
Some plugins require plugin Lookup API to be installed.
The plugin Lookup API is requested in version >= 8.17.1 but only 8.15.2 was found. The following plugin is affected:       MavenModulesNodeFactory Some plugins not installed to avoid potential installation problems.

It looks like your build environment is a bit newer than mine, although I have the latest official release...

Could you please tell me how to fix this?

Posted by vdtoorn on November 05, 2012 at 02:38 AM PST #

It's for 7.3 Beta.

Posted by Geertjan on November 05, 2012 at 05:30 AM PST #

I love it! Thanks for the great plugin. I work with several multi module projects all the time and this is a great feature that would be nice to have in the standard IDE. Just a few suggestions:

1. Please sort the modules alphabetically by project name.
2. Aggegator pom modules aren't being shown (bug?)
3. I would expect sub-modules that belong to aggregator modules to be listed under the aggregator module. For example, with the following project structure:

example/
----pom.xml (example:pom)
----admin/
--------pom.xml (example-admin:pom)
--------qa/
------------pom.xml (example-admin-qa:jar)
--------web/
------------pom.xml (example-admin-web:war)
----ui/
--------pom.xml (example-ui:pom)
--------qa/
------------pom.xml (example-ui-qa:jar)
--------web/
------------pom.xml (example-ui-web:war)
----ws/
--------pom.xml (example-ws:pom)
--------api/
------------pom.xml (example-ws-api:jar)
--------qa/
------------pom.xml (example-ws-qa:jar)
--------web/
------------pom.xml (example-ws-web:war)

I would expect the Projects view to show up something like the following:

+ example
---- + example-admin
---------- example-admin-qa
---------- example-admin-web
---- + example-ui
---------- example-ui-qa
---------- example-ui-web
---- + example-ws
---------- example-ws-api
---------- example-ws-qa
---------- example-ws-web

Posted by guest on November 05, 2012 at 11:19 AM PST #

Hi Geertjan

Is there a feature request for something like this? It would definitely get my vote.

Posted by Tim Sparg on November 06, 2012 at 04:20 AM PST #

guest's #2 & #3 are because you are not directly inspecting the Maven metadata but rather using SubprojectProvider, which just offers a set of non-POM projects…as well as some other stuff which would be entirely inappropriate here, such as known source projects for classpath dependencies of these projects. Needs to be rewritten to refer directly to the Maven model.

Anyway this is cute but not terribly useful without basic changes in projectuiapi, since you either have to open these submodules as well—in which case you have a duplicated view—or try to use them unopened, which will work to some extent but not so well (e.g. most refactoring operations will be unavailable while editing).

Posted by Jesse Glick on November 06, 2012 at 06:23 AM PST #

Hi Geertjan, this is extremely useful. Can this be part of the next Netbeans release? I think it should be the default behavior. Thanks.

Posted by Mathieu on November 08, 2012 at 06:52 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today