net.sf.click.extras.tree
Class Tree

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.extras.tree.Tree
All Implemented Interfaces:
Control, Serializable
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 screenshot of how the tree will render in a browser.

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;
     }
 } 

Tree Style

The Tree control automatically deploys the tree CSS style sheet (tree.css) and javascript (tree.js) to the application directory /click/tree. To import the style sheet simply reference the PageImports object. For example:
 <html>
    <head>
       $imports
    </head>
    <body>
       $tree
    </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 classes are set in a <span> element.
<span class="leafIcon">
renders the leaf node of the tree
<span class="expandedIcon">
renders the expanded state of a node
<span class="collapsedIcon">
renders the collapsed state of a node
Credit goes to Wicket for the following:

Author:
Bob Schellink
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  String[] expandOrCollapseNodeIds
          Array of ids that must be expanded or collapsed.
static String JAVASCRIPT_COOKIE_IMPORTS
          Client side javascript cookie import link.
static int JAVASCRIPT_COOKIE_POLICY
          Indicator for using cookies to implement client side behavior.
static String JAVASCRIPT_IMPORTS
          Client side javascript import link.
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  String[] selectOrDeselectNodeIds
          Array of ids that must be selected or deselected.
protected static String[] TREE_IMAGES
          The Tree image file names.
static String TREE_IMPORTS
          The tree.css style sheet import link.
static String[] TREE_RESOURCES
          The Tree resource file names.
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.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 oldValue)
          Notifies all listeners currently registered with the tree, about any collapse events.
protected  void fireNodeDeselected(TreeNode node, boolean oldValue)
          Notifies all listeners currently registered with the tree, about any deselection events.
protected  void fireNodeExpanded(TreeNode node, boolean oldValue)
          Notifies all listeners currently registered with the tree, about any expand events.
protected  void fireNodeSelected(TreeNode node, boolean oldValue)
          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 getExpandedNodes(boolean includeInvisibleNodes)
          Returns all the nodes that were expanded.
protected  String getHref(Map parameters)
          Return an anchor <a> tag href attribute for the given parameters.
 String getHtmlImports()
          Return the HTML head import statements for the CSS stylesheet file: click/tree/tree.css.
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 getSelectedNodes(boolean includeInvisibleNodes)
          Returns all the nodes that were selected.
 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 iterator()
          Returns an iterator over all the nodes.
 Iterator iterator(TreeNode node)
          Returns an iterator over all nodes starting from the specified node.
 void onDeploy(ServletContext servletContext)
          Deploy all files defined in the constants TREE_RESOURCES and TREE_IMAGES to the click/tree web directory when the application is initialized.
 boolean onProcess()
          Processes user request to change state of the tree.
protected  void processNodes(Collection 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)
          This method does nothing.
 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 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 setJavascriptEnabled(boolean newValue)
          Enables javascript functionality.
 void setJavascriptEnabled(boolean newValue, int javascriptPolicy)
          Overloads setJavascriptEnabled(boolean).
 void setListener(Object listener, String method)
          This method does nothing.
 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 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.
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 net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getId, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasStyles, onDestroy, onInit, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setAttribute, setId, setName, 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

TREE_IMPORTS

public static final String TREE_IMPORTS
The tree.css style sheet import link.

See Also:
Constant Field Values

JAVASCRIPT_IMPORTS

public static final String JAVASCRIPT_IMPORTS
Client side javascript import link.

See Also:
Constant Field Values

JAVASCRIPT_COOKIE_IMPORTS

public static final String JAVASCRIPT_COOKIE_IMPORTS
Client side javascript cookie import link.

See Also:
Constant Field Values

TREE_RESOURCES

public static final String[] TREE_RESOURCES
The Tree resource file names.


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

TREE_IMAGES

protected static final String[] TREE_IMAGES
The Tree image file names.


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.


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

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 navigatable 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 navigatable 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)

getHtmlImports

public String getHtmlImports()
Return the HTML head import statements for the CSS stylesheet file: click/tree/tree.css.

If javascript is enabled, this method also includes the head import Javascript file: click/tree/tree.js.

Returns:
the HTML head import statements for the control stylesheet

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 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 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.

onDeploy

public void onDeploy(ServletContext servletContext)
Deploy all files defined in the constants TREE_RESOURCES and TREE_IMAGES to the click/tree web directory when the application is initialized.

Parameters:
servletContext - the servlet context
See Also:
Control.onDeploy(ServletContext)

iterator

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

Returns:
iterator over all elements in the tree

iterator

public Iterator 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.

Returns:
true to continue Page event processing or false otherwise
See Also:
Control.onProcess(), expandOrCollapse(java.lang.String[]), selectOrDeselect(java.lang.String[])

setListener

public void setListener(Object listener,
                        String method)
This method does nothing.

Please use the addListener(TreeListener) method instead.

Parameters:
listener - the listener object with the named method to invoke
method - the name of the method to invoke
See Also:
Control.setListener(Object, String)

setActionListener

public void setActionListener(ActionListener listener)
This method does nothing.

Please use the addListener(TreeListener) method instead.

Parameters:
listener - the control's action listener
See Also:
Control.setListener(Object, String)

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()
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()

render

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

Parameters:
buffer - the specified buffer to render the control's output to
See Also:
toString()

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.


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.

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 oldValue)
Notifies all listeners currently registered with the tree, about any expand events.

Parameters:
node - specify the TreeNode that was expanded
oldValue - previous expanded value of the specified node

fireNodeCollapsed

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

Parameters:
node - specific the TreeNode that was collapsed
oldValue - previous collapsed value of the specified node

fireNodeSelected

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

Parameters:
node - specific the TreeNode that was selected
oldValue - previous selected value of the specified node

fireNodeDeselected

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

Parameters:
node - specific the TreeNode that was deselected
oldValue - previous deselected value of the specified node

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 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 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 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 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