Monday Dec 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.

About

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.

Search

Archives
« December 2008 »
SunMonTueWedThuFriSat
 
3
7
12
16
17
18
19
21
22
25
26
27
28
29
30
   
       
Today