com.gwtext.client.data
Class Node

java.lang.Object
  extended by com.gwtext.client.core.JsObject
      extended by com.gwtext.client.data.Node
Direct Known Subclasses:
TreeNode

public class Node
extends JsObject

A data Node class.


Field Summary
protected  com.google.gwt.core.client.JavaScriptObject configJS
           
 
Fields inherited from class com.gwtext.client.core.JsObject
jsObj
 
Constructor Summary
Node()
          Create a new Node instance.
Node(com.google.gwt.core.client.JavaScriptObject jsObj)
           
 
Method Summary
 void addListener(NodeListener listener)
          Add a Node listener.
 void appendChild(Node child)
          Insert node as the last child node of this node.
 void bubble(NodeTraversalCallback cb)
          Bubbles up the tree from this node, calling the specified function with each node.
 void cascade(NodeTraversalCallback cb)
          Cascades down the tree from this node, calling the specified function with each node.
 boolean contains(Node child)
          Returns true if this node is an ancestor (at any point) of the passed node.
protected  com.google.gwt.core.client.JavaScriptObject create(com.google.gwt.core.client.JavaScriptObject config)
           
protected  Node createNode(com.google.gwt.core.client.JavaScriptObject jsNode)
           
 void eachChild(NodeTraversalCallback cb)
          Interates the child nodes of this node, calling the specified function with each node.
 boolean equals(java.lang.Object o)
           
 Node findChildBy(NodeTraversalCallback cb)
          Finds the first child by a custom callback function.
 java.lang.String getAttribute(java.lang.String name)
          Returns a node's attribute as String.
 java.lang.Object getAttributeAsObject(java.lang.String name)
          Returns a node's Object attribute.
 Node[] getChildNodes()
          Returns all child nodes of this node.
 int getDepth()
          Returns depth of this node (the root node has a depth of 0).
 Node getFirstChild()
          Return the first direct child node of this node, or null if this node has no child nodes.
 java.lang.String getId()
          Return the node's ID.
 com.google.gwt.core.client.JavaScriptObject getJsObj()
           
 Node getLastChild()
          return the last direct child node of this node, or null if this node has no child nodes.
 Node getNextSibling()
          Return the node immediately following this node in the tree, or null if there is no sibling node.
 Tree getOwnerTree()
          Returns the tree this node is in.
 Node getParentNode()
          The parent node for this node.
 java.lang.String getPath()
          Returns the path for this node.
 java.lang.String getPath(java.lang.String attr)
          Returns the path for this node.
 Node getPreviousSibling()
          Return the node immediately preceding this node in the tree, or null if there is no sibling node.
 java.lang.Object getUserObject()
          Return the user defined object
 int hashCode()
           
 int indexOf(Node child)
          Returns the index of a child node.
 Node insertBefore(Node node, Node nodeRef)
          Inserts the first node before the second node in this nodes childNodes collection.
 boolean isAncestor(Node node)
          Returns true if the passed node is an ancestor (at any point) of this node.
 boolean isFirst()
          Returns true if this node is the first child of its parent.
 boolean isLast()
          Returns true if this node is the last child of its parent.
 boolean isLeaf()
          Returns true if this node is a leaf.
 Node item(int index)
          Returns the child node at the specified index.
 void remove()
          Removes this node from it's parent.
 Node removeChild(Node child)
          Removes a child node from this node.
 Node replaceChild(Node newChild, Node oldChild)
          Replaces one child node in this node with another.
protected  void setAttribute(java.lang.String name, com.google.gwt.core.client.JavaScriptObject value)
           
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets a attribute on the node.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets a attribute on the node.
 void setId(java.lang.String id)
          Set the Node's ID.
 void setLeaf(boolean leaf)
          Sets whether the node is a leaf.
 void setUserObject(java.lang.Object userObject)
          Associate a user defined Object with the node.
 void sort(java.util.Comparator c)
          Sorts this nodes children using the supplied sort function.
 
Methods inherited from class com.gwtext.client.core.JsObject
getProperties, isCreated, setJsObj
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configJS

protected com.google.gwt.core.client.JavaScriptObject configJS
Constructor Detail

Node

public Node()
Create a new Node instance.


Node

public Node(com.google.gwt.core.client.JavaScriptObject jsObj)
Method Detail

create

protected com.google.gwt.core.client.JavaScriptObject create(com.google.gwt.core.client.JavaScriptObject config)

createNode

protected Node createNode(com.google.gwt.core.client.JavaScriptObject jsNode)

getJsObj

public com.google.gwt.core.client.JavaScriptObject getJsObj()
Overrides:
getJsObj in class JsObject

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Sets a attribute on the node.

Parameters:
name - the attribute name
value - the attribute value

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Sets a attribute on the node.

Parameters:
name - the attribute name
value - the attribute value

setAttribute

protected void setAttribute(java.lang.String name,
                            com.google.gwt.core.client.JavaScriptObject value)

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns a node's attribute as String.

Parameters:
name - the attribute name
Returns:
attribute value as String

getAttributeAsObject

public java.lang.Object getAttributeAsObject(java.lang.String name)
Returns a node's Object attribute.

Parameters:
name - the attribute name
Returns:
attribute value
See Also:
setAttribute(String, Object)

getChildNodes

public Node[] getChildNodes()
Returns all child nodes of this node.

Returns:
node's child nodes, null if none present

getFirstChild

public Node getFirstChild()
Return the first direct child node of this node, or null if this node has no child nodes.

Returns:
the first child node

getId

public java.lang.String getId()
Return the node's ID.

Returns:
the node ID, null if not defined

getLastChild

public Node getLastChild()
return the last direct child node of this node, or null if this node has no child nodes.

Returns:
the last child node

getNextSibling

public Node getNextSibling()
Return the node immediately following this node in the tree, or null if there is no sibling node.

Returns:
this nodes next sibling

getParentNode

public Node getParentNode()
The parent node for this node.

Returns:
the parent node, null if root node

getPreviousSibling

public Node getPreviousSibling()
Return the node immediately preceding this node in the tree, or null if there is no sibling node.

Returns:
this nodes previosu sibling

appendChild

public void appendChild(Node child)
Insert node as the last child node of this node.

Parameters:
child - node to append

bubble

public void bubble(NodeTraversalCallback cb)
Bubbles up the tree from this node, calling the specified function with each node. If the callback method returns false at any point, the bubble is stopped.

Parameters:
cb - the callback function handle

cascade

public void cascade(NodeTraversalCallback cb)
Cascades down the tree from this node, calling the specified function with each node. If the callback method returns false at any point, the cascade is stopped on that branch.

Parameters:
cb - the callback function handle

contains

public boolean contains(Node child)
Returns true if this node is an ancestor (at any point) of the passed node.

Parameters:
child - the node
Returns:
true if contains

eachChild

public void eachChild(NodeTraversalCallback cb)
Interates the child nodes of this node, calling the specified function with each node. If the callback function returns false at any point, the iteration stops.

Parameters:
cb - the callback function handle

findChildBy

public Node findChildBy(NodeTraversalCallback cb)
Finds the first child by a custom callback function. The child matches if the function passed returns true.

Parameters:
cb - the callback function handle
Returns:
the child or null if not found

getDepth

public int getDepth()
Returns depth of this node (the root node has a depth of 0).

Returns:
the depth of this node

getOwnerTree

public Tree getOwnerTree()
Returns the tree this node is in.

Returns:
the owner tree

getPath

public java.lang.String getPath()
Returns the path for this node. The path can be used to expand or select this node programmatically.

Returns:
the path

getPath

public java.lang.String getPath(java.lang.String attr)
Returns the path for this node. The path can be used to expand or select this node programmatically.

Parameters:
attr - the attr to use for the path (defaults to the node's id)
Returns:
the path

indexOf

public int indexOf(Node child)
Returns the index of a child node.

Parameters:
child - the child node
Returns:
the index of the node or -1 if it was not found

insertBefore

public Node insertBefore(Node node,
                         Node nodeRef)
Inserts the first node before the second node in this nodes childNodes collection.

Parameters:
node - the node to insert
nodeRef - the node to insert before (if null the node is appended)
Returns:
the inserted node

isAncestor

public boolean isAncestor(Node node)
Returns true if the passed node is an ancestor (at any point) of this node.

Parameters:
node - the node to test
Returns:
true of ancestor

isFirst

public boolean isFirst()
Returns true if this node is the first child of its parent.

Returns:
true if first node

isLast

public boolean isLast()
Returns true if this node is the last child of its parent.

Returns:
true if last

isLeaf

public boolean isLeaf()
Returns true if this node is a leaf.

Returns:
true if leaf node

item

public Node item(int index)
Returns the child node at the specified index.

Parameters:
index - the index
Returns:
the child at index, null if none present

remove

public void remove()
Removes this node from it's parent.


removeChild

public Node removeChild(Node child)
Removes a child node from this node.

Parameters:
child - the node to remove
Returns:
the removed node

replaceChild

public Node replaceChild(Node newChild,
                         Node oldChild)
Replaces one child node in this node with another.

Parameters:
newChild - the replacement node
oldChild - the node to replace
Returns:
the replaced node

sort

public void sort(java.util.Comparator c)
Sorts this nodes children using the supplied sort function.

Parameters:
c - the Comparator return 0 if equal, -1 if first node less than second, 1 if first greater than second

addListener

public void addListener(NodeListener listener)
Add a Node listener.

Parameters:
listener - the listener

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

setUserObject

public void setUserObject(java.lang.Object userObject)
Associate a user defined Object with the node.

Parameters:
userObject - the user data object

getUserObject

public java.lang.Object getUserObject()
Return the user defined object

Returns:
the user defined object

setId

public void setId(java.lang.String id)
Set the Node's ID.

Parameters:
id - the node ID

setLeaf

public void setLeaf(boolean leaf)
Sets whether the node is a leaf.

Parameters:
leaf - true if leaf