|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.control.AbstractControl net.sf.click.extras.tree.Tree
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.
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; } }
PageImports
object. For example:
<html> <head> $imports </head> <body> $tree </body> </html>
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 |
public static final String EXPAND_TREE_NODE_PARAM
public static final String SELECT_TREE_NODE_PARAM
public static final String TREE_IMPORTS
public static final String JAVASCRIPT_IMPORTS
public static final String JAVASCRIPT_COOKIE_IMPORTS
public static final String[] TREE_RESOURCES
public static final int JAVASCRIPT_COOKIE_POLICY
public static final int JAVASCRIPT_SESSION_POLICY
protected static final String[] TREE_IMAGES
protected static final String EXPAND_ICON
protected static final String COLLAPSE_ICON
protected static final String LEAF_ICON
protected TreeNode rootNode
protected String[] selectOrDeselectNodeIds
protected String[] expandOrCollapseNodeIds
protected transient Tree.JavascriptHandler javascriptHandler
Tree.JavascriptHandler
Constructor Detail |
public Tree(String name)
name
- the tree name
IllegalArgumentException
- if the name is nullpublic Tree()
Method Detail |
public TreeNode getRootNode()
public boolean hasRootNode()
public boolean isRootNodeDisplayed()
public void setRootNodeDisplayed(boolean rootNodeDisplayed)
rootNodeDisplayed
- true if the root node should be displayed,
false otherwisepublic void setRootNode(TreeNode rootNode)
rootNode
- node will be set as the rootpublic Decorator getDecorator()
public void setDecorator(Decorator decorator)
decorator
- the tree's decoratorpublic boolean isJavascriptEnabled()
setJavascriptEnabled(boolean)
public void setJavascriptEnabled(boolean newValue)
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".
newValue
- the value to set the javascriptEnabled property to
IllegalArgumentException
- if the context is nullsetJavascriptEnabled(boolean, int)
public void setJavascriptEnabled(boolean newValue, int javascriptPolicy)
setJavascriptEnabled(boolean)
. Enables one
to select the javascript policy to apply.
newValue
- the value to set the javascriptEnabled property tojavascriptPolicy
- the current javascript policy
IllegalArgumentException
- if the context is nullsetJavascriptEnabled(boolean)
public String getHtmlImports()
public void bindExpandOrCollapseValues()
public void bindSelectOrDeselectValues()
public boolean isNotifyListeners()
public void setNotifyListeners(boolean notifyListeners)
notifyListeners
- true if the tree will notify its listeners ,
false otherwisepublic void expand(String id)
isNotifyListeners()
returns false, this method will not
notify its listeners of any change.
id
- identifier of the node to be expanded.public void expand(TreeNode node)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
node
- the node to be expanded.public void collapse(String id)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
id
- identifier of node to be collapsed.public void collapse(TreeNode node)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
node
- the node to be collapsed.public void expandAll()
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
public void collapseAll()
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
public void select(String id)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
id
- identifier of node to be selected.public void select(TreeNode node)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
node
- the node to be selected.public void deselect(String id)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
id
- id of node to be deselected.public void deselect(TreeNode node)
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
node
- the node to be deselected.public void selectAll()
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
public void deselectAll()
isNotifyListeners()
returns false, this method will not
notify listeners of any change.
public List getExpandedNodes(boolean includeInvisibleNodes)
includeInvisibleNodes
- indicator if only invisible nodes should be included.
public List getSelectedNodes(boolean includeInvisibleNodes)
includeInvisibleNodes
- indicates if invisible nodes should be included.
public void onDeploy(ServletContext servletContext)
TREE_RESOURCES
and TREE_IMAGES
to the click/tree web
directory when the application is initialized.
servletContext
- the servlet contextControl.onDeploy(ServletContext)
public Iterator iterator()
public Iterator iterator(TreeNode node)
node
- starting point of nodes to iterator over
public TreeNode find(String id)
id
- identifier of the node to find
IllegalArgumentException
- if argument is null.public void bindRequestValue()
bindExpandOrCollapseValues()
,
bindSelectOrDeselectValues()
public boolean onProcess()
Control.onProcess()
,
expandOrCollapse(java.lang.String[])
,
selectOrDeselect(java.lang.String[])
public void setListener(Object listener, String method)
addListener(TreeListener)
method instead.
listener
- the listener object with the named method to invokemethod
- the name of the method to invokeControl.setListener(Object, String)
public void setActionListener(ActionListener listener)
addListener(TreeListener)
method instead.
listener
- the control's action listenerControl.setListener(Object, String)
public void addListener(TreeListener listener)
listener
- to add to start receiving tree events.public void removeListener(TreeListener listener)
listener
- to be removed to stop receiving tree events.public int getControlSizeEst()
AbstractControl.getControlSizeEst()
public void render(HtmlStringBuffer buffer)
buffer
- the specified buffer to render the control's output totoString()
public void cleanupSession()
JAVASCRIPT_SESSION_POLICY
.
public String toString()
setRootNodeDisplayed(boolean)
with true.
Object.toString()
protected void renderTree(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
buffer
- string buffer containing the markuptreeNode
- specified node who's children will be renderedindentation
- current level of the treeNode. The indentation increases each
time the depth of the tree increments.setRootNodeDisplayed(boolean)
protected boolean shouldRenderChildren(TreeNode treeNode)
treeNode
- specified node to check
protected void renderTreeNodeStart(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
buffer
- string buffer containing the markuptreeNode
- specified node to renderindentation
- current level of the treeNodeprotected void renderTreeNodeEnd(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
buffer
- string buffer containing the markuptreeNode
- specified node to renderindentation
- current level of the treeNodeprotected void renderExpandAndCollapseAction(HtmlStringBuffer buffer, TreeNode treeNode)
buffer
- string buffer containing the markuptreeNode
- treeNode to renderprotected void renderTreeNode(HtmlStringBuffer buffer, TreeNode treeNode, int indentation)
setDecorator(Decorator)
,
this method will render using the decorator instead.
buffer
- string buffer containing the markuptreeNode
- treeNode to renderindentation
- current level of the treeNodeprotected void renderIcon(HtmlStringBuffer buffer, TreeNode treeNode)
buffer
- string buffer containing the markuptreeNode
- treeNode to renderprotected void renderValue(HtmlStringBuffer buffer, TreeNode treeNode)
buffer
- string buffer containing the markuptreeNode
- treeNode to renderprotected String getExpandClass(TreeNode treeNode)
treeNode
- the tree node to check for css class
protected String getIconClass(TreeNode treeNode)
treeNode
- the tree node to check for css class
protected boolean isExpandedParent(TreeNode treeNode)
treeNode
- specified node to check
protected void fireNodeExpanded(TreeNode node, boolean oldValue)
node
- specify the TreeNode that was expandedoldValue
- previous expanded value of the specified nodeprotected void fireNodeCollapsed(TreeNode node, boolean oldValue)
node
- specific the TreeNode that was collapsedoldValue
- previous collapsed value of the specified nodeprotected void fireNodeSelected(TreeNode node, boolean oldValue)
node
- specific the TreeNode that was selectedoldValue
- previous selected value of the specified nodeprotected void fireNodeDeselected(TreeNode node, boolean oldValue)
node
- specific the TreeNode that was deselectedoldValue
- previous deselected value of the specified nodeprotected void setExpandState(TreeNode node, boolean newValue)
node
- specifies the TreeNode which expand state will be setnewValue
- specifies the new expand stateprotected void expandOrCollapse(String[] ids)
ids
- array of node id'sprotected void setExpandState(String id, boolean newValue)
id
- specifies the id of a TreeNode which expand state will be setnewValue
- specifies the new expand stateprotected void setExpandState(Collection nodes, boolean newValue)
nodes
- specifies the collection of a TreeNodes which expand states will be setnewValue
- specifies the new expand stateprotected void setSelectState(TreeNode node, boolean newValue)
node
- specifies the TreeNode which select state will be setnewValue
- specifies the new select stateprotected void selectOrDeselect(String[] ids)
ids
- array of node id'sprotected void setSelectState(String id, boolean newValue)
id
- specifies the id of a TreeNode which select state will be setnewValue
- specifies the new select stateprotected void setSelectState(Collection nodes, boolean newValue)
nodes
- specifies the collection of a TreeNodes which select states will be setnewValue
- specifies the new select stateprotected void processNodes(String[] ids, Tree.Callback callback)
ids
- the array of nodes to processcallback
- object on which callbacks are madeprotected void processNodes(Collection nodes, Tree.Callback callback)
nodes
- the collection of nodes to processcallback
- object on which callbacks are madeprotected TreeNode find(TreeNode node, String id)
node
- specifies at which node the search must start fromid
- specifies the id of the TreeNode to find
protected String getRequestValue(String name)
name
- specifies the parameter to return
protected String[] getRequestValues(String name)
name
- specifies the parameter to return
protected String getHref(Map parameters)
parameters
- the href parameters
protected Tree.JavascriptHandler createJavascriptHandler(int javascriptPolicy)
javascriptPolicy
- the current javascript policy
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |