Developing with the SDK > Using and Writing Data Models > NonJavaBeans Example: Abstract Model Variant > The TreeSDMModel Class

To display the data model of a tree in a diagram component, you must write a data model that transforms the tree data into an SDM model. In this example, the model is implemented by the class TreeSDMModel, which is a subclass of IlvAbstractSDMModel. Its definition is as shown in Code Sample 2.13.

public class TreeSDMModel extends IlvAbstractSDMModel
{
...

Code Sample 2.13 A Data Model Based on the Abstract SDM Model

Root of the Tree

The nodes of the graph will be represented by instances of a class TreeSDMNode. The TreeSDMModel class creates a node that represents the root of the tree, and keeps a reference to it as shown in Code Sample 2.14.

 private TreeSDMNode root;

  public TreeSDMModel(TreeModel treeModel)
  {
    root = new TreeSDMNode(treeModel, null, treeModel.getRoot());
  }

Code Sample 2.14 Keeping Track of the Root of a Tree

When asked to return the top-level objects of the graph, the getObjects method just returns a single element: the root of the tree, as shown in Code Sample 2.15.

public Enumeration getObjects()
  {
    Vector v = new Vector();
    v.addElement(root);
    return v.elements();
  }

Code Sample 2.15 A Method that Returns the Root of a Tree

Model Is Not Editable

The clear method must be implemented, but it will never be called since the TreeSDMModel class in this example represents a model that is not editable. Code Sample 2.16 shows the method implementation.

  public void clear()
  {
    // Nothing, this model is immutable.
  }
}

Code Sample 2.16 An Empty Method for the Clear Operation