Geertjan's Blog

  • April 23, 2007

Adding Nodes to an Existing Project Type's Logical View

Geertjan Wielenga
Product Manager
Since a few weeks, it's been possible to add new nodes to an existing NetBeans project type's logical view. Thanks to Milos Kleint, who created this functionality, I found out how to implement it. Take the steps below, as a kind of "hello world" experience.

  1. Create a new project called "foo" with code name base "org.netbeans.foo".

  2. In the layer, specify where you want the node to appear, i.e., which project you want to extend.

    <folder name="Projects">
    <folder name="org-netbeans-modules-java-j2seproject">
    <folder name="Nodes">
    <file name="org-netbeans-foo-NodeFactoryImpl.instance"/>

    Note that when you expand the Important Files node, then the XML Layer node, and then the "this layer in context" node, you can see a long list of new nodes under the "Projects" node, each representing a different project type. In 5.5, only the "Actions" node was shown under the "Projects" node.

    The above view is extremely useful, because without needing any documentation you can now immediately see the required names of the other project types for use within the XML layer. As always in this visual representation, our own changes, coming from our XML layer, are shown in bold. So, above it is clear we will be adding a new node to the org-netbeans-modules-java-j2seproject project type, which is the Java SE project type.

    Notice also that there are two other nodes, aside from "Nodes", one called "Customizer" and one called "Lookup". This means you can extend an existing project's customizer (Project Properties dialog box) and Lookup. Both will be discussed in future blog entries.

  3. Set source level to 1.5 and declare dependencies on Nodes API, Project API, Project UI API, and Utilities API.

    Create the class referred to above in the layer and fill it out as follows:

    public class NodeFactoryImpl implements NodeFactory {
    public NodeFactoryImpl() {
    public NodeList createNodes(Project arg0) {
    AbstractNode nd = new AbstractNode(Children.LEAF);
    nd.setDisplayName("Hello World!");
    return NodeFactorySupport.fixedNodeList(nd);

    For details on the above, see NodeFactory in the NetBeans Javadoc.

    Install the module and see your new node:

  4. You want the node to appear somewhere else? Go back to the visual representation of the XML file and drag the node that you created in the XML layer somewhere else:

    Install the module again... and now the node has been moved:

It's as simple as that...

Join the discussion

Comments ( 5 )
  • Rohan Ranade Monday, April 23, 2007
    This is a GodSend!
    J2SEProject should have been more like a framework to build java based projects. Somewhat like the WebProject infrastructure. It seems to be getting there slowly. But for people like me, having to write modules for 5.5, it's still lot of pain studying the J2SEProject code and copying it (especially the classpath infrastructure).
    This is great stuff! Thanks for sharing this. :)
  • Geertjan Tuesday, April 24, 2007
    Thanks Rohan. In 6.0, the idea is that you're now able to extend existing project types, so that you don't need to create your own. Or at least there should be less reason to create your own, since you can adapt one of the existing ones.
  • Vadiraj Thursday, January 17, 2008

    Hi Geertjan,

    Really nice tutorial to extend the existing project types! Thanks for posting this.

    I have tried to follow this to extend the project customizer for J2SE projects and it doesn't work for me.. Can you please help? I have a small sample module that I can share with you.


  • Iliyan Jeliazkov Monday, April 28, 2008

    Hi Geertjan,

    Great tutorial - thanks! I'm implementing my own project type but at the same time I'd like to take advantage of as much as possible from the framework.

    Could one just "plug-in" its Customizers, Nodes and Lookups registered in the above SF directory structure and have NB automatically instantiate them as needed? (without coding explicit implementations for ProjectFactory, Project, etc.)

    Where would such approach (if possible) be documented?



  • Geertjan Monday, April 28, 2008
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.