Today I was making another attempt to 'finally' come to terms with the NetBeans Nodes API, when I realized something interesting. Before revealing what it was, did you know that the most tutorialized NetBeans API is the Nodes API? The best example that I have found on the Nodes API is in Visual Library 2.0 Tutorial (Part 1)
. Part way down in that tutorial, in order to set up the scene for the material to be covered, you find some very simple, short, and succinct classes for adding nodes to a component palette. They're just nodes, after all, so you could add them to an explorer window instead, as described in NetBeans Nodes, Explorer Manager, and Component Palette Tutorial
However, when you start really playing with the simple example in the abovementioned Visual Library tutorial, you suddenly realize something interesting -- each node in the hierarchy is (normally) represented by three classes:
- A simple bean class, with getters and setters for properties, such as a 'name' and an 'ímage'.
- A Node class (such as AbstractNode) for presenting the bean properties in the user interface, such as in an explorer window or component palette, via setDisplayName, and so on.
- A class (such as Children.Keys) for connecting the above two classes together.
Hmmm.... three classes... one is kind of like... a model, the other one is a bit like... a view... and then... the final one is kind of like... a controller... Hmmm. Hey, wait a minute... it's coming to me now... doesn't that kind of sound like... the MVC pattern..?
Interesting, right? Take a look at your Nodes API implementations, or at samples described in the NetBeans Modules and Rich-Client Applications Learning Trail. You'll be surprised to see how much better you understand the Nodes API once you connect it to the MVC pattern.