Class RapidContext.Widget.TreeNode

Extends: RapidContext.Widget

The tree node widget class. Used to provide a tree node in a tree, using a number of <div> HTML elements. Note that events should normally not be listened for on individual tree nodes, but rather on the tree as a whole.

Source code: RapidContext_Widget_TreeNode.js

Class Summary
 
Creates a new tree node widget.
Method Summary
 
addChildNode(child)
Adds a single child tree node widget to this widget.
 
Collapses this node to hide any child nodes.
 
collapseAll(depth)
Recursively collapses this node and all its children.
 
Expands this node to display any child nodes.
 
expandAll(depth)
Recursively expands this node and all its children.
 
findByPath(path)
Searches for a descendant tree node from the specified path.
 
findChild(name)
Finds a child tree node with the specified name.
 
Checks if this folder node is expanded.
 
Checks if this node is a folder.
 
Checks if this node is selected.
 
Marks this tree node and all child nodes recursively.
 
Returns the parent tree node widget.
 
path()
Returns the path to this tree node.
 
Removes all marked tree nodes.
 
Selects this tree node.
 
setAttrs(attrs)
Updates the widget or HTML DOM node attributes.
 
toggle(evt)
Toggles expand and collapse for this node.
 
tree()
Returns the ancestor tree widget.
 
Unselects this tree node.
Methods borrowed from class RapidContext.Widget:
addAll, addClass, animate, blurAll, destroy, disable, enable, getChildNodes, hasClass, hide, isDisabled, isHidden, removeAll, removeChildNode, removeClass, setStyle, show, toggleClass, uid
Class Detail
RapidContext.Widget.TreeNode(attrs)
Creates a new tree node widget.
JavaScript:
var parent = RapidContext.Widget.TreeNode({ folder: true, name: "Parent" });
var child = RapidContext.Widget.TreeNode({ name: "Child" });
parent.addAll(child);
User Interface XML:
<TreeNode name="Parent">
  <TreeNode name="Child" />
</TreeNode>
Parameters:
{Object} attrs
the widget and node attributes
{String} attrs.name
the tree node name
{Boolean} attrs.folder Optional
the folder flag, defaults to false if no child nodes are provided in constructor call
{String} attrs.icon Optional
the icon reference to use, defaults to FOLDER for folders and DOCUMENT otherwise
{String} attrs.tooltip Optional
the tooltip text when hovering
{Boolean} attrs.hidden Optional
the hidden widget flag, defaults to false
{Widget} ... Optional
the child tree node widgets
Returns:
{Widget} the widget DOM node
Method Detail
setAttrs(attrs)
Updates the widget or HTML DOM node attributes.
Parameters:
{Object} attrs
the widget and node attributes to set
{String} attrs.name Optional
the tree node name
{Boolean} attrs.folder Optional
the folder flag, cannot be reverted to false once set (implicitly or explicitly)
{Icon/Object/String} attrs.icon Optional
icon the icon to set, or null to remove
{String} attrs.tooltip Optional
the tooltip text when hovering
{Boolean} attrs.hidden Optional
the hidden widget flag

addChildNode(child)
Adds a single child tree node widget to this widget.
Parameters:
{Widget} child
the tree node widget to add

removeAllMarked()
Removes all marked tree nodes. When adding or updating tree nodes, any node modified is automatically unmarked (e.g. by calling setAttrs). This makes it easy to prune a tree after an update, by initially marking all tree nodes with markAll(), inserting or touching all nodes to keep, and finally calling this method to remove the remaining nodes.
parent.markAll();
parent.setAttrs();
child.setAttrs();
...
parent.removeAllMarked();

markAll()
Marks this tree node and all child nodes recursively. When adding or updating tree nodes, any node modified is automatically unmarked (e.g. by calling setAttrs). This makes it easy to prune a tree after an update, by initially marking all tree nodes, inserting or touching all nodes to keep, and finally calling removeAllMarked() to remove the remaining nodes.
parent.markAll();
parent.setAttrs();
child.setAttrs();
...
parent.removeAllMarked();

{Boolean} isFolder()
Checks if this node is a folder.
Returns:
{Boolean} true if this node is a folder, or false otherwise

{Boolean} isExpanded()
Checks if this folder node is expanded.
Returns:
{Boolean} true if this node is expanded, or false otherwise

{Boolean} isSelected()
Checks if this node is selected.
Returns:
{Boolean} true if the node is selected, or false otherwise

{Widget} tree()
Returns the ancestor tree widget.
Returns:
{Widget} the ancestor tree widget, or null if none was found

{Widget} parent()
Returns the parent tree node widget.
Returns:
{Widget} the parent tree node widget, or null if this is a root node

{Array} path()
Returns the path to this tree node.
Returns:
{Array} the tree node path, i.e an array of node names

{Widget} findChild(name)
Finds a child tree node with the specified name.
Parameters:
{String} name
the child tree node name
Returns:
{Widget} the child tree node found, or null if not found

{Widget} findByPath(path)
Searches for a descendant tree node from the specified path.
Parameters:
{Array} path
the tree node path (array of node names)
Returns:
{Widget} the descendant tree node found, or null if not found

select()
Selects this tree node.

unselect()
Unselects this tree node.

expand()
Expands this node to display any child nodes. If the parent node is not expanded, it will be expanded as well.

expandAll(depth)
Recursively expands this node and all its children. If a depth is specified, expansions will not continue below that depth.
Parameters:
{Number} depth Optional
the optional maximum depth

collapse()
Collapses this node to hide any child nodes.

collapseAll(depth)
Recursively collapses this node and all its children. If a depth is specified, only children below that depth will be collapsed.
Parameters:
{Number} depth Optional
the optional minimum depth

toggle(evt)
Toggles expand and collapse for this node.
Parameters:
evt