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"/>

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

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.


Good Day Geertjan,

I was looking at your screen shot and wondered what look and feel you applied to NetBeans?

Posted by Maurice Rogers Jr. on December 01, 2008 at 04:53 AM PST #

None, Maurice. That is Ubuntu. I am on 8.10, which is Intrepid Ibex.

Posted by Geertjan on December 01, 2008 at 05:40 AM PST #

I'm a beginner when it come to NetBeans Platform, so don't be harsh on me. :)
Where do you find things like SystemFileSystem.icon, dataObjectClass, ... How do you know BookDataLoader.instance goes into Factories? How do you know what attributes you must specify for BookDataLoader.instance?

Posted by Kovica on December 01, 2008 at 01:41 PM PST #

Because you use the New File Type wizard. That does it for you.

Posted by Geertjan on December 01, 2008 at 07:33 PM PST #

Yes, if you use the wizard, but I want to know in general. Let's say there is no wizard.

Posted by Kovica on December 02, 2008 at 04:49 AM PST #

No where seems to document how to override the data loader now, for if you want bespoke functionality in the data object loading.

Posted by Craig Marshall on March 17, 2009 at 07:48 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

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.


« July 2016