|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.extras.tree.Tree.SessionHandler
Please note this class is only meant for developers of this control, not users.
This class implements a session based javascript handler. It manages the client side javascript behavior by tracking the client's selected tree paths. The problem: when javascript is enabled, the entire tree must be sent to the browser to be navigatable without round trips to the server. However the tree should not be displayed in an expanded state so css is used to apply the 'display: none' idiom to 'collapse' the nodes even though they are really expanded. On the browser as the user expands and collapses nodes he/she will make selections and deselections of certain nodes. Since the node's value is rendered as a hyperlink, selecting or deselecting the node will create a request to the server. After the round trip to the server the tree will again be rendered in a collapsed state because the server will apply the css 'display :none' idiom before returning to the browser. It would be nice if instead of collapsing the entire tree again, to keep those tree paths that lead to selected nodes in a expanded state. The solution: SessionHandler keeps track of the selected paths and is queried at rendering time which nodes should be hidden and which nodes should be displayed. The selected path are all the node's from the selected node up to the root node. SessionHandler also keeps track of the overlaid paths. Overlaid paths comes from two or more selected paths that share certain common nodes. Overlaid paths are used in determining when a selected path can be removed from the tracker. To understand this better here is an example tree (top to bottom):root node1 node2 node1.1 node1.2 node2.1 node2.2IF node1 is selected, the selected path would include the nodes "root and node1". If node1.1 is then selected, the selected path would also include the nodes "root, node1 and node1.1". The same ff node1.2 is selected. The overlaid path would include the shared nodes of the three selected paths. Thus the overlaid path would consist of "root" because that node is shared by all three paths. Overlaid path will also contain "node1" because it is shared by node1.1 and node1.2. The implementation: To keep memory storage to a minimum, only the hashcode of a node is stored, and it is stored only once for any node on any selected path. Thus if n nodes in a tree are selected there will only be n hashcodes stored. The overlaid paths are stored in a object consisting of a counter which increments and decrements each time a path is selected or deselected. The overlaid path also stores a boolean indicating if a a node is the last node on the path or not. The last node in the selected path should not be expanded because we do not want the children of the last node to be displayed. Lets look at our previous example again. The overlaid paths would contain the following information:
AbstractControl.name
. If two tree's in the same session have the same name they
will overwrite each others session attribute!
Field Summary | |
protected Tree.JavascriptRenderer |
javascriptRenderer
Renders the needed javascript for this handler. |
Constructor Summary | |
protected |
Tree.SessionHandler(Context context)
This class is dependant on Context , so this
constructor enforces a valid context before the handler can be
used. |
Method Summary | |
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)
Retrieves the tracker from the http session if it exists. |
void |
nodeCollapsed(Tree tree,
TreeNode node,
Context context,
boolean oldValue)
Invoked when user collapsed the specified node. |
void |
nodeDeselected(Tree tree,
TreeNode node,
Context context,
boolean oldValue)
Removes all node's that are part of the selected path from the tracker. |
void |
nodeExpanded(Tree tree,
TreeNode node,
Context context,
boolean oldValue)
Invoked when user expanded the specified node. |
void |
nodeSelected(Tree tree,
TreeNode node,
Context context,
boolean oldValue)
Adds all node's that are part of the selected path to the tracker. |
boolean |
renderAsExpanded(TreeNode treeNode)
Queries the handler if the specified node should be rendered as expanded or not. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Tree.JavascriptRenderer javascriptRenderer
Constructor Detail |
protected Tree.SessionHandler(Context context)
Context
, so this
constructor enforces a valid context before the handler can be
used.
context
- provides access to the http request, and sessionMethod Detail |
public void init(Context context)
init
in interface Tree.JavascriptHandler
context
- provides access to the http request, and sessionpublic boolean renderAsExpanded(TreeNode treeNode)
renderAsExpanded
in interface Tree.JavascriptHandler
treeNode
- the specified node to check if it is expanded
or not
renderAsExpanded(TreeNode)
public void destroy()
Tree.JavascriptHandler
destroy
in interface Tree.JavascriptHandler
destroy()
public Tree.JavascriptRenderer getJavascriptRenderer()
Tree.JavascriptHandler
getJavascriptRenderer
in interface Tree.JavascriptHandler
getJavascriptRenderer()
public void nodeSelected(Tree tree, TreeNode node, Context context, boolean oldValue)
nodeSelected
in interface TreeListener
tree
- tree the operation was made onnode
- node that was selectedcontext
- provides access to Context
oldValue
- contains the previous value of selected stateTreeListener.nodeSelected(Tree, TreeNode, Context, boolean)
public void nodeDeselected(Tree tree, TreeNode node, Context context, boolean oldValue)
nodeDeselected
in interface TreeListener
tree
- tree the operation was made onnode
- node that was deselectedcontext
- provides access to Context
oldValue
- contains the previous value of selected stateTreeListener.nodeDeselected(Tree, TreeNode, Context, boolean)
public void nodeExpanded(Tree tree, TreeNode node, Context context, boolean oldValue)
TreeListener
nodeExpanded
in interface TreeListener
tree
- tree the operation was made onnode
- node that was expandedcontext
- provides access to Context
oldValue
- contains the previous value of expanded stateTreeListener.nodeExpanded(Tree, TreeNode, Context, boolean)
public void nodeCollapsed(Tree tree, TreeNode node, Context context, boolean oldValue)
TreeListener
nodeCollapsed
in interface TreeListener
tree
- tree the operation was made onnode
- node that was collapsedcontext
- provides access to Context
oldValue
- contains the previous value of selected stateTreeListener.nodeCollapsed(Tree, TreeNode, Context, boolean)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |