org.apache.click.extras.tree
Class Tree.CookieHandler

java.lang.Object
  extended by org.apache.click.extras.tree.Tree.CookieHandler
All Implemented Interfaces:
Serializable, Tree.JavascriptHandler, TreeListener
Direct Known Subclasses:
CheckboxTree.CheckboxCookieHandler
Enclosing class:
Tree

protected class Tree.CookieHandler
extends Object
implements Tree.JavascriptHandler

Please note this class is only meant for developers of this control, not users.

This class implements a cookie based javascript handler. Cookies in the browser tracks the expand and collapse state of the nodes. When a request is made to the server the cookies is processed and the state of the nodes are modified accordingly.

There are two cookies used to track the state:

The cookies are removed between requests. New requests issue new cookies and update the state of the nodes accordingly.

Note: This class is used in conjunction with cookie-helper.js which manipulates the cookie values in the browser as the user navigates the tree.

See Also:
Serialized Form

Field Summary
protected  String collapsedCookieName
          Name of cookie responsible for tracking the expanded node id's.
protected  String expandedCookieName
          Name of cookie responsible for tracking the expanded node id's.
protected  Tree.JavascriptRenderer javascriptRenderer
          Variable holding a javascript renderer.
 
Constructor Summary
protected Tree.CookieHandler(Context context)
          Creates and initializes a new CookieHandler.
 
Method Summary
protected  Set<String> asSet(String value, String delim)
          Returns the specified string value as a set, tokenizing the string based on the specified delimiter.
 void destroy()
          Called to indicate the user request cycle is complete.
 Tree.JavascriptRenderer getJavascriptRenderer()
          Returns the javascript renderer associated with this handler.
 void init(Context context)
          Initialize the handler state from the current cookies.
 void nodeCollapsed(Tree tree, TreeNode node, Context context, boolean oldValue)
          Removes the specified node from the cookie handler tracker.
 void nodeDeselected(Tree tree, TreeNode node, Context context, boolean oldValue)
          Invoked when user deselected the specified node.
 void nodeExpanded(Tree tree, TreeNode node, Context context, boolean oldValue)
          Adds the specified node to the cookie handler tracker.
 void nodeSelected(Tree tree, TreeNode node, Context context, boolean oldValue)
          Invoked when user selected the specified node.
protected  String prepareCookieValue(String value)
          Does some preparation on the cookie value like decoding and stripping of unneeded characters.
 boolean renderAsExpanded(TreeNode treeNode)
          Currently this implementation just calls Tree.isExpandedParent(TreeNode).
protected  void setCookie(String value, String name)
          Sets a cookie with the specified name and value to the http response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expandedCookieName

protected final String expandedCookieName
Name of cookie responsible for tracking the expanded node id's.


collapsedCookieName

protected final String collapsedCookieName
Name of cookie responsible for tracking the expanded node id's.


javascriptRenderer

protected Tree.JavascriptRenderer javascriptRenderer
Variable holding a javascript renderer.

Constructor Detail

Tree.CookieHandler

protected Tree.CookieHandler(Context context)
Creates and initializes a new CookieHandler.

Parameters:
context - provides access to the http request, and session
Method Detail

init

public void init(Context context)
Initialize the handler state from the current cookies.

Specified by:
init in interface Tree.JavascriptHandler
Parameters:
context - provides access to the http request, and session

renderAsExpanded

public boolean renderAsExpanded(TreeNode treeNode)
Currently this implementation just calls Tree.isExpandedParent(TreeNode).

CookieHandler uses cookies to sync any state change on the browser with the server, so the handler will not contain any state outside of the treeNode.

Specified by:
renderAsExpanded in interface Tree.JavascriptHandler
Parameters:
treeNode - the specified treeNode to check if it is part of the users selected paths
Returns:
true if the specified treeNode is part of the users selected path, false otherwise
See Also:
renderAsExpanded(TreeNode)

destroy

public void destroy()
Description copied from interface: Tree.JavascriptHandler
Called to indicate the user request cycle is complete. Any last minute tasks can be performed here.

Specified by:
destroy in interface Tree.JavascriptHandler
See Also:
destroy()

getJavascriptRenderer

public Tree.JavascriptRenderer getJavascriptRenderer()
Description copied from interface: Tree.JavascriptHandler
Returns the javascript renderer associated with this handler.

Specified by:
getJavascriptRenderer in interface Tree.JavascriptHandler
Returns:
currently installed javascript renderer
See Also:
getJavascriptRenderer()

nodeExpanded

public void nodeExpanded(Tree tree,
                         TreeNode node,
                         Context context,
                         boolean oldValue)
Adds the specified node to the cookie handler tracker.

Specified by:
nodeExpanded in interface TreeListener
Parameters:
tree - tree the operation was made on
node - node that was expanded
context - provides access to Context
oldValue - contains the previous value of expanded state
See Also:
TreeListener.nodeExpanded(Tree, TreeNode, Context, boolean)

nodeCollapsed

public void nodeCollapsed(Tree tree,
                          TreeNode node,
                          Context context,
                          boolean oldValue)
Removes the specified node from the cookie handler tracker.

Specified by:
nodeCollapsed in interface TreeListener
Parameters:
tree - tree the operation was made on
node - node that was collapsed
context - provides access to Context
oldValue - contains the previous value of selected state
See Also:
TreeListener.nodeCollapsed(Tree, TreeNode, Context, boolean)

nodeSelected

public void nodeSelected(Tree tree,
                         TreeNode node,
                         Context context,
                         boolean oldValue)
Description copied from interface: TreeListener
Invoked when user selected the specified node.

Specified by:
nodeSelected in interface TreeListener
Parameters:
tree - tree the operation was made on
node - node that was selected
context - provides access to Context
oldValue - contains the previous value of selected state
See Also:
TreeListener.nodeSelected(Tree, TreeNode, Context, boolean)

nodeDeselected

public void nodeDeselected(Tree tree,
                           TreeNode node,
                           Context context,
                           boolean oldValue)
Description copied from interface: TreeListener
Invoked when user deselected the specified node.

Specified by:
nodeDeselected in interface TreeListener
Parameters:
tree - tree the operation was made on
node - node that was selected
context - provides access to Context
oldValue - contains the previous value of selected state
See Also:
TreeListener.nodeDeselected(Tree, TreeNode, Context, boolean)

setCookie

protected void setCookie(String value,
                         String name)
Sets a cookie with the specified name and value to the http response.

Parameters:
value - the cookie's value
name - the cookie's name

prepareCookieValue

protected String prepareCookieValue(String value)
Does some preparation on the cookie value like decoding and stripping of unneeded characters.

Parameters:
value - the cookie's value to prepare
Returns:
the prepared value

asSet

protected Set<String> asSet(String value,
                            String delim)
Returns the specified string value as a set, tokenizing the string based on the specified delimiter.

Parameters:
value - value to return as set
delim - delimiter used to tokenize the value
Returns:
set of tokens