Geertjan's Blog

  • December 2, 2005

Making Life Even Easier for NetBeans Developers

Geertjan Wielenga
Product Manager
Some developers know exactly what they want when they're creating their application. They don't want to first use a project wizard to create their application and then use the Library Manager to select the libraries they need. For these people, wouldn't it be cool if all the libraries were to be available in the Frameworks panel? (Currently, this additional panel is only available in the Web Application wizard.) And, if you think of web frameworks as consisting of a library (JSF, Struts, whatever) that contains JARs, together with some IDE-specific support for how the libraries are used (syntax highlighting, code completion, samples, etc), then the Frameworks panel in the Web Application project template is already a Libraries panel. So, instead of only making a new library available in the Library Manager, one should also—if one agrees with this thinking—make it available to the Frameworks panel (and then hope that in the next release, the title 'Frameworks' changes to 'Frameworks and Libraries').

To make this happen, the code required is truly minimal. Here's my projects window, and the only additional file required is selected:

The rest of the files you see above are (1) Bundle.properties, which contains this module's localization strings that will be displayed in the Frameworks panel; (2) layer.xml, which has this content for registering the WicketFrameworkProvider.java class in the NetBeans system:

<folder name="j2ee">
<folder name="webtier">
<folder name="framework">
<file name="org-netbeans-modules-wicketsupport-WicketFrameworkProvider.instance"/>

Finally, you see (3) wicket.xml, which is the J2SE library descriptor, an XML file, which registers the Wicket libraries in the Library Manager. (For information on this file, and the Library Manager registration process in general, see NetBeans Project Template Module Tutorial).

So, the only file that needs a little bit of explanation is WicketFrameworkProvider.java. Here it is, in an absolutely simple implementation (since all it does is provide libraries). Below, all the method declarations are in bold, to (hopefully) make things more legible:

public class WicketFrameworkProvider extends WebFrameworkProvider {
public WicketFrameworkProvider() {
NbBundle.getMessage(WicketFrameworkProvider.class, "Wicket_Name"),
NbBundle.getMessage(WicketFrameworkProvider.class, "Wicket_Description")); }
public Set extend(WebModule webModule) {
FileObject fo = webModule.getDocumentBase();
Project project = FileOwnerQuery.getOwner(fo);
Library lib = LibraryManager.getDefault().getLibrary("wicket");
if (lib != null) {
ProjectClassPathExtender cpExtender
= (ProjectClassPathExtender) project.getLookup().lookup(ProjectClassPathExtender.class);
if (cpExtender != null) {
try {
} catch (IOException ioe) {
} else {
ErrorManager.getDefault().log("WebProjectClassPathExtender not
found in the project lookup of project:
return null;}
public boolean isInWebModule(WebModule webModule) {
return false;}
public File[] getConfigurationFiles(WebModule webModule) {
return null;}
public FrameworkConfigurationPanel getConfigurationPanel(WebModule webModule) {
return null;}

So, here the only method that's interesting is extend(). This is normally where all the action happens when you subclass WebFrameworkProvider. Normally, content is provided for deployment descriptors and configuration files, here in this method. However, since all we're doing is providing libraries, that's also all that happens here. So the Library Manager is looked up and queried for a library called 'wicket'. How do we know for sure that that library is there? Because this module includes the J2SE library desciptor which adds a library called 'wicket' to the Library Manager.

One small point, though—as discussed in yesterday's blog entry, the isInWebModule() method is used by the Project Properties dialog box to populate its Frameworks panel with a list of supported frameworks. Normally, it queries the web.xml deployment descriptor, to see whether the framework's servlet class is there. However, in this case, all we're doing is adding libraries, so there's really nothing to check (however, if someone can tell me how to check whether a library is on a project's classpath, that would be great, because then the isInWebModule() method would check whether the main Wicket JAR files are present, and only then would the Frameworks panel in the Project Properties dialog box be useful for this scenario).

So, anyway, after adding this file, a checkbox with the label 'Wicket' (thanks to the Bundle.properties file) is added to the Frameworks panel in the Web Application project wizard. When the user selects this checkbox and clicks OK, thus exiting the wizard, the libraries are automatically added—thus saving the extra step of having to go to the Library Manager to add the libraries that you knew you needed from the start. A small thing, but cool. But, maybe it's also a first step—maybe other things could be definable in the project wizards? By adding two or three extra panels (all of which the user could choose to ignore by being able to click 'Finish' anywhere), the user might be able to add far more things to their application, before having even typed a single character of code.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.