Download NetBeans!

20070731 Tuesday July 31, 2007

Extend an Existing NetBeans Project Type for Grails?

As mentioned in Adding Nodes to an Existing Project Type's Logical View, in 6.0 NetBeans module authors are encouraged to—as far as reasonably possible—extend existing project types, rather than creating new ones. The thinking is that in doing so, there will be more consistency between them. The more new ones that are created, the more potential conflicts there might end up being. Plus, there's no need to reinvent the wheel—you can 'simply' slot your own nodes into the nodes of an existing project type, checking the lookup to determine whether the nodes should be created or not.

So, when thinking about creating a new project type, the first thing you should think is: "Wouldn't it make more sense to extend one that already exists? After all, in 6.0 I can extend an existing project type's logical view, customizer, and lookup... so what is so special about my project type that I can't use one of the existing project types as a starting point?" In this light, have a look at this screenshot, which shows one of the samples that comes with the Grails distribution, which I opened in the IDE, via the 'Open Project' dialog box:

There is still a very long way to go (such as the fact that I can't deploy the application yet), and possibly the approach I've taken is completely wrong (though I've consulted a bit with Milos Kleint, who created the APIs for extending project types), but here one can see the benefits (and potential pitfalls) of extending an existing project type. For example, a benefit is that the server support for my Grails application is baked right into the original web application project type. A pitfall is that that same project type lets the user add support for web frameworks... I doubt that one would want the user to be able to add JSF or Struts or something similar to a Grails application. And, even if one would want that, one would probably want to do so in a different way to standard web applications. (Maybe I should be extending the freeform web application project type instead, which doesn't support web frameworks. Alternatively, maybe I should simply hide the customizer panel for adding web frameworks.) So... as one can see, just from these random ruminations, there is a lot one can gain and a lot one can lose from the ability to extend an existing project type. But Grails is probably an extreme example. Adding web service support or JAXB support to an existing project type is more likely to be the typical use case in this regard. Still, let's see how far I get! And, at the same time, Martin Adamek is taking the new-project-type approach to creating Grails support (in the few seconds per day that he has some free time), so maybe he'll end up with a better end result. It will be interesting to compare the pros and cons in this real life situation.

Jul 31 2007, 09:45:57 AM PDT Permalink