org.apache.click.extras.tree
Class Tree

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.extras.tree.Tree
All Implemented Interfaces:
Serializable, Control
Direct Known Subclasses:
CheckboxTree

public class Tree
extends AbstractControl

Provides a tree control for displaying hierarchical data. The tree operates on a hierarchy of TreeNode's. Each TreeNode must provide a uniquely identified node in the hierarchy.

Below is a screenshot of the tree in action.

Tree Example

An example tree usage is provided below (this code was used to produce the screenshot):
 public class PlainTreePage extends BorderPage {

     public PlainTreePage() {
         Tree tree = buildTree();
         addControl(tree);
     }

     // This method creates a representation of a Windows OS directory.
     public Tree buildTree() {
         Tree tree = new Tree("tree");

         // Create a node representing the root directory with the specified
         // parameter as the value. Because an id is not specified, a random
         // one will be generated by the node. By default the root node is
         // not rendered by the tree. This can be changed by calling
         // tree.setRootNodeDisplayed(true).
         TreeNode root = new TreeNode("c:");

         // Create a new directory, setting the root directory as its parent. Here
         // we do specify a id as the 2nd argument, so no id is generated.
         TreeNode dev = new TreeNode("dev","1", root);

         // The following two nodes represent files in the directory.
         // The false argument to the constructor below means that these nodes
         // does not support child nodes. Makes sense since files cannot contain
         // directories or other files
         new TreeNode("java.pdf", "2", dev, false);
         new TreeNode("ruby.pdf", "3", dev, false);

         TreeNode programFiles = new TreeNode("program files", "4", root);
         TreeNode adobe = new TreeNode("Adobe", "5", programFiles);

         TreeNode download = new TreeNode("downloads","6", root);
         TreeNode web = new TreeNode("web", "7", download);
         new TreeNode("html.pdf", "8", web);
         new TreeNode("css.html", "9", web);

         TreeNode databases = new TreeNode("databases", "10", download);
         new TreeNode("mysql.html","11",databases);
         new TreeNode("oracle.pdf","12",databases);
         new TreeNode("postgres","13",databases);

         tree.setRootNode(root);
         return tree;
     }
 } 

CSS and JavaScript resources

The Tree control makes use of the following resources (which Click automatically deploys to the application directory, /click/tree): To import these Tree files simply reference the variables $headElements and $jsElements in the page template. For example:
 <html>
 <head>
 $headElements
 </head>
 <body>

 $tree

 $jsElements
 </body>
 </html> 

Tree customization

The following list of stylesheet classes are used to render the tree icons. One can easily change the tree.css to use a different set of icons. Note: all CSS classes are set inline in <span> elements. Credit goes to Wicket for these images:

See Also:
Serialized Form

Nested Class Summary
protected  class Tree.AbstractJavascriptRenderer
          Please note this class is not meant for public use.
protected static interface Tree.Callback
          Provides a TreeNode callback interface.
protected  class Tree.CookieHandler
          Please note this class is only meant for developers of this control, not users.
protected  class Tree.CookieRenderer
          Please note this class is only meant for developers of this control, not users.
protected static interface Tree.JavascriptHandler
          Please note this class is not meant for public use.
protected static interface Tree.JavascriptRenderer
          Please note this class is not meant for public use.
protected  class Tree.SessionHandler
          Please note this class is only meant for developers of this control, not users.
protected  class Tree.SessionRenderer
          Please note this class is only meant for developers of this control, not users.
 
Field Summary
protected static String COLLAPSE_ICON
          The tree's collapsed icon name: "collapsedIcon".
protected static String EXPAND_ICON
          The tree's expand icon name: "expandedIcon".
static String EXPAND_TREE_NODE_PARAM
          The tree's expand/collapse parameter name: "expandTreeNode".
protected  ActionLink expandLink
          The tree node expand / collapse link.
protected  String[] expandOrCollapseNodeIds
          Array of ids that must be expanded or collapsed.
static int JAVASCRIPT_COOKIE_POLICY
          Indicator for using cookies to implement client side behavior.
static int JAVASCRIPT_SESSION_POLICY
          Indicator for using the session to implement client side behavior.
protected  Tree.JavascriptHandler javascriptHandler
          Keep track of node id's, as they are selected, deselected, expanded and collapsed.
protected static String LEAF_ICON
          The tree's leaf icon name: "leafIcon".
protected  TreeNode rootNode
          The tree's hierarchical data model.
static String SELECT_TREE_NODE_PARAM
          The tree's select/deselect parameter name: "selectTreeNode".
protected  ActionLink selectLink
          The Tree node select / deselect link.
protected  String[] selectOrDeselectNodeIds
          Array of ids that must be selected or deselected.
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.click.Control
CONTROL_MESSAGES
 
Constructor Summary
Tree()
          Create a Tree with no name defined.
Tree(String name)
          Create an Tree control for the given name.
 
Method Summary
 void addListener(TreeListener listener)
          Adds the listener to start receiving tree events.
 void bindExpandOrCollapseValues()
          This method binds the users request of expanded and collapsed nodes to the tree's nodes.
 void bindRequestValue()
          This method binds any expand/collapse and select/deselect changes from the request parameters.
 void bindSelectOrDeselectValues()
          This method binds the users request of selected nodes to the tree's nodes.
 void cleanupSession()
          Utility method that force the Tree to remove any entries it made in the HttpSession.
 void collapse(String id)
          Collapse the node with matching id and inform any listeners of the change.
 void collapse(TreeNode node)
          Collapse the node and inform any listeners of the change.
 void collapseAll()
          Collapse all the nodes of the tree and inform any listeners of the change.
protected  Tree.JavascriptHandler createJavascriptHandler(int javascriptPolicy)
          Creates a new JavascriptHandler based on the specified policy.
 void deselect(String id)
          Deselect the node with matching id and inform any listeners of the change.
 void deselect(TreeNode node)
          Deselect the node and inform any listeners of the change.
 void deselectAll()
          Deselect all the nodes of the tree and inform any listeners of the change.
 void expand(String id)
          Expand the node with matching id and inform any listeners of the change.
 void expand(TreeNode node)
          Expand the node and inform any listeners of the change.
 void expandAll()
          Expand all the nodes of the tree and inform any listeners of the change.
protected  void expandOrCollapse(String[] ids)
          Swaps the expand state of all TreeNodes with specified id's.
 TreeNode find(String id)
          Finds and returns the first node that matches the id.
protected  TreeNode find(TreeNode node, String id)
          Finds and returns the first node that matches the id, starting the search from the specified node.
protected  void fireNodeCollapsed(TreeNode node, boolean previousState)
          Notifies all listeners currently registered with the tree, about any collapse events.
protected  void fireNodeDeselected(TreeNode node, boolean previousState)
          Notifies all listeners currently registered with the tree, about any deselection events.
protected  void fireNodeExpanded(TreeNode node, boolean previousState)
          Notifies all listeners currently registered with the tree, about any expand events.
protected  void fireNodeSelected(TreeNode node, boolean previousState)
          Notifies all listeners currently registered with the tree, about any selection events.
 int getControlSizeEst()
           
 Decorator getDecorator()
          Get the tree's decorator.
protected  String getExpandClass(TreeNode treeNode)
          Query the specified treeNode and check which css class to apply.
 List<TreeNode> getExpandedNodes(boolean includeInvisibleNodes)
          Returns all the nodes that were expanded.
 ActionLink getExpandLink()
          Return the tree node expand / collapse link.
 List<Element> getHeadElements()
          Return the Tree HTML HEAD elements for the following resources:

click/tree/tree.css click/tree/tree.js click/tree/cookie-helper.js

 String getHeight()
          Return the CSS "height" style of the tree, or null if not defined.
protected  String getHref(Map<String,? extends Object> parameters)
          Return an anchor <a> tag href attribute for the given parameters.
protected  String getIconClass(TreeNode treeNode)
          Query the specified treeNode and check which css class to apply for the icons.
protected  String getRequestValue(String name)
          Returns the value of the specified named parameter or a empty string "" if not found.
protected  String[] getRequestValues(String name)
          Returns an array of all values of the specified named parameter or null if the parameter does not exist.
 TreeNode getRootNode()
          Return the tree's root TreeNode.
 List<TreeNode> getSelectedNodes(boolean includeInvisibleNodes)
          Returns all the nodes that were selected.
 ActionLink getSelectLink()
          Return the tree node select / deselect link.
 String getWidth()
          Return the CSS "width" style attribute of the tree, or null if not defined.
 boolean hasRootNode()
          Return if tree has a root node.
protected  boolean isExpandedParent(TreeNode treeNode)
          Helper method indicating if the specified node is both expanded and has at least 1 child node.
 boolean isJavascriptEnabled()
          Returns if javascript functionality are enabled or not.
 boolean isNotifyListeners()
          Query if the tree will notify its tree listeners of any change to the tree's model.
 boolean isRootNodeDisplayed()
          Return if the tree's root node should be displayed or not.
 Iterator<TreeNode> iterator()
          Returns an iterator over all the nodes.
 Iterator<TreeNode> iterator(TreeNode node)
          Returns an iterator over all nodes starting from the specified node.
 void onDestroy()
          This method cleans up the expandLink and selectLink.
 boolean onProcess()
          Processes user request to change state of the tree.
protected  void processNodes(Collection<TreeNode> nodes, Tree.Callback callback)
          Provides callback functionality for all the specified nodes.
protected  void processNodes(String[] ids, Tree.Callback callback)
          Provides callback functionality for all the specified nodes.
 void removeListener(TreeListener listener)
          Removes the listener to stop receiving tree events.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the tree.
protected  void renderExpandAndCollapseAction(HtmlStringBuffer buffer, TreeNode treeNode)
          Render the expand and collapse action of the tree.
protected  void renderIcon(HtmlStringBuffer buffer, TreeNode treeNode)
          Render the node's icon depending on the current state of the node.
protected  void renderTree(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
          Render the children of the specified tree node as html markup and append the output to the specified buffer.
protected  void renderTreeNode(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
          Render the specified treeNode.
protected  void renderTreeNodeEnd(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
          Interception point to render html after the tree node was rendered.
protected  void renderTreeNodeStart(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
          Interception point to render html before the tree node is rendered.
protected  void renderValue(HtmlStringBuffer buffer, TreeNode treeNode)
          Render the node's value.
 void select(String id)
          Select the node with matching id and inform any listeners of the change.
 void select(TreeNode node)
          Select the node and inform any listeners of the change.
 void selectAll()
          Select all the nodes of the tree and inform any listeners of the change.
protected  void selectOrDeselect(String[] ids)
          Swaps the select state of all TreeNodes with specified id's to the new value.
 void setActionListener(ActionListener listener)
          Set the control's action listener.
 void setDecorator(Decorator decorator)
          Set the tree's decorator which enables a interception point for users to render the tree nodes.
protected  void setExpandState(Collection<TreeNode> nodes, boolean newValue)
          Sets the TreeNode expand state of each node in the specified collection to the new value.
protected  void setExpandState(String id, boolean newValue)
          Sets the expand state of the TreeNode with specified id to the new value.
protected  void setExpandState(TreeNode node, boolean newValue)
          Sets the TreeNode expand state to the new value.
 void setHeight(String value)
          Set the the CSS "height" style attribute of the tree.
 void setJavascriptEnabled(boolean newValue)
          Enables javascript functionality.
 void setJavascriptEnabled(boolean newValue, int javascriptPolicy)
          Overloads setJavascriptEnabled(boolean).
 void setListener(Object listener, String method)
          Set the controls event listener.
 void setName(String name)
           
 void setNotifyListeners(boolean notifyListeners)
          Enable or disable if the tree will notify its tree listeners of any change to the tree's model.
 void setRootNode(TreeNode rootNode)
          Set the tree's root TreeNode.
 void setRootNodeDisplayed(boolean rootNodeDisplayed)
          Sets whether the tree's root node should be displayed or not.
protected  void setSelectState(Collection<TreeNode> nodes, boolean newValue)
          Sets the TreeNode select state of each node in the specified collection to the new value.
protected  void setSelectState(String id, boolean newValue)
          Sets the select state of the TreeNode with specified id to the new value.
protected  void setSelectState(TreeNode node, boolean newValue)
          Sets the TreeNode select state to the new value.
 void setWidth(String value)
          Set the the CSS "width" style attribute of the tree.
protected  boolean shouldRenderChildren(TreeNode treeNode)
          Check the state of the specified node if its children should be rendered or not.
 String toString()
          Return a HTML rendered Tree string of all the tree's nodes.
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHtmlImports, getId, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onInit, onRender, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setAttribute, setId, setParent, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EXPAND_TREE_NODE_PARAM

public static final String EXPAND_TREE_NODE_PARAM
The tree's expand/collapse parameter name: "expandTreeNode".

See Also:
Constant Field Values

SELECT_TREE_NODE_PARAM

public static final String SELECT_TREE_NODE_PARAM
The tree's select/deselect parameter name: "selectTreeNode".

See Also:
Constant Field Values

JAVASCRIPT_COOKIE_POLICY

public static final int JAVASCRIPT_COOKIE_POLICY
Indicator for using cookies to implement client side behavior.

See Also:
Constant Field Values

JAVASCRIPT_SESSION_POLICY

public static final int JAVASCRIPT_SESSION_POLICY
Indicator for using the session to implement client side behavior.

See Also:
Constant Field Values

EXPAND_ICON

protected static final String EXPAND_ICON
The tree's expand icon name: "expandedIcon".

See Also:
Constant Field Values

COLLAPSE_ICON

protected static final String COLLAPSE_ICON
The tree's collapsed icon name: "collapsedIcon".

See Also:
Constant Field Values

LEAF_ICON

protected static final String LEAF_ICON
The tree's leaf icon name: "leafIcon".

See Also:
Constant Field Values

rootNode

protected TreeNode rootNode
The tree's hierarchical data model.


selectOrDeselectNodeIds

protected String[] selectOrDeselectNodeIds
Array of ids that must be selected or deselected.


expandOrCollapseNodeIds

protected String[] expandOrCollapseNodeIds
Array of ids that must be expanded or collapsed.


selectLink

protected ActionLink selectLink
The Tree node select / deselect link.


expandLink

protected ActionLink expandLink
The tree node expand / collapse link.


javascriptHandler

protected transient Tree.JavascriptHandler javascriptHandler
Keep track of node id's, as they are selected, deselected, expanded and collapsed.

See Also:
Tree.JavascriptHandler
Constructor Detail

Tree

public Tree(String name)
Create an Tree control for the given name.

The constructor also sets the id attribute to "tree" and the css class to "treestyle" to qualify the tree control when styled by tree.css. If the css class value is changed, ensure to also change the tree.css selectors that still reference "treestyle".

Parameters:
name - the tree name
Throws:
IllegalArgumentException - if the name is null

Tree

public Tree()
Create a Tree with no name defined.

The constructor also sets the id attribute to "tree" and the css class to "treestyle" to qualify the tree control when styled by tree.css. If the css class value is changed, ensure to also change the tree.css selectors that still reference "treestyle".

Please note the control's name must be defined before it is valid.

Method Detail

setName

public void setName(String name)
Specified by:
setName in interface Control
Overrides:
setName in class AbstractControl
Parameters:
name - of the control
Throws:
IllegalArgumentException - if the name is null
See Also:
Control.setName(String)

getRootNode

public TreeNode getRootNode()
Return the tree's root TreeNode. This method will recalculate the tree's root node in case a new root node was set.

Returns:
the tree's root TreeNode.

hasRootNode

public boolean hasRootNode()
Return if tree has a root node.

Returns:
boolean indicating if the tree's root has been set.

isRootNodeDisplayed

public boolean isRootNodeDisplayed()
Return if the tree's root node should be displayed or not.

Returns:
if root node should be displayed

setRootNodeDisplayed

public void setRootNodeDisplayed(boolean rootNodeDisplayed)
Sets whether the tree's root node should be displayed or not.

Parameters:
rootNodeDisplayed - true if the root node should be displayed, false otherwise

setRootNode

public void setRootNode(TreeNode rootNode)
Set the tree's root TreeNode.

Parameters:
rootNode - node will be set as the root

getDecorator

public Decorator getDecorator()
Get the tree's decorator.

Returns:
the tree's decorator.

setDecorator

public void setDecorator(Decorator decorator)
Set the tree's decorator which enables a interception point for users to render the tree nodes.

Parameters:
decorator - the tree's decorator

isJavascriptEnabled

public boolean isJavascriptEnabled()
Returns if javascript functionality are enabled or not.

Returns:
true if javascript functions are enabled, false otherwise
See Also:
setJavascriptEnabled(boolean)

setJavascriptEnabled

public void setJavascriptEnabled(boolean newValue)
Enables javascript functionality.

If true the tree will be navigable in the browser using javascript, instead of doing round trips to the server on each operation.

With javascript enabled you need to store the values passed from the browser between requests. The tree currently supports the following options:

This method will try and determine which policy should be applied to the current request by checking the value HttpServletRequest.isRequestedSessionIdFromCookie(). If HttpServletRequest.isRequestedSessionIdFromCookie() returns true, JAVASCRIPT_COOKIE_POLICY will be used, otherwise JAVASCRIPT_SESSION_POLICY.

Note: if javascript is enabled, then the entire tree is rendered even if some nodes are in a collapsed state. This enables the tree to still be fully navigable in the browser. However nodes that are in a collapsed state are still displayed as collapsed using the style "display:none".

Parameters:
newValue - the value to set the javascriptEnabled property to
Throws:
IllegalArgumentException - if the context is null
See Also:
setJavascriptEnabled(boolean, int)

setJavascriptEnabled

public void setJavascriptEnabled(boolean newValue,
                                 int javascriptPolicy)
Overloads setJavascriptEnabled(boolean). Enables one to select the javascript policy to apply.

Parameters:
newValue - the value to set the javascriptEnabled property to
javascriptPolicy - the current javascript policy
Throws:
IllegalArgumentException - if the context is null
See Also:
setJavascriptEnabled(boolean)

getWidth

public String getWidth()
Return the CSS "width" style attribute of the tree, or null if not defined.

Returns:
the CSS "width" style attribute of the tree, or null if not defined

setWidth

public void setWidth(String value)
Set the the CSS "width" style attribute of the tree. For example:
 Tree tree = new Tree("mytree");
 tree.setWidth("200px"); 

Parameters:
value - the CSS "width" style attribute

getHeight

public String getHeight()
Return the CSS "height" style of the tree, or null if not defined.

Returns:
the CSS "height" style attribute of the tree, or null if not defined

setHeight

public void setHeight(String value)
Set the the CSS "height" style attribute of the tree. For example:
 Tree tree = new Tree("mytree");
 tree.setHeight("200px"); 

Parameters:
value - the CSS "height" style attribute

getHeadElements

public List<Element> getHeadElements()
Return the Tree HTML HEAD elements for the following resources:

Specified by:
getHeadElements in interface Control
Overrides:
getHeadElements in class AbstractControl
Returns:
the HTML HEAD elements for the control
See Also:
Control.getHeadElements()

getExpandLink

public ActionLink getExpandLink()
Return the tree node expand / collapse link.

This method returns a SubmitLink so that the Tree can function properly when added to a Form.

Returns:
the tree node expand / collapse link

getSelectLink

public ActionLink getSelectLink()
Return the tree node select / deselect link.

This method returns a SubmitLink so that the Tree can function properly when added to a Form.

Returns:
the tree node select / deselect link.

bindExpandOrCollapseValues

public void bindExpandOrCollapseValues()
This method binds the users request of expanded and collapsed nodes to the tree's nodes.


bindSelectOrDeselectValues

public void bindSelectOrDeselectValues()
This method binds the users request of selected nodes to the tree's nodes.


isNotifyListeners

public boolean isNotifyListeners()
Query if the tree will notify its tree listeners of any change to the tree's model.

Returns:
true if listeners should be notified of any changes.

setNotifyListeners

public void setNotifyListeners(boolean notifyListeners)
Enable or disable if the tree will notify its tree listeners of any change to the tree's model.

Parameters:
notifyListeners - true if the tree will notify its listeners , false otherwise

expand

public void expand(String id)
Expand the node with matching id and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify its listeners of any change.

Parameters:
id - identifier of the node to be expanded.

expand

public void expand(TreeNode node)
Expand the node and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
node - the node to be expanded.

collapse

public void collapse(String id)
Collapse the node with matching id and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
id - identifier of node to be collapsed.

collapse

public void collapse(TreeNode node)
Collapse the node and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
node - the node to be collapsed.

expandAll

public void expandAll()
Expand all the nodes of the tree and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.


collapseAll

public void collapseAll()
Collapse all the nodes of the tree and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.


select

public void select(String id)
Select the node with matching id and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
id - identifier of node to be selected.

select

public void select(TreeNode node)
Select the node and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
node - the node to be selected.

deselect

public void deselect(String id)
Deselect the node with matching id and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
id - id of node to be deselected.

deselect

public void deselect(TreeNode node)
Deselect the node and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.

Parameters:
node - the node to be deselected.

selectAll

public void selectAll()
Select all the nodes of the tree and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.


deselectAll

public void deselectAll()
Deselect all the nodes of the tree and inform any listeners of the change. If isNotifyListeners() returns false, this method will not notify listeners of any change.


getExpandedNodes

public List<TreeNode> getExpandedNodes(boolean includeInvisibleNodes)
Returns all the nodes that were expanded.

Parameters:
includeInvisibleNodes - indicator if only invisible nodes should be included
Returns:
list of currently expanded nodes

getSelectedNodes

public List<TreeNode> getSelectedNodes(boolean includeInvisibleNodes)
Returns all the nodes that were selected.

Parameters:
includeInvisibleNodes - indicates if invisible nodes should be included.
Returns:
list of currently selected nodes.

iterator

public Iterator<TreeNode> iterator()
Returns an iterator over all the nodes.

Returns:
iterator over all elements in the tree

iterator

public Iterator<TreeNode> iterator(TreeNode node)
Returns an iterator over all nodes starting from the specified node. If null is specified, root node is used instead.

Parameters:
node - starting point of nodes to iterator over
Returns:
iterator over all nodes starting form the specified node

find

public TreeNode find(String id)
Finds and returns the first node that matches the id.

Parameters:
id - identifier of the node to find
Returns:
TreeNode the first node matching the id.
Throws:
IllegalArgumentException - if argument is null.

bindRequestValue

public void bindRequestValue()
This method binds any expand/collapse and select/deselect changes from the request parameters.

In other words the node id's of expanded, collapsed, selected and deselected nodes are retrieved from the request.

See Also:
bindExpandOrCollapseValues(), bindSelectOrDeselectValues()

onProcess

public boolean onProcess()
Processes user request to change state of the tree. This implementation processes any expand/collapse and select/deselect changes as requested.

Thus expanded nodes will be collapsed and collapsed nodes will be expanded. Similarly selected nodes will be deselected and deselected nodes will be selected.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class AbstractControl
Returns:
true to continue Page event processing or false otherwise
See Also:
Control.onProcess(), expandOrCollapse(java.lang.String[]), selectOrDeselect(java.lang.String[])

onDestroy

public void onDestroy()
This method cleans up the expandLink and selectLink.

Specified by:
onDestroy in interface Control
Overrides:
onDestroy in class AbstractControl
See Also:
Control.onDestroy()

setListener

public void setListener(Object listener,
                        String method)
Set the controls event listener.

To receive notifications when TreeNodes are selected or expanded please use addListener(TreeListener).

Specified by:
setListener in interface Control
Overrides:
setListener in class AbstractControl
Parameters:
listener - the listener object with the named method to invoke
method - the name of the method to invoke

setActionListener

public void setActionListener(ActionListener listener)
Set the control's action listener.

To receive notifications when TreeNodes are selected or expanded please use addListener(TreeListener).

Overrides:
setActionListener in class AbstractControl
Parameters:
listener - the control's action listener

addListener

public void addListener(TreeListener listener)
Adds the listener to start receiving tree events.

Parameters:
listener - to add to start receiving tree events.

removeListener

public void removeListener(TreeListener listener)
Removes the listener to stop receiving tree events.

Parameters:
listener - to be removed to stop receiving tree events.

getControlSizeEst

public int getControlSizeEst()
Overrides:
getControlSizeEst in class AbstractControl
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()

cleanupSession

public void cleanupSession()
Utility method that force the Tree to remove any entries it made in the HttpSession.

Note Tree only stores a value in the Session when JavaScript is enabled and set to JAVASCRIPT_SESSION_POLICY.


render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the tree.

Specified by:
render in interface Control
Overrides:
render in class AbstractControl
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
toString()

toString

public String toString()
Return a HTML rendered Tree string of all the tree's nodes.

Note: by default the tree's root node will not be rendered. However this behavior can be changed by calling setRootNodeDisplayed(boolean) with true.

Overrides:
toString in class AbstractControl
Returns:
a HTML rendered Tree string
See Also:
Object.toString()

renderTree

protected void renderTree(HtmlStringBuffer buffer,
                          TreeNode treeNode,
                          int indentation)
Render the children of the specified tree node as html markup and append the output to the specified buffer.

Note: only the children of the specified tree node will be rendered not the treeNode itself. This method is recursive, so the node's children and their children will be rendered and so on.

Parameters:
buffer - string buffer containing the markup
treeNode - specified node who's children will be rendered
indentation - current level of the treeNode. The indentation increases each time the depth of the tree increments.
See Also:
setRootNodeDisplayed(boolean)

shouldRenderChildren

protected boolean shouldRenderChildren(TreeNode treeNode)
Check the state of the specified node if its children should be rendered or not.

Parameters:
treeNode - specified node to check
Returns:
true if the child nodes should be rendered, false otherwise

renderTreeNodeStart

protected void renderTreeNodeStart(HtmlStringBuffer buffer,
                                   TreeNode treeNode,
                                   int indentation)
Interception point to render html before the tree node is rendered.

Parameters:
buffer - string buffer containing the markup
treeNode - specified node to render
indentation - current level of the treeNode

renderTreeNodeEnd

protected void renderTreeNodeEnd(HtmlStringBuffer buffer,
                                 TreeNode treeNode,
                                 int indentation)
Interception point to render html after the tree node was rendered.

Parameters:
buffer - string buffer containing the markup
treeNode - specified node to render
indentation - current level of the treeNode

renderExpandAndCollapseAction

protected void renderExpandAndCollapseAction(HtmlStringBuffer buffer,
                                             TreeNode treeNode)
Render the expand and collapse action of the tree.

Default implementation creates a hyperlink that users can click on to expand or collapse the nodes.

Parameters:
buffer - string buffer containing the markup
treeNode - treeNode to render

renderTreeNode

protected void renderTreeNode(HtmlStringBuffer buffer,
                              TreeNode treeNode,
                              int indentation)
Render the specified treeNode.

If a decorator was specified using setDecorator(Decorator), this method will render using the decorator instead.

Parameters:
buffer - string buffer containing the markup
treeNode - treeNode to render
indentation - current level of the treeNode

renderIcon

protected void renderIcon(HtmlStringBuffer buffer,
                          TreeNode treeNode)
Render the node's icon depending on the current state of the node.

Parameters:
buffer - string buffer containing the markup
treeNode - treeNode to render

renderValue

protected void renderValue(HtmlStringBuffer buffer,
                           TreeNode treeNode)
Render the node's value.

Subclasses should override this method to change the rendering of the node's value. By default the value will be rendered as a hyperlink, passing its id to the server.

Parameters:
buffer - string buffer containing the markup
treeNode - treeNode to render

getExpandClass

protected String getExpandClass(TreeNode treeNode)
Query the specified treeNode and check which css class to apply.

Possible classes are expanded, collapsed, leaf, expandedLastNode, collapsedLastNode and leafLastNode.

Parameters:
treeNode - the tree node to check for css class
Returns:
string specific css class to apply

getIconClass

protected String getIconClass(TreeNode treeNode)
Query the specified treeNode and check which css class to apply for the icons.

Possible classes are expandedIcon, collapsedIcon and leafIcon.

Parameters:
treeNode - the tree node to check for css class
Returns:
string specific css class to apply

isExpandedParent

protected boolean isExpandedParent(TreeNode treeNode)
Helper method indicating if the specified node is both expanded and has at least 1 child node.

Parameters:
treeNode - specified node to check
Returns:
true if the specified node is both expanded and contains at least 1 child node

fireNodeExpanded

protected void fireNodeExpanded(TreeNode node,
                                boolean previousState)
Notifies all listeners currently registered with the tree, about any expand events.

Parameters:
node - specify the TreeNode that was expanded
previousState - contains the previous expanded state

fireNodeCollapsed

protected void fireNodeCollapsed(TreeNode node,
                                 boolean previousState)
Notifies all listeners currently registered with the tree, about any collapse events.

Parameters:
node - specific the TreeNode that was collapsed
previousState - contains the previous expanded state

fireNodeSelected

protected void fireNodeSelected(TreeNode node,
                                boolean previousState)
Notifies all listeners currently registered with the tree, about any selection events.

Parameters:
node - specific the TreeNode that was selected
previousState - contains the previous selected state

fireNodeDeselected

protected void fireNodeDeselected(TreeNode node,
                                  boolean previousState)
Notifies all listeners currently registered with the tree, about any deselection events.

Parameters:
node - specific the TreeNode that was deselected
previousState - contains the previous selected state

setExpandState

protected void setExpandState(TreeNode node,
                              boolean newValue)
Sets the TreeNode expand state to the new value.

Parameters:
node - specifies the TreeNode which expand state will be set
newValue - specifies the new expand state

expandOrCollapse

protected void expandOrCollapse(String[] ids)
Swaps the expand state of all TreeNodes with specified id's. Thus if a node's expand state is currently 'true', calling expandOrCollapse will set the expand state to 'false' and vice versa.

Parameters:
ids - array of node id's

setExpandState

protected void setExpandState(String id,
                              boolean newValue)
Sets the expand state of the TreeNode with specified id to the new value.

Parameters:
id - specifies the id of a TreeNode which expand state will be set
newValue - specifies the new expand state

setExpandState

protected void setExpandState(Collection<TreeNode> nodes,
                              boolean newValue)
Sets the TreeNode expand state of each node in the specified collection to the new value.

Parameters:
nodes - specifies the collection of a TreeNodes which expand states will be set
newValue - specifies the new expand state

setSelectState

protected void setSelectState(TreeNode node,
                              boolean newValue)
Sets the TreeNode select state to the new value.

Parameters:
node - specifies the TreeNode which select state will be set
newValue - specifies the new select state

selectOrDeselect

protected void selectOrDeselect(String[] ids)
Swaps the select state of all TreeNodes with specified id's to the new value. Thus if a node's select state is currently 'true', calling selectOrDeselect will set the select state to 'false' and vice versa.

Parameters:
ids - array of node id's

setSelectState

protected void setSelectState(String id,
                              boolean newValue)
Sets the select state of the TreeNode with specified id to the new value.

Parameters:
id - specifies the id of a TreeNode which select state will be set
newValue - specifies the new select state

setSelectState

protected void setSelectState(Collection<TreeNode> nodes,
                              boolean newValue)
Sets the TreeNode select state of each node in the specified collection to the new value.

Parameters:
nodes - specifies the collection of a TreeNodes which select states will be set
newValue - specifies the new select state

processNodes

protected void processNodes(String[] ids,
                            Tree.Callback callback)
Provides callback functionality for all the specified nodes.

Parameters:
ids - the array of nodes to process
callback - object on which callbacks are made

processNodes

protected void processNodes(Collection<TreeNode> nodes,
                            Tree.Callback callback)
Provides callback functionality for all the specified nodes.

Parameters:
nodes - the collection of nodes to process
callback - object on which callbacks are made

find

protected TreeNode find(TreeNode node,
                        String id)
Finds and returns the first node that matches the id, starting the search from the specified node.

Parameters:
node - specifies at which node the search must start from
id - specifies the id of the TreeNode to find
Returns:
TreeNode the first node matching the id or null if no match was found.

getRequestValue

protected String getRequestValue(String name)
Returns the value of the specified named parameter or a empty string "" if not found.

Parameters:
name - specifies the parameter to return
Returns:
the specified parameter or a empty string "" if not found

getRequestValues

protected String[] getRequestValues(String name)
Returns an array of all values of the specified named parameter or null if the parameter does not exist.

Parameters:
name - specifies the parameter to return
Returns:
all matching parameters or null if no parameter was found

getHref

protected String getHref(Map<String,? extends Object> parameters)
Return an anchor <a> tag href attribute for the given parameters. This method will encode the URL with the session ID if required using HttpServletResponse.encodeURL().

Parameters:
parameters - the href parameters
Returns:
the HTML href attribute

createJavascriptHandler

protected Tree.JavascriptHandler createJavascriptHandler(int javascriptPolicy)
Creates a new JavascriptHandler based on the specified policy.

Parameters:
javascriptPolicy - the current javascript policy
Returns:
newly created JavascriptHandler