| Developing with the SDK > Using and Writing Data Models > NonJavaBeans Example: Abstract Model Variant > The TreeSDMModel Class |
The TreeSDMModel Class |
INDEX
PREVIOUS
NEXT
|
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 { ... |
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()); } |
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(); } |
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. } } |
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |