Tapstry3之Tree组件全攻略

接上例:http://blog.csdn.net/kunshan_shenbin/archive/2008/11/19/3335718.aspx

T3版本Tree的例程:

如下图所示建立工程:

使用的Jar包一览:

bsf-2.3.0.jar
commons-beanutils-1.6.1.jar
commons-codec-1.2.jar
commons-collections-2.1.jar
commons-digester-1.5.jar
commons-fileupload-1.0.jar
commons-lang-1.0.jar
commons-logging-1.0.2.jar
jakarta-oro-2.0.6.jar
javassist-2.5.1.jar
ognl-2.6.3.jar
tapestry-3.0.jar
tapestry-contrib-3.0.jar

 

代码如下:

AssetsHolder.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import org.apache.tapestry.asset.PrivateAsset;
  16. import org.apache.tapestry.resource.ClasspathResourceLocation;
  17. import org.apache.tapestry.util.DefaultResourceResolver;
  18. /**
  19.  * All right reserved.
  20.  * Copyright (c) by Rushmore Digital Ltd.
  21.  * Created on Oct 3, 2002
  22.  *
  23.  * @author ceco
  24.  *
  25.  */
  26. public class AssetsHolder {
  27.     private String m_strOpenAssetsURL;
  28.     private String m_strCloseAssetsURL;
  29.     private PrivateAsset m_objOpenAsset = null;
  30.     private PrivateAsset m_objCloseAsset = null;
  31.     /**
  32.      * Constructor for AssetsHolder.
  33.      */
  34.     public AssetsHolder(String strOpenAssetsURL, String strCloseAssetsURL) {
  35.         super();
  36.         m_strOpenAssetsURL = strOpenAssetsURL;
  37.         m_strCloseAssetsURL = strCloseAssetsURL;
  38.     }
  39.     public PrivateAsset getAssetForOpenNode(){
  40.         if(m_objOpenAsset == null){
  41.             //m_objOpenAsset = new PrivateAsset(m_strOpenAssetsURL);
  42.             m_objOpenAsset =
  43.                 new PrivateAsset
  44.                 (new ClasspathResourceLocation
  45.                  (new DefaultResourceResolver(), m_strOpenAssetsURL), null);
  46.         }
  47.         return m_objOpenAsset;
  48.     }
  49.     public PrivateAsset getAssetForCloseNode(){
  50.         if(m_objCloseAsset == null){
  51.                     //m_objCloseAsset = new PrivateAsset(m_strCloseAssetsURL);
  52.                     m_objCloseAsset =
  53.                         new PrivateAsset
  54.                         (new ClasspathResourceLocation
  55.                          (new DefaultResourceResolver(), m_strCloseAssetsURL),
  56.                          null);
  57.         }
  58.         return m_objCloseAsset;
  59.     }
  60. }

DirectoryTableView.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.util.ArrayList;
  16. import java.util.Collection;
  17. import org.apache.tapestry.BaseComponent;
  18. import org.apache.tapestry.IBinding;
  19. import org.apache.tapestry.contrib.table.components.Table;
  20. import org.apache.tapestry.contrib.table.model.ITableColumn;
  21. import org.apache.tapestry.contrib.table.model.ITableModel;
  22. import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn;
  23. import org.apache.tapestry.contrib.table.model.simple.SimpleTableModel;
  24. import fsmodel.SFObject;
  25. import org.apache.tapestry.event.PageDetachListener;
  26. import org.apache.tapestry.event.PageEvent;
  27. /**
  28.  * @author ceco
  29.  * @version $Id: DirectoryTableView.java,v 1.4 2004/02/19 17:38:07 hlship Exp $
  30.  */
  31. public class DirectoryTableView extends BaseComponent implements PageDetachListener{
  32.     private ITableModel m_objTableModel = null;
  33.     private ITableColumn[] m_arrColumns = null;
  34.     private ISelectedFolderSource m_objSelectedFolderSource = null;
  35.     /**
  36.      * 
  37.      */
  38.     public DirectoryTableView() {
  39.         super();
  40.         initialize();
  41.     }
  42.     private void initialize(){
  43.         m_objTableModel = null;
  44.         m_objSelectedFolderSource = null;
  45.     }
  46.     
  47.     /**
  48.      * @see org.apache.tapestry.AbstractComponent#finishLoad()
  49.      */
  50.     protected void finishLoad() {
  51.         super.finishLoad();
  52.         getPage().addPageDetachListener(this);
  53.     }
  54.     /**
  55.      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(org.apache.tapestry.event.PageEvent)
  56.      */
  57.     public void pageDetached(PageEvent arg0) {
  58.         initialize();
  59.     }
  60.     public ITableModel getTableModel() {
  61.         if(m_objTableModel == null){
  62.             ISelectedFolderSource objSelectedFolderSource = getSelectedFolderSource();
  63.             Collection colChildrens = objSelectedFolderSource.getSelectedFolderChildren();
  64.             
  65.             m_objTableModel = new SimpleTableModel(colChildrens.toArray(), getColumns());
  66.         }
  67.         return m_objTableModel;
  68.     }
  69.     public ITableColumn[] getColumns() {
  70.         if(m_arrColumns == null){
  71.             ArrayList arrColumnsList = new ArrayList();
  72.             arrColumnsList.add(new SimpleTableColumn ("Name"true
  73.                 { 
  74.                     public Object getColumnValue(Object objValue) {
  75.                         SFObject objSFObject = (SFObject) objValue;
  76.                         return objSFObject.getName();
  77.                     }
  78.                 });
  79.             arrColumnsList.add(new SimpleTableColumn ("Date"true
  80.                 { 
  81.                     public Object getColumnValue(Object objValue) {
  82.                         SFObject objSFObject = (SFObject) objValue;
  83.                         return objSFObject.getDate();
  84.                     }
  85.                 });
  86.             m_arrColumns = new SimpleTableColumn[arrColumnsList.size()];
  87.             arrColumnsList.toArray(m_arrColumns);
  88.         }
  89.         return m_arrColumns;
  90.     }
  91.     public ISelectedFolderSource getSelectedFolderSource() {
  92.         if(m_objSelectedFolderSource == null){
  93.             IBinding objBinding = getBinding("selectedFolderSource");
  94.             m_objSelectedFolderSource = (ISelectedFolderSource)objBinding.getObject();
  95.         }
  96.         return m_objSelectedFolderSource;
  97.     }
  98.     public void resetState(){
  99.         initialize();
  100.         Table objTable = (Table)getComponent("table");
  101.         objTable.reset();
  102.     }
  103.     
  104.     public String getSelectedNodeName(){
  105.         return getSelectedFolderSource().getSelectedNodeName();
  106.     }
  107. }

Drive.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  17. public class Drive extends FolderObject {
  18.     private String m_strType;
  19.     private String m_strLabel;
  20.     private long m_lSize;
  21.     public Drive(ITreeNode objParent, File objFile) {
  22.         super(objParent, objFile, false);
  23.     }
  24.     public long getSize() {
  25.         return m_lSize;
  26.     }
  27.     public String getType() {
  28.         return m_strType;
  29.     }
  30.     public String getLabel() {
  31.         return m_strLabel;
  32.     }
  33.     public AssetsHolder getAssets() {
  34.         if (m_objAssetsHolder == null) {
  35.             m_objAssetsHolder =
  36.                 new AssetsHolder(
  37.                     "/fsmodel/harddrive.gif",
  38.                     "/fsmodel/harddrive.gif");
  39.         }
  40.         return m_objAssetsHolder;
  41.     }
  42. }

FileObject.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import java.util.ArrayList;
  17. import java.util.Collection;
  18. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  19. public class FileObject extends SFObject {
  20.     private long m_lSize;
  21.     public FileObject(ITreeNode objParent, File objFile) {
  22.         super(objParent, objFile);
  23.         init();
  24.     }
  25.     protected void init() {
  26.         super.init();
  27.         m_lSize = m_objFile.length();
  28.     }
  29.     public long getSize() {
  30.         return m_lSize;
  31.     }
  32.     /**
  33.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
  34.      */
  35.     public boolean containsChild(ITreeNode node) {
  36.         return false;
  37.     }
  38.     /**
  39.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
  40.      */
  41.     public boolean getAllowsChildren() {
  42.         return false;
  43.     }
  44.     /**
  45.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
  46.      */
  47.     public int getChildCount() {
  48.         return 0;
  49.     }
  50.     /**
  51.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
  52.      */
  53.     public Collection getChildren() {
  54.         return new ArrayList();
  55.     }
  56.     /**
  57.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
  58.      */
  59.     public boolean isLeaf() {
  60.         return true;
  61.     }
  62.     /**
  63.      * @see org.apache.tapestry.workbench.tree.examples.fsmodel.IFileSystemTreeNode#getAssets()
  64.      */
  65.     public AssetsHolder getAssets() {
  66.         if (m_objAssetsHolder == null) {
  67.             final String a = "/fsmodel/file.gif";
  68.             m_objAssetsHolder = new AssetsHolder(a, a);
  69.         }
  70.         return m_objAssetsHolder;
  71.     }
  72. }

FileSystem.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import java.util.Collection;
  17. import java.util.Date;
  18. import java.util.Vector;
  19. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  20. public class FileSystem implements IFileSystemTreeNode
  21. {
  22.   private transient AssetsHolder m_objAssetsHolder = null;
  23.     /** @associates <{Drive}>
  24.      * @supplierCardinality 0..*
  25.      * @link aggregation*/
  26.     
  27.   private Vector m_vDrives;
  28.   public FileSystem()
  29.   {
  30.     //initDrives();
  31.   }
  32.   private void initDrives()
  33.   {
  34.     m_vDrives = new Vector();
  35.     File[] arrFile = File.listRoots();
  36.     if (arrFile != null)
  37.       for(int i=0; i<arrFile.length; i++)
  38.       {
  39.         m_vDrives.addElement(new Drive(this, arrFile[i]));
  40.       }
  41.   }
  42.   public Vector getDrives()
  43.   {
  44.     if(m_vDrives == null){
  45.         initDrives();
  46.     }
  47.     return m_vDrives;
  48.   }
  49.   public int getChildNumber(Object objChild)
  50.   {
  51.     for(int i=0;i<m_vDrives.size();i++)
  52.     {
  53.       Object objChildDrive = m_vDrives.elementAt(i);
  54.       if(objChildDrive.equals(objChild))
  55.       {
  56.         return i;
  57.       }
  58.     }
  59.     return -1;
  60.   }
  61.     /**
  62.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
  63.      */
  64.     public boolean containsChild(ITreeNode node) {
  65.         return true;
  66.     }
  67.     /**
  68.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
  69.      */
  70.     public boolean getAllowsChildren() {
  71.         return true;
  72.     }
  73.     /**
  74.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
  75.      */
  76.     public int getChildCount() {
  77.         return getDrives().size();
  78.     }
  79.     /**
  80.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
  81.      */
  82.     public Collection getChildren() {
  83.         return getDrives();
  84.     }
  85.     /**
  86.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getParent()
  87.      */
  88.     public ITreeNode getParent() {
  89.         return null;
  90.     }
  91.     /**
  92.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
  93.      */
  94.     public boolean isLeaf() {
  95.         return false;
  96.     }
  97.     /**
  98.      * @see java.lang.Object#toString()
  99.      */
  100.     public String toString() {
  101.         return getName();
  102.     }
  103.     public String getName(){
  104.         return "FileSystem";
  105.     }
  106.     
  107.     /**
  108.      * @see java.lang.Object#equals(Object)
  109.      */
  110.     public boolean equals(Object arg0) {
  111.         if(!(arg0 instanceof FileSystem))
  112.             return false;
  113.         FileSystem objFileSystem = (FileSystem)arg0;
  114.         if(getName().equals(objFileSystem.getName()))
  115.             return true;
  116.         return false;
  117.     }
  118.     /**
  119.      * @see java.lang.Object#hashCode()
  120.      */
  121.     public int hashCode() {
  122.         return getName().hashCode();
  123.     }
  124.     /**
  125.      * @see fsmodel.IFileSystemTreeNode#getAbsolutePath()
  126.      */
  127.     public String getAbsolutePath() {
  128.         return "";
  129.     }
  130.     /**
  131.      * @see fsmodel.IFileSystemTreeNode#getAssets()
  132.      */
  133.     public AssetsHolder getAssets() {
  134.         if(m_objAssetsHolder == null){
  135.             m_objAssetsHolder = new AssetsHolder("/fsmodel/computer.gif""/fsmodel/computer.gif");
  136.         }
  137.         return m_objAssetsHolder;
  138.     }
  139.     /**
  140.      * @see fsmodel.IFileSystemTreeNode#getObjectDate()
  141.      */
  142.     public Date getDate() {
  143.         return null;
  144.     }
  145. }

FileSystemDataModel.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.Serializable;
  16. import java.util.Iterator;
  17. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  18. import org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel;
  19. /**
  20.  * @author ceco
  21.  */
  22. public class FileSystemDataModel extends SimpleTreeDataModel
  23.     implements Serializable {
  24.     /**
  25.      * Constructor for FileSystemDataModel.
  26.      * @param objRootNode
  27.      */
  28.     public FileSystemDataModel(ITreeNode objRootNode) {
  29.         super(objRootNode);
  30.     }
  31.     /**
  32.      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getObject(Object)
  33.      */
  34.     public Object getObject(Object objUniqueKey) {
  35.         return findNode(objUniqueKey, (IFileSystemTreeNode)getRoot());
  36.     }
  37.     private IFileSystemTreeNode findNode(Object objUniqueKey,
  38.                                          IFileSystemTreeNode objParentNode) {
  39.         String strUniqueKey = (String) objUniqueKey;
  40.         String strParentUniqueKey = objParentNode.getAbsolutePath();
  41.         if (strUniqueKey.equals(strParentUniqueKey)) {
  42.             return objParentNode;
  43.         }
  44.         IFileSystemTreeNode obj = null;
  45.         if(strUniqueKey.startsWith(strParentUniqueKey))
  46.         {
  47.             for (Iterator iter = objParentNode.getChildren().iterator(); iter.hasNext();) {
  48.                 IFileSystemTreeNode element = (IFileSystemTreeNode) iter.next();
  49.                 obj = findNode(objUniqueKey, element);
  50.                 if (obj != null) {
  51.                     break;
  52.                 }
  53.             }
  54.         }
  55.         return obj;
  56.     }
  57.     /**
  58.      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getUniqueKey(Object, Object)
  59.      */
  60.     public Object getUniqueKey(Object objTarget, Object objParentUniqueKey) {
  61.         IFileSystemTreeNode objNode = (IFileSystemTreeNode) objTarget;
  62.         return objNode.getAbsolutePath();
  63.     }
  64.     /**
  65.      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#isAncestorOf(Object, Object)
  66.      */
  67.     public boolean isAncestorOf(Object objChildUniqueKey,
  68.                                 Object objParentUniqueKey) {
  69.         String strChildAbsolutePath = (String)objChildUniqueKey;
  70.         String strParentAbsolutePath = (String)objParentUniqueKey;
  71.         if("".equals(strParentAbsolutePath)) {
  72.             return true;
  73.         }
  74.         return strChildAbsolutePath.lastIndexOf(strParentAbsolutePath) > -1;
  75.     }
  76.     /**
  77.      * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getParentUniqueKey(Object)
  78.      */
  79.     public Object getParentUniqueKey(Object objChildUniqueKey) {
  80.         IFileSystemTreeNode objNode =
  81.             (IFileSystemTreeNode) getObject(objChildUniqueKey);
  82.         return objNode.getParent();
  83.     }
  84. }

FileSystemStateManager.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
  17. import org.apache.tapestry.contrib.tree.model.ITreeModel;
  18. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  19. import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
  20. import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
  21. import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
  22. /**
  23.  * @author ceco
  24.  */
  25. public class FileSystemStateManager implements ITreeSessionStateManager {
  26.     private String m_strRootDir;
  27.     /**
  28.      * Constructor for FileSystemStateManager.
  29.      */
  30.     public FileSystemStateManager(String strRootDir) {
  31.         super();
  32.         m_strRootDir = strRootDir;
  33.     }
  34.     /**
  35.      * @see org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager#getSessionState(ITreeModel)
  36.      */
  37.     public Object getSessionState(ITreeModel objModel) {
  38.         return objModel.getTreeStateModel();
  39.     }
  40.     /**
  41.      * @see org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager#getModel(Object)
  42.      */
  43.     public ITreeModel getModel(Object objSessionState) {
  44.         ITreeStateModel objStateModel = (ITreeStateModel) objSessionState;
  45.         ITreeNode objParent;
  46.         if (m_strRootDir == null || "".equals(m_strRootDir)) {
  47.             objParent = new FileSystem();
  48.         } else {
  49.             FolderObject objFolder = new FolderObject(nullnew File(m_strRootDir), true);
  50.             objFolder.reload();
  51.             objParent = objFolder;
  52.         }
  53.         ITreeDataModel objDataModel = new FileSystemDataModel(objParent);
  54.         ITreeModel objModel = new SimpleTreeModel(objDataModel,
  55.                                                     objStateModel);
  56.         return objModel;
  57.     }
  58. }

FileSystemTree.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import java.util.Collection;
  17. import java.util.Date;
  18. import org.apache.tapestry.contrib.tree.components.INodeRenderFactory;
  19. import org.apache.tapestry.contrib.tree.components.TreeView;
  20. import fsmodel.FileSystem;
  21. import fsmodel.FileSystemDataModel;
  22. import fsmodel.FileSystemStateManager;
  23. import fsmodel.FolderObject;
  24. import fsmodel.NodeRenderFactory;
  25. import org.apache.tapestry.contrib.tree.model.TreeStateEvent;
  26. import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
  27. import org.apache.tapestry.contrib.tree.model.ITreeModel;
  28. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  29. import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
  30. import org.apache.tapestry.contrib.tree.model.ITreeStateListener;
  31. import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
  32. import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
  33. import org.apache.tapestry.html.BasePage;
  34. public class FileSystemTree extends BasePage implements ISelectedFolderSource, ITreeStateListener{
  35.     private ITreeSessionStateManager m_objTreeSessionStateManager = null;
  36.     private ITreeDataModel m_objDataModel;
  37.     private ITreeModel m_objModel;
  38.     private Object m_objValue;
  39.     public FileSystemTree() {
  40.         super();
  41.     }
  42.     protected void initialize() {
  43.         super.initialize();
  44.         m_objDataModel = null;
  45.         m_objValue = null;
  46.         m_objTreeSessionStateManager = null;
  47.     }
  48.     public void initTableModel() {
  49.         ITreeNode objParent;
  50.         String strRootDir = getRequestCycle().getRequestContext().getServlet().getInitParameter("TreeRootDir");
  51.         System.out.println("strRootDir = " + strRootDir);
  52.         if (strRootDir == null || "".equals(strRootDir)) {
  53.             objParent = new FileSystem();
  54.         } else{
  55.             FolderObject objFolder = new FolderObject(nullnew File(strRootDir), true);
  56.             objFolder.reload();
  57.             objParent = objFolder;
  58.         }
  59.         m_objDataModel = new FileSystemDataModel(objParent);
  60.         m_objModel = new SimpleTreeModel(m_objDataModel);
  61.     }
  62.     public Date getCurrentTime() {
  63.         return new Date();
  64.     }
  65.     public ITreeModel getTreeModel() {
  66.         if (m_objDataModel == null) {
  67.             initTableModel();
  68.         }
  69.         System.out.println("getting TreeModel");
  70.         return m_objModel;
  71.     }
  72.     /**
  73.      * Returns the value.
  74.      * @return Object
  75.      */
  76.     public Object getValue() {
  77.         return m_objValue;
  78.     }
  79.     /**
  80.      * Sets the value.
  81.      * @param value The value to set
  82.      */
  83.     public void setValue(Object value) {
  84.         m_objValue = value;
  85.     }
  86.     public INodeRenderFactory getRenderFactory() {
  87.         return new NodeRenderFactory();
  88.     }
  89.     public ITreeSessionStateManager getSessionStateManager() {
  90.         //IPage objPage = getRequestCycle().getPage("contrib:TreeNodeViewPage");
  91.         //System.out.println("TreeNodeViewPage NamespaceId : "+objPage.getNamespace().getNamespaceId());
  92.         
  93.         if (m_objTreeSessionStateManager == null) {
  94.             String strRootDir = getRequestCycle().getRequestContext().getServlet().getInitParameter("TreeRootDir");
  95.             //System.out.println("strRootDir = " + strRootDir);
  96.             m_objTreeSessionStateManager =
  97.                 new FileSystemStateManager(strRootDir);
  98.         }
  99.         return m_objTreeSessionStateManager;
  100.     }
  101.     /**
  102.      * @see org.apache.tapestry.workbench.tree.examples.ISelectedFolderSource#getSelectedFolder()
  103.      */
  104.     public Collection getSelectedFolderChildren() {
  105.         TreeView objTreeView = (TreeView)getComponent("treeView");
  106.         ITreeStateModel objTreeStateModel = objTreeView.getTreeModel().getTreeStateModel();
  107.         Object objSelectedNodeUID = objTreeStateModel.getSelectedNode();
  108.         ITreeNode objSelectedNode = null;
  109.         if(objSelectedNodeUID != null)
  110.             objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getObject(objSelectedNodeUID);
  111.         else{
  112.             objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getRoot();
  113.         }
  114.         return objSelectedNode.getChildren();
  115.     }
  116.     /**
  117.      * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
  118.      */
  119.     public void treeStateChanged(TreeStateEvent objEvent) {
  120.         DirectoryTableView objDirectoryTableView = (DirectoryTableView)getComponent("directoryTableView");
  121.         objDirectoryTableView.resetState();
  122.     }
  123.     public ITreeStateListener getTreeStateListener(){
  124.         return this;
  125.     }
  126.     public ISelectedFolderSource getSelectedFolderSource(){
  127.         return this;
  128.     }
  129.     
  130.     /**
  131.      * @see org.apache.tapestry.workbench.tree.examples.ISelectedFolderSource#getSelectedNodeName()
  132.      */
  133.     public String getSelectedNodeName() {
  134.         TreeView objTreeView = (TreeView)getComponent("treeView");
  135.         ITreeStateModel objTreeStateModel = objTreeView.getTreeModel().getTreeStateModel();
  136.         Object objSelectedNodeUID = objTreeStateModel.getSelectedNode();
  137.         ITreeNode objSelectedNode = null;
  138.         if(objSelectedNodeUID != null)
  139.             objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getObject(objSelectedNodeUID);
  140.         else{
  141.             objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getRoot();
  142.         }
  143.         return objSelectedNode.toString();
  144.     }
  145. }

FolderObject.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import java.util.ArrayList;
  17. import java.util.Collection;
  18. import java.util.Vector;
  19. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  20. public class FolderObject extends SFObject{
  21.     /**
  22.      * @associates <{File}>
  23.      * @supplierCardinality 0..*
  24.      * @link aggregation
  25.      */
  26.     private Vector m_vFiles = null;
  27.     /**
  28.      * @associates <{FolderObject}>
  29.      * @supplierCardinality 0..*
  30.      * @link aggregation
  31.      */
  32.     private Vector m_vFolders = null;
  33.     private boolean m_bShared;
  34.     public FolderObject(ITreeNode objParent, File objFile, boolean bInvokeInit) {
  35.         super(objParent, objFile);
  36.         if(bInvokeInit)
  37.             init();
  38.     }
  39.     public void reload() {
  40.         m_vFolders = new Vector();
  41.         m_vFiles = new Vector();
  42.         File[] arrFiles = getFile().listFiles();
  43.         if (arrFiles == null) {
  44.             return;
  45.         }
  46.         for (int i=0; i<arrFiles.length; i++) {
  47.             if (arrFiles[i].isDirectory()) {
  48.                 m_vFolders.addElement(new FolderObject(this, arrFiles[i], true));
  49.             } else {
  50.                 m_vFiles.addElement(new FileObject(this, arrFiles[i]));
  51.             }
  52.         }
  53.     }
  54.     public boolean isShared() {
  55.         return m_bShared;
  56.     }
  57.     public Vector getFolders() {
  58.         if (m_vFolders == null) {
  59.             reload();
  60.         }
  61.         return m_vFolders;
  62.     }
  63.     public Vector getFiles() {
  64.         if (m_vFiles == null) {
  65.             reload();
  66.         }
  67.         return m_vFiles;
  68.     }
  69.     public int getChildNumber(Object objChild) {
  70.         for(int i = 0; i < m_vFolders.size(); i++) {
  71.             Object objChildFolder = m_vFolders.elementAt(i);
  72.             if (objChildFolder.equals(objChild)) {
  73.                 return i;
  74.             }
  75.         }
  76.         return -1;
  77.     }
  78.     /**
  79.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
  80.      */
  81.     public boolean containsChild(ITreeNode node) {
  82.         return true;
  83.     }
  84.     /**
  85.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
  86.      */
  87.     public boolean getAllowsChildren() {
  88.         return true;
  89.     }
  90.     /**
  91.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
  92.      */
  93.     public int getChildCount() {
  94.         return getFolders().size() + getFiles().size();
  95.     }
  96.     /**
  97.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
  98.      */
  99.     public Collection getChildren() {
  100.         ArrayList arrChildrens = new ArrayList();
  101.         arrChildrens.addAll(getFolders());
  102.         arrChildrens.addAll(getFiles());
  103.         return arrChildrens;
  104.     }
  105.     /**
  106.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
  107.      */
  108.     public boolean isLeaf() {
  109.         return false;
  110.     }
  111.     private final static String openImage =
  112.         "/fsmodel/TreeOpen.gif";
  113.     private final static String closedImage =
  114.         "/fsmodel/TreeClosed.gif";
  115.     public AssetsHolder getAssets() {
  116.         if (m_objAssetsHolder == null) {
  117.             m_objAssetsHolder = new AssetsHolder(openImage, closedImage);
  118.         }
  119.         return m_objAssetsHolder;
  120.     }
  121. }

IFileSystemTreeNode.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.util.Date;
  16. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  17. /**
  18.  * @author ceco
  19.  */
  20. public interface IFileSystemTreeNode extends ITreeNode {
  21.     String getAbsolutePath();
  22.     AssetsHolder getAssets();
  23.     Date getDate();
  24. }

ISelectedFolderSource.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.util.Collection;
  16. /**
  17.  * All right reserved.
  18.  * Copyright (c) by Rushmore Digital Ltd.
  19.  * 
  20.  * Created on Sep 4, 2003
  21.  * 
  22.  * @author ceco
  23.  */
  24. public interface ISelectedFolderSource {
  25.     Collection getSelectedFolderChildren();
  26.     String getSelectedNodeName();
  27. }

NodeRenderFactory.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import org.apache.tapestry.IMarkupWriter;
  16. import org.apache.tapestry.IRender;
  17. import org.apache.tapestry.IRequestCycle;
  18. import org.apache.tapestry.asset.PrivateAsset;
  19. import org.apache.tapestry.contrib.tree.components.INodeRenderFactory;
  20. import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
  21. import org.apache.tapestry.contrib.tree.model.ITreeModelSource;
  22. import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
  23. /**
  24.  * @author ceco
  25.  */
  26. public class NodeRenderFactory implements INodeRenderFactory {
  27.     /**
  28.      * Constructor for NodeRenderFactory.
  29.      */
  30.     public NodeRenderFactory() {
  31.         super();
  32.     }
  33.     public IRender getRenderByID(Object objUniqueKey,
  34.                                  ITreeModelSource objTreeModelSource,
  35.                                  IRequestCycle objCycle) {
  36.         Object objValue = objTreeModelSource.getTreeModel().getTreeDataModel().getObject(objUniqueKey);
  37.         return getRender(objValue, objTreeModelSource, objCycle);
  38.     }
  39.     public IRender getRender(Object objValue,
  40.                              ITreeModelSource objTreeModelSource,
  41.                              IRequestCycle objCycle) {
  42.         return new CFileSystemRender(objValue, objTreeModelSource);
  43.     }
  44.     public class CFileSystemRender implements IRender{
  45.         private Object m_objNode;
  46.         private ITreeModelSource m_objTreeModelSource;
  47.         public CFileSystemRender(Object objNode, ITreeModelSource objTreeModelSource) {
  48.             super();
  49.             m_objNode = objNode;
  50.             m_objTreeModelSource = objTreeModelSource;
  51.         }
  52.         public boolean isOpen() {
  53.             ITreeDataModel objDataModel =
  54.                 m_objTreeModelSource.getTreeModel().getTreeDataModel();
  55.             ITreeStateModel objStateModel =
  56.                 m_objTreeModelSource.getTreeModel().getTreeStateModel();
  57.             Object objUniqueKey = objDataModel.getUniqueKey(m_objNode, null);
  58.             return objStateModel.isUniqueKeyExpanded(objUniqueKey);
  59.         }
  60.         public boolean isSelected(){
  61.             ITreeDataModel objDataModel =
  62.                 m_objTreeModelSource.getTreeModel().getTreeDataModel();
  63.             ITreeStateModel objStateModel =
  64.                 m_objTreeModelSource.getTreeModel().getTreeStateModel();
  65.             Object objUniqueKey = objDataModel.getUniqueKey(m_objNode, null);
  66.             return objUniqueKey.equals(objStateModel.getSelectedNode());
  67.         }
  68.         public void render(IMarkupWriter objWriter, IRequestCycle objCycle) {
  69.             PrivateAsset objAsset = getAsset();
  70.             objWriter.begin("img");
  71.             objWriter.attribute("border""0");
  72.             objWriter.attribute("src", objAsset.buildURL(objCycle));
  73.             objWriter.attribute("align""bottom");
  74.             objWriter.end();
  75.             objWriter.print(" ");
  76.             objWriter.begin("span");
  77.             String strClassName = "fsNodeValue";
  78.             objWriter.attribute("class", strClassName);
  79.             objWriter.closeTag();
  80.             objWriter.print(getNode().toString().trim());
  81.             objWriter.end();
  82.         }
  83.         public IFileSystemTreeNode getNode(){
  84.             return (IFileSystemTreeNode) m_objNode;
  85.         }
  86.         private PrivateAsset getAsset(){
  87.             PrivateAsset objAsset;
  88.             if (!isOpen()) {
  89.                 objAsset = getNode().getAssets().getAssetForCloseNode();
  90.             } else {
  91.                 objAsset = getNode().getAssets().getAssetForOpenNode();
  92.             }
  93.             return objAsset;
  94.         }
  95.     }
  96. }

SFObject.java

  1. //  Copyright 2004 The Apache Software Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //     http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsmodel;
  15. import java.io.File;
  16. import java.util.Collection;
  17. import java.util.Date;
  18. import org.apache.tapestry.contrib.tree.model.ITreeNode;
  19. public abstract class SFObject implements IFileSystemTreeNode{
  20.     protected File m_objFile;
  21.     protected ITreeNode m_objParent;
  22.     private Date m_objDate;
  23.     protected transient AssetsHolder m_objAssetsHolder = null;
  24.     public SFObject(ITreeNode objParent, File objFile) {
  25.         m_objParent = objParent;
  26.         m_objFile = objFile;
  27. //        init();
  28.     }
  29.     protected void init() {
  30.         if(m_objFile.isFile() || m_objFile.isDirectory())
  31.             m_objDate = new Date(m_objFile.lastModified());
  32.     }
  33.     public String getName() {
  34.         if (m_objFile.getName().equals("")) {
  35.             return m_objFile.toString();
  36.         }
  37.         return m_objFile.getName();
  38.     }
  39.     public Date getDate() {
  40.         return m_objDate;
  41.     }
  42.     public Object getAttributes() {
  43.         return null;
  44.     }
  45.     protected File getFile() {
  46.         return m_objFile;
  47.     }
  48.     /**
  49.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getParent()
  50.      */
  51.     public ITreeNode getParent() {
  52.         return m_objParent;
  53.     }
  54.     /**
  55.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
  56.      */
  57.     public boolean containsChild(ITreeNode node) {
  58.         return false;
  59.     }
  60.     /**
  61.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
  62.      */
  63.     public boolean getAllowsChildren() {
  64.         return false;
  65.     }
  66.     /**
  67.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
  68.      */
  69.     public int getChildCount() {
  70.         return 0;
  71.     }
  72.     /**
  73.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
  74.      */
  75.     public Collection getChildren() {
  76.         return null;
  77.     }
  78.     /**
  79.      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
  80.      */
  81.     public boolean isLeaf() {
  82.         return false;
  83.     }
  84.     /**
  85.      * @see java.lang.Object#equals(Object)
  86.      */
  87.     public boolean equals(Object arg0) {
  88.         if (!(arg0 instanceof SFObject)) {
  89.             return false;
  90.         }
  91.         SFObject objSF = (SFObject)arg0;
  92.         if (getFile().equals(objSF.getFile())) {
  93.             return true;
  94.         }
  95.         return false;
  96.     }
  97.     /**
  98.      * @see java.lang.Object#hashCode()
  99.      */
  100.     public int hashCode() {
  101.         return m_objFile.hashCode();
  102.     }
  103.     /**
  104.      * @see java.lang.Object#toString()
  105.      */
  106.     public String toString() {
  107.         return getName();
  108.     }
  109.     /**
  110.      * @see fsmodel.IFileSystemTreeNode#getAbsolutePath()
  111.      */
  112.     public String getAbsolutePath() {
  113.         return getFile().getAbsolutePath();
  114.     }
  115. }

FirstTreePage.java

  1. /*
  2.  * Created on Oct 21, 2004
  3.  *
  4.  */
  5. package tapestrytrees;
  6. import org.apache.tapestry.IEngine;
  7. import org.apache.tapestry.contrib.tree.components.TreeView;
  8. import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
  9. import org.apache.tapestry.contrib.tree.model.ITreeModel;
  10. import org.apache.tapestry.contrib.tree.model.ITreeStateListener;
  11. import org.apache.tapestry.contrib.tree.model.TreeStateEvent;
  12. import org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel;
  13. import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
  14. import org.apache.tapestry.contrib.tree.simple.TreeNode;
  15. import org.apache.tapestry.html.BasePage;
  16. /**
  17.  * @author John Reynolds
  18.  *  
  19.  */
  20. public class FirstTreePage extends BasePage implements ITreeStateListener {
  21.     private ITreeDataModel treeDataModel;
  22.     private ITreeModel treeModel;
  23.     private Object value;
  24.     public void attach(IEngine value) {
  25.         super.attach(value);
  26.     }
  27.     public void detach() {
  28.         super.detach();
  29.         treeDataModel = null;
  30.         value = null;
  31.     }
  32.     public ITreeStateListener getTreeStateListener() {
  33.         return this;
  34.     }
  35.     /*
  36.      * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
  37.      */
  38.     public void treeStateChanged(TreeStateEvent objEvent) {
  39.         // Get the StringTreeNode object that was selected 
  40.         TreeView treeView = (TreeView)getComponent("treeView");
  41.         if(treeView != null){
  42.             ITreeDataModel thisTreeDataModel = treeView.getTreeModel().getTreeDataModel();
  43.             Object selectedNode = thisTreeDataModel.getObject(objEvent.getNodeUID());
  44.             if(selectedNode instanceof StringTreeNode){
  45.                lastNodeSelectedValue = ((StringTreeNode)selectedNode).getValue();
  46.             }
  47.         } else { // This shouldn't happen
  48.             lastNodeSelectedValue = objEvent.getNodeUID().toString();
  49.         }
  50.     }
  51.     String lastNodeSelectedValue;
  52.     public String getLastNodeSelectedMsg()
  53.     {
  54.         if(lastNodeSelectedValue==null){
  55.             return null;
  56.         }
  57.         return lastNodeSelectedValue + " was the last node selected.";
  58.     }
  59.     
  60.     ITreeDataModel getTreeDataModel() {
  61.         if (treeDataModel == null) {
  62.             StringTreeSource firstTreeSource = new StringTreeSource();
  63.             treeDataModel = firstTreeSource.getTreeDataModel();
  64.         }
  65.         return treeDataModel;
  66.     }
  67.     /**
  68.      * Get the TreeModel that contains the nodes to be rendered
  69.      * 
  70.      * @return ITreeModel
  71.      */
  72.      public ITreeModel getTreeModel() {
  73.          if (treeModel == null) {
  74.             System.out.println("creating SimpleTreeModel");
  75.             // Create and "connect" all the nodes
  76.             TreeNode node1 = new StringTreeNode("Root Node");
  77.             TreeNode node2 = new StringTreeNode("Child One");
  78.             TreeNode node2a = new StringTreeNode("Grandchild One");
  79.             node2.insert(node2a);
  80.             node1.insert(node2);
  81.             TreeNode node3 = new StringTreeNode("Child Two");
  82.             TreeNode node3a = new StringTreeNode("GrandChild Two");
  83.             node3.insert(node3a);
  84.             TreeNode node3a1 = new StringTreeNode("Great Grandchild One");
  85.             node3a.insert(node3a1);
  86.             node1.insert(node3);
  87.             // Wrap the root node in a SimpleTreeDataModel
  88.             treeDataModel = new SimpleTreeDataModel(node1);
  89.             // Wrap the SimpleTreeDataModel in a SimpleTreeModel
  90.             treeModel = new SimpleTreeModel(treeDataModel);
  91.          }
  92.          return treeModel;
  93.      }
  94. }

SecondTreePage.java

  1. /*
  2.  * Created on Oct 21, 2004
  3.  *
  4.  */
  5. package tapestrytrees;
  6. import org.apache.tapestry.IEngine;
  7. import org.apache.tapestry.contrib.tree.components.INodeRenderFactory;
  8. import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
  9. import org.apache.tapestry.contrib.tree.model.ITreeModel;
  10. import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
  11. import org.apache.tapestry.contrib.tree.model.ITreeStateListener;
  12. import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
  13. import org.apache.tapestry.contrib.tree.model.TreeStateEvent;
  14. import org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory;
  15. import org.apache.tapestry.contrib.tree.simple.SimpleSessionStateManager;
  16. import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
  17. import org.apache.tapestry.contrib.tree.simple.SimpleTreeStateModel;
  18. import org.apache.tapestry.html.BasePage;
  19. /**
  20.  * @author John Reynolds
  21.  *
  22.  */
  23. public class SecondTreePage extends BasePage implements ITreeStateListener {
  24.     private ITreeDataModel treeDataModel;
  25.     private ITreeModel treeModel;
  26.     private Object value;
  27.     public void attach(IEngine value) {
  28.         super.attach(value);
  29.     }
  30.     public void detach() {
  31.         super.detach();
  32.         treeDataModel = null;
  33.         value = null;
  34.     }
  35.     /* (non-Javadoc)
  36.      * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
  37.      */
  38.     public void treeStateChanged(TreeStateEvent objEvent) {
  39.         System.out.println("TreeStateChanged: " + objEvent.getEventType());
  40.         ITreeStateModel tsm = objEvent.getTreeStateModel();
  41.         if (tsm instanceof SimpleTreeStateModel)
  42.         {
  43.             System.out.println("The ITreeStateModel is a SimpleTreeStateModel");
  44.         }
  45.         tsm.expandPath(objEvent.getNodeUID());
  46.     }
  47.     
  48.     ITreeDataModel getTreeDataModel()
  49.     {
  50.         if(treeDataModel==null)
  51.         {
  52.             StringTreeSource firstTreeSource = new StringTreeSource();
  53.             treeDataModel = firstTreeSource.getTreeDataModel();
  54.         }
  55.         return treeDataModel;
  56.     }
  57.     
  58.     public ITreeModel getTreeModel()
  59.     {
  60.         if(treeModel == null)
  61.         {
  62.             treeModel = new SimpleTreeModel(getTreeDataModel());
  63.             System.out.println("creating SimpleTreeModel");
  64.         } else {
  65.             System.out.println("getting SimpleTreeModel");
  66.         }
  67.         return treeModel;
  68.     }
  69. /*
  70.     ITreeSessionStateManager treeSessionStateManager;
  71.     public ITreeSessionStateManager getTreeSessionStateManager()
  72.     {
  73.         if(treeSessionStateManager == null)
  74.         {
  75.             treeSessionStateManager = new SimpleSessionStateManager();
  76.             System.out.println("creating SimpleSessionStateManager");
  77.         } else {
  78.             System.out.println("getting SimpleSessionStateManager");
  79.         }
  80.         return treeSessionStateManager;
  81.     }
  82. */
  83.     public ITreeStateListener getTreeStateListener(){
  84.         return this;
  85.     }
  86. /*
  87.     public INodeRenderFactory getNodeRenderFactory() {
  88.         System.out.println("creating SimpleNodeRenderFactory");
  89.         return new SimpleNodeRenderFactory();
  90.     }
  91. */
  92. }

StringTreeNode.java

  1. /*
  2.  * Created on Oct 20, 2004
  3.  *
  4.  */
  5. package tapestrytrees;
  6. import org.apache.tapestry.contrib.tree.model.IMutableTreeNode;
  7. import org.apache.tapestry.contrib.tree.simple.TreeNode;
  8. /**
  9.  * @author John Ryenolds
  10.  * This is a simple extension of TreeNode that can be used for
  11.  * trees that display Strings.
  12.  */
  13. public class StringTreeNode extends TreeNode {
  14.     String strValue;
  15.     /**
  16.      */
  17.     public String getValue() {
  18.         return strValue;
  19.     }
  20.     
  21.     public StringTreeNode( String strValue)
  22.     {
  23.         super();
  24.         this.strValue = strValue;
  25.     }
  26.     public StringTreeNode( String strValue, IMutableTreeNode parent)
  27.     {
  28.         super(parent);
  29.         this.strValue = strValue;
  30.     }
  31.     /**
  32.      *  @see org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory
  33.      *  SimpleNodeRenderFactory.getRender() returns a  RenderString 
  34.      *  instanciated by object.toString()
  35.      * 
  36.      *  If we want anything other then the serialized object displayed
  37.      *  we have to overwrite toString()
  38.      */
  39.     public String toString(){
  40.         return getValue();
  41.     }
  42.     /**
  43.      *  Overwrite hashCode to match getValue().hashCode()
  44.      */
  45.     public int hashCode(){
  46.         return getValue().hashCode();
  47.     }
  48.     /**
  49.      *  Overwrite equals to match getValue().equals()
  50.      */
  51.     public boolean equals(Object objTarget){
  52.         if(objTarget == this)
  53.             return true;
  54.         if(! (objTarget instanceof StringTreeNode))
  55.             return false;
  56.         StringTreeNode objTargetNode = (StringTreeNode)objTarget;
  57.         return this.getValue().equals(objTargetNode.getValue());
  58.     }
  59. }

StringTreeSource.java

  1. /*
  2.  * Created on Oct 20, 2004
  3.  *
  4.  */
  5. package tapestrytrees;
  6. import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
  7. import org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel;
  8. /**
  9.  * @author John Ryenolds
  10.  * This is the source of the data for the tree examples
  11.  */
  12. public class StringTreeSource {
  13.     
  14.     ITreeDataModel treeDataModel;
  15.     public ITreeDataModel getTreeDataModel()
  16.     {
  17.         if( treeDataModel == null)
  18.         {
  19.             StringTreeNode node1 = new StringTreeNode("node1");
  20.             StringTreeNode node2 = new StringTreeNode("node2");
  21.             StringTreeNode node2a = new StringTreeNode("node2a");
  22.             node2.insert(node2a);
  23.             node1.insert(node2);
  24.             StringTreeNode node3 = new StringTreeNode("node3");
  25.             StringTreeNode node3a = new StringTreeNode("node3a");
  26.             node3.insert(node3a);
  27.             StringTreeNode node3a1 = new StringTreeNode("node3a1");
  28.             node3a.insert(node3a1);
  29.             node1.insert(node3);
  30.             System.out.println("node1 has " + node1.getChildCount() + " children" );
  31.             treeDataModel = new SimpleTreeDataModel(node1);
  32.         }
  33.         System.out.println("getting TreeDataModel");
  34.         return treeDataModel;
  35.     }
  36. }

TapestryTreesVisit.java

  1. /* Contributed by John Reynolds - October 2004
  2.  * This work is hereby released into the Public Domain. 
  3.  * To view a copy of the public domain dedication, visit 
  4.  * http://creativecommons.org/licenses/publicdomain/ 
  5.  * or send a letter to Creative Commons, 559 Nathan Abbott Way, 
  6.  * Stanford, California 94305, USA.
  7.  *
  8.  * This class pretty much corresponds to a users session object
  9.  * It is accessible from all of the pages in the application
  10.  */
  11. package tapestrytrees;
  12. import java.io.Serializable;
  13. public class TapestryTreesVisit implements Serializable
  14. {
  15.     public TapestryTreesVisit()
  16.     {
  17.     }
  18. }

style.css

  1. body  
  2. {
  3.   font-family : Trebuchet MS, san serif;
  4.   font-weight : normal;
  5. }

  6. tr.even
  7. {
  8.   background-color: lightblue;
  9. }

  10. tr.odd
  11. {
  12.   background-colorrgb(228,255,228);
  13. }

  14. code.snippet, div.snippet
  15. {
  16.   colorred;
  17. }

  18. div.code
  19. {
  20.   colorred;
  21.   background-colorrgb(255,255,228);
  22. }


  23. code.highlight, div.highlight
  24. {
  25.   colorred;
  26.   background-colorrgb(255,255,128);
  27. }

  28. span.inputerror
  29. {
  30.   colorred;
  31.   font-weight : strong;
  32.   background-color: yellow;
  33. }

  34. div.note
  35. {
  36.   background-colorrgb(228,255,228);
  37. }

  38. .tree .selectedNodeViewClass A:visited .fsNodeValue, .tree .selectedNodeViewClass A:active .fsNodeValue, .tree .selectedNodeViewClass A:link .fsNodeValue {
  39.     color:              white;
  40.     background-color:   #3163CE;
  41.     text-decoration:    none
  42. }

  43. .tree .selectedNodeViewClass A:hover .fsNodeValue{
  44.     color:              white;
  45.     background-color:   #3163CE;
  46.     text-decoration:    underline;
  47. }

  48. .tree .selectedNodeViewClass A:link, .tree .selectedNodeViewClass A:visited, .tree .selectedNodeViewClass A:active, .tree .selectedNodeViewClass A:hover  {
  49.     text-decorationnone;
  50. }

  51. .tree .notSelectedNodeViewClass A:visited .fsNodeValue, .tree .notSelectedNodeViewClass A:active .fsNodeValue, .tree .notSelectedNodeViewClass A:link .fsNodeValue{
  52.     color:              black;
  53.     text-decoration:    none
  54. }

  55. .tree .notSelectedNodeViewClass A:hover .fsNodeValue{
  56.     color:              black;
  57.     text-decoration:    underline;
  58. }

  59. .tree .notSelectedNodeViewClass A:link, .tree .notSelectedNodeViewClass A:visited, .tree .notSelectedNodeViewClass A:active, .tree .notSelectedNodeViewClass A:hover  {
  60.     text-decorationnone;
  61. }
DirectoryTableView.html

  1. <span jwcid="$content$">
  2. <table height="100%">
  3.     <tr>
  4.         <td valign="top">Table View Of Folder : <span jwcid="@Insert" value="ognl:selectedNodeName"/></td>
  5.     </tr>
  6.     <tr>
  7.         <td valign="top"><span jwcid="table"/></td>
  8.     </tr>
  9. </table>
DirectoryTableView.jwc

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.    Copyright 2004 The Apache Software Foundation
  4.   
  5.    Licensed under the Apache License, Version 2.0 (the "License");
  6.    you may not use this file except in compliance with the License.
  7.    You may obtain a copy of the License at
  8.   
  9.        http://www.apache.org/licenses/LICENSE-2.0
  10.   
  11.    Unless required by applicable law or agreed to in writing, software
  12.    distributed under the License is distributed on an "AS IS" BASIS,
  13.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.    See the License for the specific language governing permissions and
  15.    limitations under the License.
  16. -->
  17. <!--  $Id: DirectoryTableView.jwc,v 1.2 2004/02/29 18:49:07 harishkswamy Exp $ -->
  18. <!DOCTYPE component-specification PUBLIC 
  19.   "-//Apache Software Foundation//Tapestry Specification 3.0//EN" 
  20.   "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">

  21. <component-specification class="fsmodel.DirectoryTableView"
  22.     allow-body="yes" allow-informal-parameters="yes">
  23.     
  24.     <component id="table" type="contrib:Table">
  25.         <binding name="tableModel" expression="tableModel"/>
  26.         <!--binding name="tableSessionStateManager" expression="tableSessionStateManager"/-->
  27.     </component>
  28. </component-specification>
FileSystemTree.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>File System Tree</h1>
  7.     <div class="note">
  8.         This page demonstates the using the Tree components to display the server's File System 
  9.     </div>
  10.     <p>
  11.         As a starting point, here is Tsvetelin's  File System Tree example from the 
  12.         Tapestry Workbench:
  13.     <p>
  14.     <table border="1">
  15.         <tr>
  16.             <td valign="top">
  17.                 <span class="tree" jwcid="treeView">
  18.                     <span jwcid="treeData">
  19.                         <span jwcid="treeNodeView"/>
  20.                     </span>
  21.                 </span>
  22.             </td>
  23.             <td valign="top" height="100%">
  24.                 <span jwcid="directoryTableView"/>
  25.             </td>
  26.         </tr>
  27.     </table>
  28.     <p>
  29.         This is a great example of what the tree is capable of, but
  30.         it's a bit involved for a neophyte.  We'll start off with something
  31.         a bit simpler.
  32.     <p>    
  33.     <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  34. </body>
  35. </html>
FileSystemTree.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.    Copyright 2004 The Apache Software Foundation
  4.   
  5.    Licensed under the Apache License, Version 2.0 (the "License");
  6.    you may not use this file except in compliance with the License.
  7.    You may obtain a copy of the License at
  8.   
  9.        http://www.apache.org/licenses/LICENSE-2.0
  10.   
  11.    Unless required by applicable law or agreed to in writing, software
  12.    distributed under the License is distributed on an "AS IS" BASIS,
  13.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.    See the License for the specific language governing permissions and
  15.    limitations under the License.
  16. -->
  17. <!-- $Id: FileSystemTree.page,v 1.2 2004/02/29 18:49:07 harishkswamy Exp $ -->
  18. <!DOCTYPE page-specification PUBLIC 
  19.   "-//Apache Software Foundation//Tapestry Specification 3.0//EN" 
  20.   "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">


  21. <page-specification class="fsmodel.FileSystemTree">
  22.     <context-asset name="stylesheet" path="css/style.css"/>

  23.     <component id="currentTime" type="Insert">
  24.         <binding name="value" expression='currentTime'/>
  25.     </component>

  26.     <component id="treeData" type="contrib:TreeDataView">
  27.         <binding name="treeView" expression='components.treeView'/>
  28.         <binding name="value" expression='value'/>
  29.     </component>

  30.     <component id="treeNodeView" type="contrib:TreeNodeView">
  31.         <binding name="makeNodeDirect" expression="true"/>
  32.         <binding name="nodeRenderFactory" expression='renderFactory'/>
  33.         <binding name="showNodeImages" expression="false"/>
  34.         <binding name="treeDataView" expression='components.treeData'/>
  35.     </component>

  36.     <component id="treeView" type="contrib:TreeView">
  37.         <binding name="sessionStateManager" expression='sessionStateManager'/>
  38.         <binding name="treeModel" expression='treeModel'/>
  39.         <binding name="treeStateListener" expression='treeStateListener'/>
  40.     </component>

  41.     <component id="directoryTableView" type="DirectoryTableView">
  42.         <binding name="selectedFolderSource" expression='selectedFolderSource'/>
  43.     </component>

  44.     <!--component id="showInspector" type="contrib:InspectorButton"/-->
  45. </page-specification>
FirstTree.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>First Tree</h1>
  7.     <div class="note">
  8.         This page demonstrates how to use the Tree components to implement 
  9.         a simple tree.
  10.     </div>
  11.     The simple tree that follows uses the <code>contrib:TreeView</code>,
  12.     <code>contrib:TreeDataView</code> and <code>contrib:TreeView</code>
  13.     components.  Click on the nodes to expand and contract the tree.
  14.     <table border="1">
  15.         <tr>
  16.             <td valign="top">
  17.                 <span class="tree" jwcid="treeView">
  18.                     <span jwcid="treeDataView">
  19.                         <span jwcid="treeNodeView"/>
  20.                     </span>
  21.                 </span>
  22.             </td>
  23.         </tr>
  24.     </table>
  25.     <p>
  26.         The files <code>FirstTree.html</code><code>FirstTree.page</code>,
  27.         <code>FirstTreePage.java</code> and <code>StringTreeNode.java</code>
  28.         are used to implement this page.
  29.     <p>
  30.         Here is a snippet from <code>FirstTree.html</code> that shows how the
  31.         tree is set up on the HTML template:
  32. <div class="code">
  33. <pre>
  34.     <span class="tree" jwcid="treeView">
  35.         <span jwcid="treeDataView">
  36.             <span jwcid="treeNodeView"/>
  37.         </span>
  38.     </span>
  39. </pre>
  40. </div>        
  41.     <p>
  42.         Here is a snippet from <code>FirstTree.page</code> that shows how the
  43.         tree is set up:
  44. <div class="code">
  45. <pre>
  46.     <component id="treeView" type="contrib:TreeView">
  47.         <binding name="treeModel" <code class="highlight">expression='treeModel'</code>/>
  48.         <binding name="treeStateListener" expression='treeStateListener'/>
  49.     </component>

  50.     <component id="treeDataView" type="contrib:TreeDataView">
  51.         <binding name="treeView" expression='components.treeView'/>
  52.         <binding name="value" expression='value'/>
  53.     </component>

  54.     <component id="treeNodeView" type="contrib:TreeNodeView">
  55.         <binding name="treeDataView" expression='components.treeDataView'/>
  56.         <binding name="makeNodeDirect" expression="true"/>
  57.     </component>
  58. </pre>
  59. </div>        
  60.     <p>
  61.         The expression <code>'treeModel'</code> resolves
  62.         to the method <code>getTreeModel()</code> in <code>FirstTreePage.java</code>.
  63.         Before examining that code, we need to discuss the objects that provide
  64.         data to the tree components.
  65.     <p>    
  66.         To use <code>contrib:TreeView</code> on a page, you must first create a populated TreeModel 
  67.         by performing the following steps:
  68.         <ul>
  69.             <li>Create a class that implements the ITreeNode interface</li>
  70.             <li>Create a "tree" of ITreeNode objects</li>
  71.             <li>Create an ITreeDataModel object to wrap the "tree"</li>
  72.             <li>Create an ITreeModel that wraps the ITreeDataModel</li>                    
  73.         </ul>
  74.     <p>
  75.         <a href="#" jwcid="@PageLink" page="FirstTree1">Creating a class that implements ITreeNode...</a>
  76.     <p>    
  77.     <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  78. </body>
  79. </html>
FirstTree.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->

  6. <page-specification class="tapestrytrees.FirstTreePage">
  7.     <context-asset name="stylesheet" path="css/style.css"/>

  8.     <component id="treeView" type="contrib:TreeView">
  9.         <binding name="treeModel" expression='treeModel'/>
  10.         <binding name="treeStateListener" expression='treeStateListener'/>
  11.     </component>

  12.     <component id="treeDataView" type="contrib:TreeDataView">
  13.         <binding name="treeView" expression='components.treeView'/>
  14.         <binding name="value" expression='value'/>
  15.     </component>

  16.     <component id="treeNodeView" type="contrib:TreeNodeView">
  17.         <binding name="treeDataView" expression='components.treeDataView'/>
  18.         <binding name="makeNodeDirect" expression="true"/>
  19.     </component>
  20.     
  21. </page-specification>
FirstTree1.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>Creating a class that implements ITreeNode</h1>
  7.     <div class="note">
  8.         This page demonstrates a simple class that implements the ITreeNode interface. 
  9.     </div>
  10.     <table border="1">
  11.         <tr>
  12.             <td valign="top">
  13.                 <span class="tree" jwcid="treeView">
  14.                     <span jwcid="treeDataView">
  15.                         <span jwcid="treeNodeView"/>
  16.                     </span>
  17.                 </span>
  18.             </td>
  19.         </tr>
  20.     </table>
  21.     <p>
  22.         The Tapestry Tree components render ITreeNode objects.  
  23.         This is a simple interface that defines nodes which can have a single 
  24.         parent and multiple children.
  25.     <p>
  26.         The distribution contains a "building block" implementation of
  27.         ITreeNode called TreeNode.  TreeNode provides much of the
  28.         functionality that you will need, but you must extend it to 
  29.         provide the data that you want the tree to render.  For this
  30.         example, I have extended TreeNode to contain a String that
  31.         will be displayed in the tree.
  32.     <p>
  33.         Here is a snippet from <code>StringTreeNode.java</code>:
  34.     </p>
  35. <div class="code">        
  36. <pre>
  37. public class StringTreeNode extends TreeNode {

  38.     String strValue;
  39.     /**
  40.      */
  41.     public String getValue() {
  42.         return strValue;
  43.     }
  44.     
  45.     public StringTreeNode( String strValue)
  46.     {
  47.         super();
  48.         this.strValue = strValue;
  49.     }

  50.     public StringTreeNode( String strValue, IMutableTreeNode parent)
  51.     {
  52.         super(parent);
  53.         this.strValue = strValue;
  54.     }

  55.     /**
  56.      *  @see org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory
  57.      *  SimpleNodeRenderFactory.getRender() returns a  RenderString 
  58.      *  instanciated by object.toString()
  59.      * 
  60.      *  If we want anything other then the serialized object displayed
  61.      *  we have to overwrite toString()
  62.      */
  63.     public String toString(){
  64.         return getValue();
  65.     }

  66.     /**
  67.      *  Overwrite hashCode to match getValue().hashCode()
  68.      */
  69.     public int hashCode(){
  70.         return getValue().hashCode();
  71.     }

  72.     /**
  73.      *  Overwrite equals to match getValue().equals()
  74.      */
  75.     public boolean equals(Object objTarget){
  76.         if(objTarget == this)
  77.             return true;
  78.         if(! (objTarget instanceof StringTreeNode))
  79.             return false;
  80.         StringTreeNode objTargetNode = (StringTreeNode)objTarget;
  81.         return this.getValue().equals(objTargetNode.getValue());
  82.     }

  83. }
  84. </pre>
  85. </div>    
  86.     <p>    
  87.         Note that you
  88.         must overwrite hashCode() and equals() for your tree to expand
  89.         and collapse properly.
  90.     <p>
  91.         Once you've created your own implementation of ITreeNode, you
  92.         need to create the nodes and use them to initialize an object
  93.         that implements ITreeTable.
  94.     <p>
  95.     
  96. <a href="#" jwcid="@PageLink" page="FirstTree2">Creating a populated ITreeModel...</a>
  97. <p>    
  98. <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  99. </body>
  100. </html>
FirstTree1.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->

  6. <page-specification class="tapestrytrees.FirstTreePage">
  7.     <context-asset name="stylesheet" path="css/style.css"/>

  8.     <component id="treeView" type="contrib:TreeView">
  9.         <binding name="treeModel" expression='treeModel'/>
  10.         <binding name="treeStateListener" expression='treeStateListener'/>
  11.     </component>

  12.     <component id="treeDataView" type="contrib:TreeDataView">
  13.         <binding name="treeView" expression='components.treeView'/>
  14.         <binding name="value" expression='value'/>
  15.     </component>

  16.     <component id="treeNodeView" type="contrib:TreeNodeView">
  17.         <binding name="treeDataView" expression='components.treeDataView'/>
  18.         <binding name="makeNodeDirect" expression="true"/>
  19.     </component>
  20.     
  21. </page-specification>
FirstTree2.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>Creating a populated ITreeModel</h1>
  7.     <div class="note">
  8.         This page demonstrates how to create a populated ITreeModel 
  9.         using SimpleTreeDataModel and SimpleTreeModel with our custom
  10.         StringTreeNode. 
  11.     </div>
  12.     <table border="1">
  13.         <tr>
  14.             <td valign="top">
  15.                 <span class="tree" jwcid="treeView">
  16.                     <span jwcid="treeDataView">
  17.                         <span jwcid="treeNodeView"/>
  18.                     </span>
  19.                 </span>
  20.             </td>
  21.         </tr>
  22.     </table>
  23.     <p>
  24.         The distribution includes the classes SimpleTreeDataModel
  25.         and SimpleTreeModel that can be used to wrap our custom
  26.         StringTreeNode objects.  
  27.         Here is a code
  28.         snippet from <code>FirstTreePage.java</code> that demonstrates how you
  29.         can use these classes:
  30. <div class="code">
  31. <pre>
  32.      public ITreeModel getTreeModel() {
  33.          if (treeModel == null) {
  34.             System.out.println("creating SimpleTreeModel");

  35.             // Create and "connect" all the nodes
  36.             TreeNode node1 = new StringTreeNode("Root Node");
  37.             TreeNode node2 = new StringTreeNode("Child One");
  38.             TreeNode node2a = new StringTreeNode("Grandchild One");
  39.             node2.insert(node2a);
  40.             node1.insert(node2);
  41.             TreeNode node3 = new StringTreeNode("Child Two");
  42.             TreeNode node3a = new StringTreeNode("GrandChild Two");
  43.             node3.insert(node3a);
  44.             TreeNode node3a1 = new StringTreeNode("Great Grandchild One");
  45.             node3a.insert(node3a1);
  46.             node1.insert(node3);

  47.             // Wrap the root node in a SimpleTreeDataModel
  48.             treeDataModel = new SimpleTreeDataModel(node1);
  49.             // Wrap the SimpleTreeDataModel in a SimpleTreeModel
  50.             treeModel = new SimpleTreeModel(treeDataModel);
  51.          }
  52.          return treeModel;
  53.      }
  54. </pre>
  55. </div>
  56. <p>
  57.     That's about all you have to do to create a simple tree that renders
  58.     Strings.  Most likely you will want to perform some action when
  59.     the user clicks on a node.  We'll do that next.
  60. <p>
  61. <a href="#" jwcid="@PageLink" page="FirstTree3">Performing an action when a node is clicked...</a>
  62. <p>    
  63. <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  64. </body>
  65. </html>
FirstTree2.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->

  6. <page-specification class="tapestrytrees.FirstTreePage">
  7.     <context-asset name="stylesheet" path="css/style.css"/>

  8.     <component id="treeView" type="contrib:TreeView">
  9.         <binding name="treeModel" expression='treeModel'/>
  10.         <binding name="treeStateListener" expression='treeStateListener'/>
  11.     </component>

  12.     <component id="treeDataView" type="contrib:TreeDataView">
  13.         <binding name="treeView" expression='components.treeView'/>
  14.         <binding name="value" expression='value'/>
  15.     </component>

  16.     <component id="treeNodeView" type="contrib:TreeNodeView">
  17.         <binding name="treeDataView" expression='components.treeDataView'/>
  18.         <binding name="makeNodeDirect" expression="true"/>
  19.     </component>
  20.     
  21. </page-specification>
FirstTree3.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>Performing an action when a node is clicked</h1>
  7.     <div class="note">
  8.         This page demonstrates how to use a TreeStateListener to
  9.         respond when a node is clicked. 
  10.     </div>
  11.     <table border="1">
  12.         <tr>
  13.             <td valign="top">
  14.                 <span class="tree" jwcid="treeView">
  15.                     <span jwcid="treeDataView">
  16.                         <span jwcid="treeNodeView"/>
  17.                     </span>
  18.                 </span>
  19.             </td>
  20.         </tr>
  21.         <tr>
  22.             <td colspan="4">
  23.                <code class="highlight"><span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/></code>
  24.             <td>
  25.         </tr>    
  26.     </table>
  27.     <p>
  28.         Here is a snippet from FirstTree3.hmtl that adds a dynamic string
  29.         to the page to indicate the last node that was selected:
  30. <div class="code">
  31. <pre>
  32.     <table border="1">
  33.         <tr>
  34.             <td valign="top">
  35.                 <span class="tree" jwcid="treeView">
  36.                     <span jwcid="treeDataView">
  37.                         <span jwcid="treeNodeView"/>
  38.                     </span>
  39.                 </span>
  40.             </td>
  41.         </tr>
  42.         <tr>
  43.             <td colspan="4"><code class="highlight">
  44.                <code class="highlight">
  45.                 <span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/>
  46.                </code></code>
  47.             <td>
  48.         </tr>    
  49.     </table>
  50. </pre>
  51. </div>
  52.     <p>
  53.         The TreeView's TreeStateListener is notified any time a node
  54.         of the tree is selected.  In our case the page is the TreeStateListener.
  55.         This was set up on <code>FirstTree3.page</code> in the following snippet:
  56. <div class="code">
  57. <pre>
  58.     <component id="treeView" type="contrib:TreeView">
  59.         <binding name="treeModel" expression='treeModel'/>
  60.         <code class="highlight"><binding name="treeStateListener" expression='treeStateListener'/></code>
  61.     </component>
  62. </pre>
  63. </div>
  64.         Here are some code
  65.         snippets from <code>FirstTreePage.java</code> that demonstrate how
  66.         to respond to events from the tree:
  67. <div class="code">
  68. <pre>
  69.     public class FirstTreePage extends BasePage 
  70.         implements <code class="highlight">ITreeStateListener</code> {
  71.     
  72.     public ITreeStateListener getTreeStateListener() {
  73.         return this;
  74.     }
  75.     
  76.     /*
  77.      * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
  78.      */
  79.     public void treeStateChanged(TreeStateEvent objEvent) {
  80.         // Get the StringTreeNode object that was selected 
  81.         TreeView treeView = (TreeView)getComponent("treeView");
  82.         if(treeView != null){
  83.             ITreeDataModel thisTreeDataModel = treeView.getTreeModel().getTreeDataModel();
  84.             Object selectedNode = thisTreeDataModel.getObject(objEvent.getNodeUID());
  85.             if(selectedNode instanceof StringTreeNode){
  86.                lastNodeSelectedValue = ((StringTreeNode)selectedNode).getValue();
  87.             }
  88.         } else { // This shouldn't happen
  89.             lastNodeSelectedValue = objEvent.getNodeUID().toString();
  90.         }
  91.     }

  92.     String lastNodeSelectedValue;
  93.     public String getLastNodeSelectedMsg()
  94.     {
  95.         if(lastNodeSelectedValue==null){
  96.             return null;
  97.         }
  98.         return lastNodeSelectedValue + " was the last node selected.";
  99.     }
  100. </pre>
  101. </div>
  102. <p>
  103.     As you can see, in the <code>TreeStateChanged</code> event handler 
  104.     it is fairly easy to get the ITreeNode that was
  105.     selected. With that information you can do whatever is appropriate for
  106.     your application.
  107. <p>
  108. <a href="#" jwcid="@PageLink" page="FirstTree4">Changing the open and close icons...</a>
  109. <p>
  110. <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  111. </body>
  112. </html>
FirstTree3.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->

  6. <page-specification class="tapestrytrees.FirstTreePage">
  7.     <context-asset name="stylesheet" path="css/style.css"/>

  8.     <component id="treeView" type="contrib:TreeView">
  9.         <binding name="treeModel" expression='treeModel'/>
  10.         <binding name="treeStateListener" expression='treeStateListener'/>
  11.     </component>

  12.     <component id="treeDataView" type="contrib:TreeDataView">
  13.         <binding name="treeView" expression='components.treeView'/>
  14.         <binding name="value" expression='value'/>
  15.     </component>

  16.     <component id="treeNodeView" type="contrib:TreeNodeView">
  17.         <binding name="treeDataView" expression='components.treeDataView'/>
  18.         <binding name="makeNodeDirect" expression="true"/>
  19.     </component>
  20.     
  21. </page-specification>
FirstTree4.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>Changing the open and close icons</h1>
  7.     <div class="note">
  8.         This page demonstrates how to supply custom open and close icons
  9.         to the <code>TreeNodeView</code>.
  10.     </div>
  11.     <p>
  12.         It's really quite simple to change the open and close icons in
  13.         the tree:
  14.     <table border="1">
  15.         <tr>
  16.             <td valign="top">
  17.                 <span class="tree" jwcid="treeView">
  18.                     <span jwcid="treeDataView">
  19.                         <span jwcid="treeNodeView"/>
  20.                     </span>
  21.                 </span>
  22.             </td>
  23.         </tr>
  24.         <tr>
  25.             <td colspan="4">
  26.                <code class="highlight"><span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/></code>
  27.             <td>
  28.         </tr>    
  29.     </table>
  30.     <p>
  31.         Here are the relevent snippets from <code>FirstTree4.page</code>
  32.         that change the open and close icons:
  33. <div class="code">
  34. <pre>
  35. <code class="highlight">    <context-asset name="closeNodeImage" path="images/TreeClosed.gif"/>
  36.     <context-asset name="openNodeImage" path="images/TreeOpen.gif"/>
  37. </code>
  38.     <component id="treeNodeView" type="contrib:TreeNodeView">
  39.         <binding name="treeDataView" expression='components.treeDataView'/>
  40.         <binding name="makeNodeDirect" expression="true"/>
  41. <code class="highlight">        <binding name="closeNodeImage" expression="assets.closeNodeImage"/>
  42.         <binding name="openNodeImage" expression="assets.openNodeImage"/>
  43. </code>    </component>

  44. </pre>
  45. </div>
  46. <p>
  47.     Unfortunately, TreeNodeView does not differentiate between nodes
  48.     that have children and leaf nodes.  The same icons will be displayed
  49.     for every node.  If this doesn't meet your needs you will have to
  50.     create some custom Java classes.
  51. <p>
  52.     If you do not want open and close icons to be displayed, add the 
  53.     following binding to the <code>"treeNodeView"</code> component:
  54. <div class="code">
  55. <pre>
  56.     <binding name="showNodeImages" expression="false"/>
  57. </pre>
  58. </div>
  59.     
  60. <p>
  61. <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  62. </body>
  63. </html>
FirstTree4.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->

  6. <page-specification class="tapestrytrees.FirstTreePage">
  7.     <context-asset name="stylesheet" path="css/style.css"/>
  8.     <context-asset name="closeNodeImage" path="images/TreeClosed.gif"/>
  9.     <context-asset name="openNodeImage" path="images/TreeOpen.gif"/>

  10.     <component id="treeView" type="contrib:TreeView">
  11.         <binding name="treeModel" expression='treeModel'/>
  12.         <binding name="treeStateListener" expression='treeStateListener'/>
  13.     </component>

  14.     <component id="treeDataView" type="contrib:TreeDataView">
  15.         <binding name="treeView" expression='components.treeView'/>
  16.         <binding name="value" expression='value'/>
  17.     </component>

  18.     <component id="treeNodeView" type="contrib:TreeNodeView">
  19.         <binding name="treeDataView" expression='components.treeDataView'/>
  20.         <binding name="makeNodeDirect" expression="true"/>
  21.         <binding name="closeNodeImage" expression="assets.closeNodeImage"/>
  22.         <binding name="openNodeImage" expression="assets.openNodeImage"/>
  23.         <!--<binding name="showNodeImages" expression="false"/>-->
  24.     </component>
  25.     
  26. </page-specification>
Home.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>Using The Tapestry Tree Control</h1> 
  7. <div class="note">    
  8.     by John Reynolds: Updated on October 22nd 2004
  9. </div>
  10. <p>
  11.     This application demonstrates some common ways to use the Tapestry Tree components.  
  12.     Thanks to
  13.     Howard Lewis Ship and the many subscribers of the Tapestry Users List who offered 
  14.     suggestions and guidance. 
  15. </p><p>
  16.     This application provides a series of pages that demonstrate one way of configuring
  17.     the Tree to produce desired behaviors.  The chosen techniques may not be optimal,
  18.     but hopefully they will be understandable and will help you figure out how to reach
  19.     your own objectives.    
  20. </p><p>
  21.     Below is a static HTML representation of the first tree that we will
  22.     implement:
  23. <p>
  24. <table border="1">
  25. <tr>
  26. <td valign="top">
  27. <span class="tree">
  28. <span style="padding-left: 0px" class="notSelectedNodeViewClass">
  29. <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
  30. Root Node<br>
  31. </span>
  32. <span style="padding-left: 15px" class="notSelectedNodeViewClass">
  33. <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
  34. Child One<br>
  35. </span>
  36. <span style="padding-left: 30px" class="notSelectedNodeViewClass">
  37. <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
  38. Grandchild One<br>
  39. </span>
  40. <span style="padding-left: 15px" class="notSelectedNodeViewClass">
  41. <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
  42. Child Two<br>
  43. </span>
  44. <span style="padding-left: 30px" class="notSelectedNodeViewClass">
  45. <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
  46. GrandChild Two<br>
  47. </span>
  48. <span style="padding-left: 45px" class="selectedNodeViewClass">
  49. <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
  50. Great Grandchild One<br>
  51. </span>
  52. </span>
  53.  </td>
  54. </tr>
  55. </table>
  56. <p>
  57.     The Tree components require creating a bit of custom Java to use, but
  58.     the results are pretty nice.  If you want to skip ahead and see something
  59.     impressive, 
  60.     follow the link to the <a href="#" jwcid="@PageLink" page="FileSystemTree">Tapestry Workbench File System Tree</a>.
  61. <p>        
  62. <a href="#" jwcid="@PageLink" page="FirstTree">Getting Started...</a>
  63. <p>
  64. <a href="#" jwcid="@PageLink" page="FirstTree1">Creating a class that implements ITreeNode...</a>
  65. <p>
  66. <a href="#" jwcid="@PageLink" page="FirstTree2">Creating a populated ITreeModel...</a>
  67. <p>
  68. <a href="#" jwcid="@PageLink" page="FirstTree3">Performing an action when a node is clicked...</a>
  69. <p>
  70. <a href="#" jwcid="@PageLink" page="FirstTree4">Changing the open and close icons...</a>
  71. <p>
  72. <p>
  73. <a href="#" jwcid="@PageLink" page="FileSystemTree">The Tapestry Workbench File System Tree...</a>

  74. </body>
  75. </html>
  76. <!--
  77.  * Released in the Public Domain by John Reynolds: http://weblogs.java.net/blog/johnreynolds/
  78.  * October 2004
  79.  * This work is hereby released into the Public Domain. 
  80.  * To view a copy of the public domain dedication, visit 
  81.  * http://creativecommons.org/licenses/publicdomain/ 
  82.  * or send a letter to Creative Commons, 559 Nathan Abbott Way, 
  83.  * Stanford, California 94305, USA.
  84. -->
Home.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->
  6. <page-specification class="org.apache.tapestry.html.BasePage">
  7.     <description><![CDATA[   add a description   ]]></description>
  8.     <context-asset name="stylesheet" path="css/style.css"/>
  9. </page-specification>
SecondTree.html

  1. <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
  2. <head jwcid="@Block">
  3.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  4. </head>
  5. <body jwcid="@Body">
  6.     <h1>First Tree</h1>
  7.     <div class="note">
  8.         This page demonstates the using the Tree components to implement 
  9.         a simple tree. 
  10.     </div>
  11.     <p>
  12.         The Tapestry Tree components render ITreeNode objects.  
  13.         This is a simple interface that defines nodes which can have a single 
  14.         parent and multiple children.
  15.     <p>
  16.         To display a Tree, you must first perform the following steps:
  17.         <ul>
  18.             <li>Create a "tree" of ITreeNode objects</li>
  19.             <li>Create an ITreeDataModel object to wrap the "tree"</li>
  20.             <li>Create an ITreeModel that wraps the ITreeDataModel</li>                    
  21.         </ul>
  22.     <p>
  23.     <table border="1">
  24.         <tr>
  25.             <td valign="top">
  26.                 <span class="tree" jwcid="treeView">
  27.                     <span jwcid="treeDataView">
  28.                         <span jwcid="treeNodeView"/>
  29.                     </span>
  30.                 </span>
  31.             </td>
  32.         </tr>
  33.     </table>
  34.         
  35.     <p>    
  36.     <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
  37. </body>
  38. </html>
SecondTree.page

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE page-specification
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->

  6. <page-specification class="tapestrytrees.SecondTreePage">
  7.     <context-asset name="stylesheet" path="css/style.css"/>

  8.     <component id="treeView" type="contrib:TreeView">
  9.         <!--<binding name="sessionStateManager" expression='treeSessionStateManager'/>-->
  10.         <binding name="treeModel" expression='treeModel'/>
  11.         <binding name="treeStateListener" expression='treeStateListener'/>
  12.     </component>

  13.     <component id="treeDataView" type="contrib:TreeDataView">
  14.         <binding name="treeView" expression='components.treeView'/>
  15.         <binding name="value" expression='value'/>
  16.     </component>

  17.     <component id="treeNodeView" type="contrib:TreeNodeView">
  18.         <binding name="treeDataView" expression='components.treeDataView'/>
  19.         <!--<binding name="nodeRenderFactory" expression='nodeRenderFactory'/>-->
  20.         <binding name="makeNodeDirect" expression="true"/>
  21.         <!--<binding name="showNodeImages" expression="false"/>-->
  22.     </component>
  23.     
  24. </page-specification>
TapestryTrees.application

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE application
  3.       PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  4.       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->
  6. <application name="TapestryTrees" engine-class="org.apache.tapestry.engine.BaseEngine" >
  7.     <description><![CDATA[   This application demonstrates the Tapestry Tree component   ]]></description>
  8.     <property name="org.apache.tapestry.visit-class">tapestrytrees.TapestryTreesVisit</property>
  9.     <library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
  10.     <page name="Home" specification-path="Home.page"/>
  11. </application>
web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE web-app
  3.       PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  4.       "http://java.sun.com/dtd/web-app_2_3.dtd">
  5. <!-- generated by Spindle, http://spindle.sourceforge.net -->
  6. <web-app>
  7.     <display-name>TapestryTrees</display-name>
  8.     <filter>
  9.         <filter-name>redirect</filter-name>
  10.         <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
  11.     </filter>
  12.     <filter-mapping>
  13.         <filter-name>redirect</filter-name>
  14.         <url-pattern>/</url-pattern>
  15.     </filter-mapping>
  16.     <servlet>
  17.         <servlet-name>TapestryTrees</servlet-name>
  18.         <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
  19.         <load-on-startup>1</load-on-startup>
  20.     </servlet>
  21.     <servlet-mapping>
  22.         <servlet-name>TapestryTrees</servlet-name>
  23.         <url-pattern>/app</url-pattern>
  24.     </servlet-mapping>
  25. </web-app>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值