Monday Apr 28, 2008


The org.openide.filesystems.FileUtil.findBrother method is typically used by the Matisse GUI Builder so that if a file named "" is in the same folder as a file named "xyz.frm", the two are merged together and opened as one in the editor. Specifically, FileUtil.findBrother takes a FileObject and a file extension, which is the file extension of the "brother" file.

There are several other conceivable scenarios where this functionality might be handy, such as Wicket, which typically has "" in the same folder as "xyz.html". The latter provides the markup for the former. Below you can see my point, the Java files that have a matching HTML file (i.e., the same name) have a Wicket icon merged with their Java icon:

So, first create a new DataObject for text/x-java—and make sure it will install before the standard Java DataObject. Then, use the DataLoader to branch the DataObject, depending on whether a "brother" is found:

protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
    FileObject bro = FileUtil.findBrother(primaryFile, "html");
    if (null != bro) {
        //Return our own data object:
        return new WicketDataObject(primaryFile, this);
    //Return the standard data object:
    return new JavaDataObject(primaryFile, this);

Finally, in the Node, use org.openide.util.Utilities.mergeImages to merge a small image on top of the standard Java icon:

private static final String WICKET_ICON_BASE = 
private static final String JAVA_ICON_BASE =   
public Image getIcon(int arg0) {
    Image wicket = Utilities.loadImage(WICKET_ICON_BASE);
    Image java = Utilities.loadImage(JAVA_ICON_BASE);
    Image result = Utilities.mergeImages(java, wicket, 8, 8);
    return result;

Install the module and then Java files with HTML brothers will have our Wicket icon merged with their Java icon.

Reorganized & Simplified Wicket Support

In preparation for a JavaOne demo, I've simplified the NetBeans/Wicket support, from a ui and user perspective. This is what the Frameworks panel now looks like, after I removed some superfluous options (so that now the header panel is always created, while the useless option for the dummy pojo is removed) and changed some default names:

And when the user finishes the wizard, they will see exactly this, i.e., the source package folder will be open automatically and the HomePage class will be open in the editor, because that's probably the first place where you'll start coding. A default model setting is defined in the generated HomePage class and the org.apache.wicket.markup.html.resources.StyleSheetReference class is used in the BasePage class, to provide localized CSS support. Notice below also that the default names of the generated files have been changed and simplified, so that it's easier to see what's what, especially if you have some Wicket background:

For example, as you can see, pages and panels are easily distinguishable, now, because the name of the generated file (by default, anyway) contains the related info in this regard. Finally, no index.jsp is created, for the first time. The IDE's Frameworks support creates an index.jsp file by default, if no welcome file element is defined in the web.xml file by the module. So, I defined a welcome file element (even though it isn't used by Wicket) and so now the index.jsp is no longer created.

I need to do a bit more work on the module, such as upgrading the libraries to Wicket 3.3 (which fixes at least one important Ajax-related bug that I am aware of) and I'm hoping to have committed all my changes to CVS by the time JavaOne begins.


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.


« April 2008 »