|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.ecs.examples.HtmlTree
This JavaBean returns the hierarchical structure described in a javax.swing.tree.DefaultMutableTreeNode as valid XHTML. This class is a very simple counterpart of the javax.swing.JTree with the exception that the external Controller is integrated into this View. If you want your tree elements (nodes and leafs) to be marked with an anchor, you'll have to make sure that the name of your node contains such an anchor.
A specific node in a tree can be identified by a path, described as colon separated integer values (e.g. "0:1"). Unlike Swing's JTree component, this JavaBean expands only the requested node, leaving all its parent nodes collapsed. An expanded node is one displays its children. A collapsed node is one which hides them.
You can use this class in a JavaServerPage like this:
Although this class is just an example of using parts of the Element Construction Set, you can use it quite well in real web applications....template text...
<%-- Get the bean from the request scope or create a new one if none exists --%>
<jsp:useBean id="tree" scope="request" class="org.apache.ecs.examples.HtmlTree"></jsp:useBean><%-- Read the path from the request --%>
<jsp:setProperty name="tree" property="path" param="path" /><%-- Set UI properties --%>
<jsp:setProperty name="tree" property="rootVisible" value="true" />
<jsp:setProperty name="tree" property="indentation" value="2" />
<jsp:setProperty name="tree" property="openIcon" value="open.gif" />
<jsp:setProperty name="tree" property="closedIcon" value="closed.gif" />
<jsp:setProperty name="tree" property="leafIcon" value="leaf.gif" /><%-- Workaround for Netscape and Opera browsers --%>
<jsp:setProperty name="tree" property="action" value="tree.jsp" />...template text...
<%-- Get the XHTML output from the bean --%>
<jsp:getProperty name="tree" property="html" />
Field Summary | |
protected java.lang.String |
action
Context path of a web resource for the workaround of a strange behaviour of Netscape and Opera browsers. |
protected java.lang.String |
closedIcon
Icon for displaying closed nodes. |
protected javax.swing.tree.DefaultMutableTreeNode |
displayNode
Stores the requested node to be displayed. |
protected int |
indentation
Number of blank spaces around each hierarchical level will be indented in relation to its parent node. |
protected java.lang.String |
leafIcon
Icon for displaying leafs. |
protected java.lang.String |
openIcon
Icon for displaying open nodes. |
protected java.lang.String |
parameterName
Parameter name used to build the query string for the anchor that acts as the Controller for opening and closing nodes. |
protected java.lang.String |
path
Path to the requested node to be displayed, described as colon separated integer values. |
private int[] |
pathArray
Array that stores the index of each node read from the path property. |
protected javax.swing.tree.DefaultMutableTreeNode |
root
The node that defines the tree displayed by this object. |
protected boolean |
rootVisible
True if the root node is displayed, false if its children are the highest visible nodes. |
Constructor Summary | |
HtmlTree()
Returns a HtmlTree with a sample model. |
|
HtmlTree(javax.swing.tree.DefaultMutableTreeNode root)
Returns a HtmlTree with the specified DefaultMutableTreeNode as its root. |
|
HtmlTree(javax.swing.tree.DefaultTreeModel model)
Returns a HtmlTree with the specified DefaultTreeModel as its model. |
Method Summary | |
static java.lang.String |
encodeToHtml(java.lang.String in)
Returns the specified string encoded into a format suitable for HTML. |
protected static javax.swing.tree.DefaultMutableTreeNode |
getDefaultTreeModel()
Creates and returns a sample tree model. |
java.lang.String |
getHtml()
Returns the hierarchical structure described in the specified root node as valid XHTML. |
java.lang.String |
getImg(java.lang.String icon)
Constructs a valid XHTML <img>-tag from the specified icon. |
int |
getIndentation()
Returns the number of blank spaces around each hierarchical level is indented in relation to its parent node. |
javax.swing.tree.DefaultTreeModel |
getModel()
Returns the model that defines the tree displayed by this object. |
java.lang.String |
getNodeName()
Returns the name of the currently expanded node. |
java.lang.String |
getParameterName()
Returns the name of the parameter used to build the query string for the anchor that acts as the Controller for opening and closing nodes. |
java.lang.String |
getPath()
Returns the path to the requested node. |
java.lang.String |
getPath(int level)
Returns a path constructed from the path array for the specified level. |
static int[] |
getPathResolved(java.lang.String path)
Returns an array that stores the index of each node read from the specified path. |
javax.swing.tree.DefaultMutableTreeNode |
getRequestedNode()
Expands the tree by following the specified path and returns the requested node to be displayed. |
javax.swing.tree.DefaultMutableTreeNode |
getRoot()
Returns the node that defines the tree displayed by this object. |
int |
getRowCount()
Returns the number of rows that are currently being displayed. |
boolean |
isRootVisible()
Returns true if the root node of the tree is displayed. |
void |
setAction(java.lang.String action)
Workaround of a strange behaviour of Netscape and Opera browsers. |
void |
setClosedIcon(java.lang.String closedIcon)
Sets the icon for displaying closed nodes. |
void |
setIndentation(int indentation)
Sets the number of blank spaces around each hierarchical level will be indented in relation to its parent node. |
void |
setLeafIcon(java.lang.String leafIcon)
Sets the icon for displaying leafs. |
void |
setModel(javax.swing.tree.DefaultTreeModel model)
Sets the tree model that will provide the data. |
void |
setOpenIcon(java.lang.String openIcon)
Sets the icon for displaying open nodes. |
void |
setParameterName(java.lang.String parameterName)
Sets the name of the parameter used to build the query string for the anchor that acts as the Controller for opening and closing nodes. |
void |
setPath(java.lang.String path)
Sets the path - described as colon separated integer values - to the requested node to be displayed. |
void |
setRoot(javax.swing.tree.DefaultMutableTreeNode root)
Sets the root node that will provide the data. |
void |
setRootVisible(boolean rootVisible)
Determines whether or not the root node is visible. |
java.lang.String |
toString()
Overrides toString() to print something meaningful. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected int indentation
protected java.lang.String path
protected java.lang.String parameterName
private int[] pathArray
protected java.lang.String leafIcon
protected java.lang.String openIcon
protected java.lang.String closedIcon
protected java.lang.String action
protected boolean rootVisible
protected javax.swing.tree.DefaultMutableTreeNode root
protected javax.swing.tree.DefaultMutableTreeNode displayNode
Constructor Detail |
public HtmlTree()
public HtmlTree(javax.swing.tree.DefaultMutableTreeNode root)
root
- a DefaultMutableTreeNode objectpublic HtmlTree(javax.swing.tree.DefaultTreeModel model)
model
- a DefaultTreeModel objectMethod Detail |
public void setRoot(javax.swing.tree.DefaultMutableTreeNode root)
root
- a DefaultMutableTreeNode objectpublic javax.swing.tree.DefaultMutableTreeNode getRoot()
public void setModel(javax.swing.tree.DefaultTreeModel model)
model
- a DefaultTreeModel objectpublic javax.swing.tree.DefaultTreeModel getModel()
public void setPath(java.lang.String path)
path
- the path to the requested node to be displayedpublic java.lang.String getPath()
public java.lang.String getPath(int level)
level
- the distance from the node to the root node.public static int[] getPathResolved(java.lang.String path) throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if the specified
path does not consist of colon separated integer valuespublic void setParameterName(java.lang.String parameterName)
parameterName
- the name of the parameter used
to build the query stringpublic java.lang.String getParameterName()
public void setRootVisible(boolean rootVisible)
rootVisible
- true if the root node of the tree
is to be displayedpublic boolean isRootVisible()
public void setIndentation(int indentation)
indentation
- the number of blank spacespublic int getIndentation()
public java.lang.String getNodeName()
public int getRowCount()
public void setOpenIcon(java.lang.String openIcon)
openIcon
- the URI of an image filepublic void setClosedIcon(java.lang.String closedIcon)
closedIcon
- the URI of an image filepublic void setLeafIcon(java.lang.String leafIcon)
leafIcon
- the URI of an image filepublic void setAction(java.lang.String action)
action
- the context path of a web resource (e.g. a JSP-File)public java.lang.String getImg(java.lang.String icon)
icon
- the URI of an image filepublic javax.swing.tree.DefaultMutableTreeNode getRequestedNode()
public java.lang.String getHtml()
A sample Style Sheet would look like this:
a { color: black; text-decoration: none; }
a:hover { color: black; text-decoration: underline; }
img { margin-right: 5px; vertical-align: middle; border: none; }
table { font: normal 8pt Arial,Helvetica,sans-serif; }
td.parent { font-weight: bold; }
public java.lang.String toString()
toString
in class java.lang.Object
getHtml()
protected static javax.swing.tree.DefaultMutableTreeNode getDefaultTreeModel()
public static java.lang.String encodeToHtml(java.lang.String in)
in
- the String to encode
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |