dk.opi.io
Class JTreeIOTreeNode
java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
dk.opi.io.JTreeIOTreeNode
- All Implemented Interfaces:
- Cloneable, MutableTreeNode, Serializable, TreeNode
- public class JTreeIOTreeNode
- extends DefaultMutableTreeNode
Class wrapping an IOItemBrowseTreeNode
object, in order to
visualize the hierarchical information contained in a IOItemBrowseTreeNode
in Swing's JTree component. All methods in this class holding state
information about the IO node, simply delegates to the similar method on an
IOItemBrowseTreeNode instance. Please note that this object extends the
DefaultMutableTreeNode
object
Example of using JTreeIOTreeNode:
OpcClientApi server = new OpcClientApi("ICONICS.Simulator");
JTree tree = new JTree(new String[] {});
// don't show the root node
tree.setRootVisible(false);
// Get the items and groups from the OPC server.
IOItemBrowseTreeNode ioTop = server.getServerItemsInfo();
// Wrap the IOItemBrowseTreeNode by using the adapter JTreeIOTreeNode.
// This adapter will make IOItemBrowseTreeNode look like normal TreeNodes
// directly insertable into the JTree Swing component as a normal root node
DefaultMutableTreeNode top = new JTreeIOTreeNode(ioTop);
DefaultTreeModel treeModel = (DefaultTreeModel )tree.getModel();
treeModel.setRoot(top);
// reload the model
treeModel.reload();
The full source of this class is as follows:
public class JTreeIOTreeNode extends DefaultMutableTreeNode {
public JTreeIOTreeNode(IOItemBrowseTreeNode ioNode) {
super(ioNode); // set the IOItemBrowseTreeNode as user object
// run through all child nodes and create wrappers for these objects aswell
Enumeration childEnum = ioNode.children();
for (Enumeration e = ioNode.children(); e.hasMoreElements() ;) {
IOItemBrowseTreeNode cIONode = (IOItemBrowseTreeNode )e.nextElement();
this.add(new JTreeIOTreeNode(cIONode));
}
}
// Returns true if the receiver allows children.
public boolean getAllowsChildren() {
// delegate to user object
return ((IOItemBrowseTreeNode )this.getUserObject()).getAllowsChildren();
}
// Returns true if the receiver is a leaf
public boolean isLeaf() {
return ((IOItemBrowseTreeNode )this.getUserObject()).isLeaf();
}
}
- See Also:
OpcClientApi.getServerInfo()
,
Serialized Form
Method Summary |
boolean |
getAllowsChildren()
Returns true if the receiver allows children. |
boolean |
isLeaf()
Returns true if the receiver is a leaf |
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode |
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString |
JTreeIOTreeNode
public JTreeIOTreeNode(IOItemBrowseTreeNode ioNode)
- Creates a new
JTreeIOTreeNode
instance based on the specified
IOItemBrowseTreeNode
object. The new
JTreeIOTreeNode
will contain all the hierarchical data
contained within the specified IOItemBrowseTreeNode
parameter, ie. a hierarchi of new objects will be created and may
instantly be given to a JTree() instance.
- Parameters:
ioNode
- an IOItemBrowseTreeNode
value
getAllowsChildren
public boolean getAllowsChildren()
- Returns true if the receiver allows children.
- Returns:
- a
boolean
value
isLeaf
public boolean isLeaf()
- Returns true if the receiver is a leaf
- Returns:
- a
boolean
value