package jaxcent.yui; import jaxcent.*; /** * Objects of class TreeNode correspond to nodes of a YUI Tree. */ public class TreeNode { String nodeVarName; jaxcent.yui.Tree tree; boolean editable; boolean dateNode; Object userData; // Constructor. Used internally. TreeNode( jaxcent.yui.Tree tree, boolean editable, boolean dateNode ) { nodeVarName = Tree.getJSVar(); this.tree = tree; this.editable = editable; this.dateNode = dateNode; tree.nodeAdded( this ); } // Retrieve the internal JavaScript name for this node. String getVarName() { return nodeVarName; } /** Add a non-editable text node as a child of this node. */ public TreeNode addTextNode( String text ) throws Jaxception { return tree.addTextNode( text, false, nodeVarName ); } /** Add an editable text node as a child of this node. */ public TreeNode addEditableTextNode( String text ) throws Jaxception { return tree.addTextNode( text, true, nodeVarName ); } /** Add a non-editable date node as a child of this node. */ public TreeNode addDateNode( java.util.Date date ) throws Jaxception { return tree.addDateNode( date, false, nodeVarName ); } /** Add an editable date node as a child of this node. */ public TreeNode addEditableDateNode( java.util.Date date ) throws Jaxception { return tree.addDateNode( date, true, nodeVarName ); } /** Return the current lable of this node. */ public String getNodeLabel() throws Jaxception { return tree.evalJavaScriptCode( nodeVarName + ".label", false, null ); } /** Remove the node and all its children from the tree. */ public void delete() throws Jaxception { tree.deleteNode( nodeVarName ); } /** Expand the node. */ public void expand() throws Jaxception { tree.execJavaScriptCode( nodeVarName + ".expand();" ); } /** Collapse the node. */ public void collapse() throws Jaxception { tree.execJavaScriptCode( nodeVarName + ".collapse();" ); } /** Is this an editable node? */ public boolean isEditableNode() { return editable; } /** Is this a text node? */ public boolean isTextNode() { return ! dateNode; } /** Is this a date node? */ public boolean isDateNode() { return ! dateNode; } /** Attach user data to node. */ public void setUserData( Object userData ) { this.userData = userData; } /** Return any user data attached to node. */ public Object getUserData() { return userData; } }