firsttree1.html
来自「经典Tapestry教程 经典Tapestry教程」· HTML 代码 · 共 107 行
HTML
107 行
<html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet"><head jwcid="@Block"> <link rel="stylesheet" type="text/css" href="../css/style.css"/></head><body jwcid="@Body"> <h1>Creating a class that implements ITreeNode</h1> <div class="note"> This page demonstrates a simple class that implements the ITreeNode interface. </div> <table border="1"> <tr> <td valign="top"> <span class="tree" jwcid="treeView"> <span jwcid="treeDataView"> <span jwcid="treeNodeView"/> </span> </span> </td> </tr> </table> <p> The Tapestry Tree components render ITreeNode objects. This is a simple interface that defines nodes which can have a single parent and multiple children. <p> The distribution contains a "building block" implementation of ITreeNode called TreeNode. TreeNode provides much of the functionality that you will need, but you must extend it to provide the data that you want the tree to render. For this example, I have extended TreeNode to contain a String that will be displayed in the tree. <p> Here is a snippet from <code>StringTreeNode.java</code>: </p><div class="code"> <pre>public class StringTreeNode extends TreeNode { String strValue; /** */ public String getValue() { return strValue; } public StringTreeNode( String strValue) { super(); this.strValue = strValue; } public StringTreeNode( String strValue, IMutableTreeNode parent) { super(parent); this.strValue = strValue; } /** * @see org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory * SimpleNodeRenderFactory.getRender() returns a RenderString * instanciated by object.toString() * * If we want anything other then the serialized object displayed * we have to overwrite toString() */ public String toString(){ return getValue(); } /** * Overwrite hashCode to match getValue().hashCode() */ public int hashCode(){ return getValue().hashCode(); } /** * Overwrite equals to match getValue().equals() */ public boolean equals(Object objTarget){ if(objTarget == this) return true; if(! (objTarget instanceof StringTreeNode)) return false; StringTreeNode objTargetNode = (StringTreeNode)objTarget; return this.getValue().equals(objTargetNode.getValue()); }}</pre></div> <p> Note that you must overwrite hashCode() and equals() for your tree to expand and collapse properly. <p> Once you've created your own implementation of ITreeNode, you need to create the nodes and use them to initialize an object that implements ITreeTable. <p> <a href="#" jwcid="@PageLink" page="FirstTree2">Creating a populated ITreeModel...</a><p> <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?