| Developing with the SDK > Using and Writing Data Models > NonJavaBeans Example: Abstract Model Variant > The TreeSDMNode Class |
The TreeSDMNode Class |
INDEX
PREVIOUS
NEXT
|
The class TreeSDMNode represents the nodes of the graph. Its definition is as shown in Code Sample 2.17.
public class TreeSDMNode implements IlvSDMNode { |
Each node in the graph (graphic object) has a reference to the corresponding node in the tree (model object). References to the parent node (graphic object) and the tree model are also needed. The children of the node are stored in a vector.
Note that the constructor calls the method createChildren. This method traverses the tree model and creates a TreeSDMNode instance for each item in the tree. In addition, it creates an instance of TreeSDMLink to draw a link between the parent node and each child node.
The following methods are the implementations of the methods belonging to the IlvSDMNode interface, which are inherited by TreeSDMNode.
The getTag method returns the type (or "tag") of the node. In this example, the type is treenode.
public String getTag() { return "treenode"; } |
The getID method returns the identifier of the node. The identifier of a node is its hash code.
public String getID() { return String.valueOf(hashCode()); } |
The getChildren method returns the children of the node, which are stored in the children data member.
public Enumeration getChildren() { return children.elements(); } |
The getParent method returns the parent node of the current node.
public IlvSDMNode getParent() { return parent; } |
The getProperty and getPropertyNames methods must be implemented to give the diagram component access to the properties of the node. In this example, there is support for two properties, userObject and CSSclass:
userObject property returns the sample food, color, and sports names.
CSSclass property returns the type of item: food, color, or sport.
The getPropertyNames method retrieves the two property names, see Code Sample 2.26.
public String[] getPropertyNames() { if(treeNode instanceof DefaultMutableTreeNode) return new String[] { "userObject", "CSSclass" }; else return new String[0]; } |
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |