Download NetBeans!

20081201 Monday December 01, 2008

Goodbye DataLoader, Goodbye DataNode

In most cases, you don't need a separate class to define a DataLoader and another separate class to define a DataNode. So in 6.5, the DataLoader is registered (by the New File Type wizard) in the layer, without being created as a Java class, while the DataNode isn't created by the New File Type wizard either. I applied these principles to the old Book Multiview Sample, which is all I needed to do to updgrade it to 6.5—I deleted the BookDataNode class and the BookDataLoader class. Then I added the following to the layer, within Loaders/text/x-book:

<folder name="Factories">
    <file name="BookDataLoader.instance">
        <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/bookmultiview/Datasource.gif"/>
        <attr name="dataObjectClass" stringvalue="org.netbeans.modules.bookmultiview.BookDataObject"/>
        <attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/>
        <attr name="mimeType" stringvalue="text/x-book"/>
    </file>
</folder>

Next, I rewrote BookDataObject.createNodeDelegate to the following, which is all that was needed in the first place anyway:

@Override
protected Node createNodeDelegate() {
    return new DataNode(this, Children.LEAF);
}

And then I was done. Two less Java classes means two less classes to debug, test, maintain, etc.

Here's how the sample looks now, which will be used as the basis of a highly simplied tutorial on this topic, because several people I've met recently on NetBeans Platform Certified Training courses are very interested in synchronization between the two views in a multiview editor:

So, my plan is to strip this sample down to its absolute basics, so that only one field is left on the visual side, with one tag on the XML side, then add a Visual Library view, and show how the three can be synchronized. I believe this material would be very useful to several NetBeans Platform users out there.

Dec 01 2008, 10:46:59 AM PST Permalink