|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.cocoon.forms.formmodel.tree.TreeWalker
public class TreeWalker
A helper to crawl a tree and quickly access important node-related information.
It's an Iterator
on the "current level" of the tree. This level starts
at the root node (and therefore obviously contains only one element), and can then
be changed to children of the current node using enterChildren()
or popped
back to the parent level using leave()
.
The next()
method will return the next node in the iteration,
and set the current node used by many convenience methods giving information about
that node.
This class was primarily written for page templates containing Tree
s (see
org/apache/cocoon/forms/generation/jx-macros.xml
) but can of course be
used in other places as well.
Constructor Summary | |
---|---|
TreeWalker(Tree tree)
|
Method Summary | |
---|---|
TreeWalker |
enterChildren()
Starts iterating the children of the current node. |
int |
getDepth()
Get the current depth of this walker (can be used e.g. to compute indentation margins or CSS styles). |
String |
getIconType()
Get the "icon type" that should be used for this node, according to the common visual paradigms used to render trees: " leaf " for leaf nodes (will be e.g. a file icon),
"expanded " for non-leaf expanded nodes (will be e.g. a "minus" icon)
"collapsed " for non-leaf collapsed nodes (will be e.g. a "plus" icon)
|
Object |
getNode()
Get the current node, which is the result of the last call to next() (except if
enterChildren() or leave() where called inbetween. |
TreePath |
getPath()
Get the path of the current node. |
String |
getSelectionType()
Get the "selection type" that should be used for this node, that can be used e.g. as a CSS class name: " selected " for selected nodes,
"unselected " for unselected nodes. |
boolean |
hasNext()
Are there more nodes to iterate on at this level? |
boolean |
isCollapsed()
Is the current node collapsed? |
boolean |
isExpanded()
Is the current node expanded? |
boolean |
isLeaf()
Is the current node a leaf? |
boolean |
isSelected()
Is the current node selected? |
boolean |
isVisible()
Is the current node visible (i.e. its parent is expanded)? |
void |
leave()
Go back to the parent node, restoring the iterator at this node. |
Object |
next()
Get the next node in the current iteration level. |
void |
remove()
Required by the Iterator interface, but not supported here. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TreeWalker(Tree tree)
Method Detail |
---|
public TreeWalker enterChildren()
leave()
.
Right after calling this method, there is no current node. Calling next()
will move to the first child, if any.
this
).public void leave()
public boolean hasNext()
hasNext
in interface Iterator
public Object next()
next
in interface Iterator
public void remove()
Iterator
interface, but not supported here.
remove
in interface Iterator
UnsupportedOperationException
- whenever called.public int getDepth()
Tree.isRootVisible()
), depth 0 is
for the root. Otherwise, children of the root node are at depth 0.
public Object getNode()
next()
(except if
enterChildren()
or leave()
where called inbetween.
public TreePath getPath()
public boolean isLeaf()
public boolean isExpanded()
public boolean isCollapsed()
public boolean isVisible()
public boolean isSelected()
public String getIconType()
leaf
" for leaf nodes (will be e.g. a file icon),expanded
" for non-leaf expanded nodes (will be e.g. a "minus" icon)collapsed
" for non-leaf collapsed nodes (will be e.g. a "plus" icon)
public String getSelectionType()
selected
" for selected nodes,unselected
" for unselected nodes.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |