Geertjan is a DZone Zone Leader and has posted 453 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Even Further with Spring RCP (1)

  • submit to reddit

Constructing a Node Hierarchy

Line 8 of the two main snippets shown in the previous section retrieves the data via a call to "CustomerNode.customers".

That call is to a class that extends "org.openide.nodes.AbstractNode", which is one of the classes from the NetBeans Platform JARs referred to previously.

In effect, in this class you model the nodes in the view, which represent the data in your model.

Looking at it another way, in this class you build your data nodes in the way that you build your form via the Spring RCP Form Builder.

Perhaps you can, therefore, think of the code below as an example of a Data Node Builder in action!

I believe the code below, though slightly lengthy, is relatively understandable without too much explanation.

First the parent node is created, then its children, which each get their own node:

public final class CustomerNode extends AbstractNode {

private static Customer customer;

private static CustomerDataStore customerDataStore = new CustomerDataStore();

private CustomerNode(Customer c) {

super(new CustomerChildren(c));
customer = c;


public static Node customers() {

AbstractNode n = new AbstractNode(new CustomerChildren(customer));
return n;


private static final class CustomerChildren extends Children.Keys<Customer> {

Customer customer;

public CustomerChildren(Customer customer) {
this.customer = customer;

protected void addNotify() {
if (customer == null) {
Customer[] objs = customerDataStore.getAllCustomers();

protected Node[] createNodes(Customer c) {
AbstractNode n = new AbstractNode(new AddressChildren(c.getAddress()));
n.setDisplayName(c.getFirstName() + " " + c.getLastName());
return new Node[]{n};


private static final class AddressChildren extends Children.Keys<Address> {

Address address;

CustomerView view;

public AddressChildren(Address address) {
this.address = address;

protected void addNotify() {

Customer[] objs = customerDataStore.getAllCustomers();
for (int i = 0; i < objs.length; i++) {
if (objs[i].getAddress().getAddress1().equals(address.getAddress1())) {
Customer customer = objs[i];
setKeys(new Address[]{customer.getAddress()});


protected Node[] createNodes(Address a) {

AddressNode addressNode = new AddressNode();

AddressNode cityNode = new AddressNode();

AddressNode stateNode = new AddressNode();

AddressNode zipNode = new AddressNode();

return new Node[]{addressNode,cityNode,stateNode,zipNode};



public static final class AddressNode extends AbstractNode {

private AddressNode() {








In this part of the Spring RCP series, I've tried to show how composite dialogs are created, via loose coupling of forms, which in that sense can be seen as "display units" that delegate rendering to Spring RCP containers—TabbedDialogPage and TreeCompositeDialogPage. I've also tried to show how, instead of recoding complex Swing components (and their models) whenever you need to display your data in a new view, you can very easily integrate NetBeans Platform JARs and thereby reuse a central concept used by that platform—the separation of data from views, which is comparable to the Spring RCP approach of separating forms from dialogs.

(And now read on... in the next part of this series!) 


figure-1.png23.7 KB
figure-2.png27.1 KB
figure-3.png17.91 KB
figure-4.png20.39 KB
figure-5.png12.4 KB
figure-6.png36.5 KB
figure-7.png24.6 KB
figure-8.png43.48 KB
Published at DZone with permission of its author, Geertjan Wielenga.


Andreas Mueller replied on Fri, 2009/10/09 - 5:35am

I'm starting to learn Spring RCP and I really want to thank you for your great tutorials.

But I'm having problems to compile the code after introducing the HierarchicalFormModel.

The lines

customerForm = new CustomerForm(FormModelHelper.createChildPageFormModel(ownerFormModel, null));
addressForm = new AddressForm(FormModelHelper.createChildPageFormModel(ownerFormModel, null));

have errors and I have no idea how to change the constructors of CustomerForm and AddressForm to make it compile.

Did I miss the source code for this?


Andreas Mueller replied on Fri, 2009/10/09 - 5:47am

I did not expect it to be so easy.
I changed the constructor of AddressForm to

AddressForm(ValidatingFormModel model) {

 and of CustomerForm to

CustomerForm(ValidatingFormModel model) {

and that was it!


Andreas Mueller replied on Fri, 2009/10/09 - 6:07am

Obviously it is not as easy as I thought.

After making the abovementioned changes in the constructors the code compiles and the app runs, but changes in data are not saved to the model.

Any help available?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.