|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.control.AbstractControl org.apache.click.extras.tree.Tree
public class 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; } }
<html> <head> $headElements </head> <body> $tree $jsElements </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 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 |
---|
public static final String EXPAND_TREE_NODE_PARAM
public static final String SELECT_TREE_NODE_PARAM
public static final int JAVASCRIPT_COOKIE_POLICY
public static final int JAVASCRIPT_SESSION_POLICY
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 ActionLink selectLink
protected ActionLink expandLink
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 void setName(String name)
setName
in interface Control
setName
in class AbstractControl
name
- of the control
IllegalArgumentException
- if the name is nullControl.setName(String)
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 navigable 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 getWidth()
public void setWidth(String value)
Tree tree = new Tree("mytree"); tree.setWidth("200px");
value
- the CSS "width" style attributepublic String getHeight()
public void setHeight(String value)
Tree tree = new Tree("mytree"); tree.setHeight("200px");
value
- the CSS "height" style attributepublic List<Element> getHeadElements()
getHeadElements
in interface Control
getHeadElements
in class AbstractControl
Control.getHeadElements()
public ActionLink getExpandLink()
SubmitLink
so that the Tree can function properly when added to a
Form
.
public ActionLink getSelectLink()
SubmitLink
so that the Tree can function properly when added to a
Form
.
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<TreeNode> getExpandedNodes(boolean includeInvisibleNodes)
includeInvisibleNodes
- indicator if only invisible nodes should be
included
public List<TreeNode> getSelectedNodes(boolean includeInvisibleNodes)
includeInvisibleNodes
- indicates if invisible nodes should be included.
public Iterator<TreeNode> iterator()
public Iterator<TreeNode> 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()
onProcess
in interface Control
onProcess
in class AbstractControl
Control.onProcess()
,
expandOrCollapse(java.lang.String[])
,
selectOrDeselect(java.lang.String[])
public void onDestroy()
expandLink
and selectLink
.
onDestroy
in interface Control
onDestroy
in class AbstractControl
Control.onDestroy()
public void setListener(Object listener, String method)
addListener(TreeListener)
.
setListener
in interface Control
setListener
in class AbstractControl
listener
- the listener object with the named method to invokemethod
- the name of the method to invokepublic void setActionListener(ActionListener listener)
addListener(TreeListener)
.
setActionListener
in class AbstractControl
listener
- the control's action listenerpublic 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()
getControlSizeEst
in class AbstractControl
AbstractControl.getControlSizeEst()
public void cleanupSession()
JAVASCRIPT_SESSION_POLICY
.
public void render(HtmlStringBuffer buffer)
render
in interface Control
render
in class AbstractControl
buffer
- the specified buffer to render the control's output totoString()
public String toString()
setRootNodeDisplayed(boolean)
with true.
toString
in class AbstractControl
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 previousState)
node
- specify the TreeNode that was expandedpreviousState
- contains the previous expanded stateprotected void fireNodeCollapsed(TreeNode node, boolean previousState)
node
- specific the TreeNode that was collapsedpreviousState
- contains the previous expanded stateprotected void fireNodeSelected(TreeNode node, boolean previousState)
node
- specific the TreeNode that was selectedpreviousState
- contains the previous selected stateprotected void fireNodeDeselected(TreeNode node, boolean previousState)
node
- specific the TreeNode that was deselectedpreviousState
- contains the previous selected stateprotected 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<TreeNode> 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<TreeNode> 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<TreeNode> 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<String,? extends Object> 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 |