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 the following code example.
public class TreeSDMModel extends IlvAbstractSDMModel { ...
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 the following code example.
private TreeSDMNode root; public TreeSDMModel(TreeModel treeModel) { root = new TreeSDMNode(treeModel, null, treeModel.getRoot()); }
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 the following code example.
public Enumeration getObjects() { Vector v = new Vector(); v.addElement(root); return v.elements(); }
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.
The following code example shows the method implementation.
public void clear() { // Nothing, this model is immutable. } }