Saturday Jul 21, 2012

Wrapper Project for NetBeans Projects

A great question in this blog by swpalmer recently:

I have a need for a custom project type that is mostly just a parent for existing NB project types for Java(Ant or Maven, soon Gradle) and C++. Think of it like a one project for a Java library that uses JNI and the project for the native library that implements the native methods that go with it. Add a little bit of metadata and some custom packaging steps (currently written with Gradle) and that would be my new project type.

Would making a new parent project type that has subprojects of existing NB project types be an easy thing to implement?

Well, here's a simple example. Imagine you have folders for your customers, each containing multiple NetBeans projects. Would be cool to be able to open all those projects together, as part of a new project defined by some recognized structure in the customer folder:

Then, once open, you can do typical things you'd like to be able to do to multiple projects belonging to a shared container of some kind, such as open the individual projects for separate editing:

Notice that, though the icon is retained from the original NetBeans project, the logical view isn't. I don't think there's a way around that.

The way this works is that the "createLogicalView" override of the Project implementation returns a Node that defines its children as FilterNode.Children, with the icons overridden. That defines the logical view. The ability to open the NetBeans project together with the main project is done via a SubprojectProvider in the Lookup of the main project, which recognizes subfolders containing an "nbproject" folder as a subproject of the main project.

Best of all, I can now create Actions which lookup all the subprojects and then do something with the group of subprojects. Maybe, for example, all the subprojects can be built together or run together or something like that. A higher level container like this can open up a lot of possibilities and isn't hard to create, if you combine the instructions in the above paragraph with the instructions in this tutorial:

Finally, if the customer project in the screenshots above were to be a Gradle project, then I think the question with which this blog entry started would be resolved. 


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.


« July 2012 »