接上例: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
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import org.apache.tapestry.asset.PrivateAsset;
- import org.apache.tapestry.resource.ClasspathResourceLocation;
- import org.apache.tapestry.util.DefaultResourceResolver;
- /**
- * All right reserved.
- * Copyright (c) by Rushmore Digital Ltd.
- * Created on Oct 3, 2002
- *
- * @author ceco
- *
- */
- public class AssetsHolder {
- private String m_strOpenAssetsURL;
- private String m_strCloseAssetsURL;
- private PrivateAsset m_objOpenAsset = null;
- private PrivateAsset m_objCloseAsset = null;
- /**
- * Constructor for AssetsHolder.
- */
- public AssetsHolder(String strOpenAssetsURL, String strCloseAssetsURL) {
- super();
- m_strOpenAssetsURL = strOpenAssetsURL;
- m_strCloseAssetsURL = strCloseAssetsURL;
- }
- public PrivateAsset getAssetForOpenNode(){
- if(m_objOpenAsset == null){
- //m_objOpenAsset = new PrivateAsset(m_strOpenAssetsURL);
- m_objOpenAsset =
- new PrivateAsset
- (new ClasspathResourceLocation
- (new DefaultResourceResolver(), m_strOpenAssetsURL), null);
- }
- return m_objOpenAsset;
- }
- public PrivateAsset getAssetForCloseNode(){
- if(m_objCloseAsset == null){
- //m_objCloseAsset = new PrivateAsset(m_strCloseAssetsURL);
- m_objCloseAsset =
- new PrivateAsset
- (new ClasspathResourceLocation
- (new DefaultResourceResolver(), m_strCloseAssetsURL),
- null);
- }
- return m_objCloseAsset;
- }
- }
DirectoryTableView.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.util.ArrayList;
- import java.util.Collection;
- import org.apache.tapestry.BaseComponent;
- import org.apache.tapestry.IBinding;
- import org.apache.tapestry.contrib.table.components.Table;
- import org.apache.tapestry.contrib.table.model.ITableColumn;
- import org.apache.tapestry.contrib.table.model.ITableModel;
- import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn;
- import org.apache.tapestry.contrib.table.model.simple.SimpleTableModel;
- import fsmodel.SFObject;
- import org.apache.tapestry.event.PageDetachListener;
- import org.apache.tapestry.event.PageEvent;
- /**
- * @author ceco
- * @version $Id: DirectoryTableView.java,v 1.4 2004/02/19 17:38:07 hlship Exp $
- */
- public class DirectoryTableView extends BaseComponent implements PageDetachListener{
- private ITableModel m_objTableModel = null;
- private ITableColumn[] m_arrColumns = null;
- private ISelectedFolderSource m_objSelectedFolderSource = null;
- /**
- *
- */
- public DirectoryTableView() {
- super();
- initialize();
- }
- private void initialize(){
- m_objTableModel = null;
- m_objSelectedFolderSource = null;
- }
- /**
- * @see org.apache.tapestry.AbstractComponent#finishLoad()
- */
- protected void finishLoad() {
- super.finishLoad();
- getPage().addPageDetachListener(this);
- }
- /**
- * @see org.apache.tapestry.event.PageDetachListener#pageDetached(org.apache.tapestry.event.PageEvent)
- */
- public void pageDetached(PageEvent arg0) {
- initialize();
- }
- public ITableModel getTableModel() {
- if(m_objTableModel == null){
- ISelectedFolderSource objSelectedFolderSource = getSelectedFolderSource();
- Collection colChildrens = objSelectedFolderSource.getSelectedFolderChildren();
- m_objTableModel = new SimpleTableModel(colChildrens.toArray(), getColumns());
- }
- return m_objTableModel;
- }
- public ITableColumn[] getColumns() {
- if(m_arrColumns == null){
- ArrayList arrColumnsList = new ArrayList();
- arrColumnsList.add(new SimpleTableColumn ("Name", true)
- {
- public Object getColumnValue(Object objValue) {
- SFObject objSFObject = (SFObject) objValue;
- return objSFObject.getName();
- }
- });
- arrColumnsList.add(new SimpleTableColumn ("Date", true)
- {
- public Object getColumnValue(Object objValue) {
- SFObject objSFObject = (SFObject) objValue;
- return objSFObject.getDate();
- }
- });
- m_arrColumns = new SimpleTableColumn[arrColumnsList.size()];
- arrColumnsList.toArray(m_arrColumns);
- }
- return m_arrColumns;
- }
- public ISelectedFolderSource getSelectedFolderSource() {
- if(m_objSelectedFolderSource == null){
- IBinding objBinding = getBinding("selectedFolderSource");
- m_objSelectedFolderSource = (ISelectedFolderSource)objBinding.getObject();
- }
- return m_objSelectedFolderSource;
- }
- public void resetState(){
- initialize();
- Table objTable = (Table)getComponent("table");
- objTable.reset();
- }
- public String getSelectedNodeName(){
- return getSelectedFolderSource().getSelectedNodeName();
- }
- }
Drive.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- public class Drive extends FolderObject {
- private String m_strType;
- private String m_strLabel;
- private long m_lSize;
- public Drive(ITreeNode objParent, File objFile) {
- super(objParent, objFile, false);
- }
- public long getSize() {
- return m_lSize;
- }
- public String getType() {
- return m_strType;
- }
- public String getLabel() {
- return m_strLabel;
- }
- public AssetsHolder getAssets() {
- if (m_objAssetsHolder == null) {
- m_objAssetsHolder =
- new AssetsHolder(
- "/fsmodel/harddrive.gif",
- "/fsmodel/harddrive.gif");
- }
- return m_objAssetsHolder;
- }
- }
FileObject.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Collection;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- public class FileObject extends SFObject {
- private long m_lSize;
- public FileObject(ITreeNode objParent, File objFile) {
- super(objParent, objFile);
- init();
- }
- protected void init() {
- super.init();
- m_lSize = m_objFile.length();
- }
- public long getSize() {
- return m_lSize;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
- */
- public boolean containsChild(ITreeNode node) {
- return false;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
- */
- public boolean getAllowsChildren() {
- return false;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
- */
- public int getChildCount() {
- return 0;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
- */
- public Collection getChildren() {
- return new ArrayList();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
- */
- public boolean isLeaf() {
- return true;
- }
- /**
- * @see org.apache.tapestry.workbench.tree.examples.fsmodel.IFileSystemTreeNode#getAssets()
- */
- public AssetsHolder getAssets() {
- if (m_objAssetsHolder == null) {
- final String a = "/fsmodel/file.gif";
- m_objAssetsHolder = new AssetsHolder(a, a);
- }
- return m_objAssetsHolder;
- }
- }
FileSystem.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import java.util.Collection;
- import java.util.Date;
- import java.util.Vector;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- public class FileSystem implements IFileSystemTreeNode
- {
- private transient AssetsHolder m_objAssetsHolder = null;
- /** @associates <{Drive}>
- * @supplierCardinality 0..*
- * @link aggregation*/
- private Vector m_vDrives;
- public FileSystem()
- {
- //initDrives();
- }
- private void initDrives()
- {
- m_vDrives = new Vector();
- File[] arrFile = File.listRoots();
- if (arrFile != null)
- for(int i=0; i<arrFile.length; i++)
- {
- m_vDrives.addElement(new Drive(this, arrFile[i]));
- }
- }
- public Vector getDrives()
- {
- if(m_vDrives == null){
- initDrives();
- }
- return m_vDrives;
- }
- public int getChildNumber(Object objChild)
- {
- for(int i=0;i<m_vDrives.size();i++)
- {
- Object objChildDrive = m_vDrives.elementAt(i);
- if(objChildDrive.equals(objChild))
- {
- return i;
- }
- }
- return -1;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
- */
- public boolean containsChild(ITreeNode node) {
- return true;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
- */
- public boolean getAllowsChildren() {
- return true;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
- */
- public int getChildCount() {
- return getDrives().size();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
- */
- public Collection getChildren() {
- return getDrives();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getParent()
- */
- public ITreeNode getParent() {
- return null;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
- */
- public boolean isLeaf() {
- return false;
- }
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return getName();
- }
- public String getName(){
- return "FileSystem";
- }
- /**
- * @see java.lang.Object#equals(Object)
- */
- public boolean equals(Object arg0) {
- if(!(arg0 instanceof FileSystem))
- return false;
- FileSystem objFileSystem = (FileSystem)arg0;
- if(getName().equals(objFileSystem.getName()))
- return true;
- return false;
- }
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return getName().hashCode();
- }
- /**
- * @see fsmodel.IFileSystemTreeNode#getAbsolutePath()
- */
- public String getAbsolutePath() {
- return "";
- }
- /**
- * @see fsmodel.IFileSystemTreeNode#getAssets()
- */
- public AssetsHolder getAssets() {
- if(m_objAssetsHolder == null){
- m_objAssetsHolder = new AssetsHolder("/fsmodel/computer.gif", "/fsmodel/computer.gif");
- }
- return m_objAssetsHolder;
- }
- /**
- * @see fsmodel.IFileSystemTreeNode#getObjectDate()
- */
- public Date getDate() {
- return null;
- }
- }
FileSystemDataModel.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.Serializable;
- import java.util.Iterator;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel;
- /**
- * @author ceco
- */
- public class FileSystemDataModel extends SimpleTreeDataModel
- implements Serializable {
- /**
- * Constructor for FileSystemDataModel.
- * @param objRootNode
- */
- public FileSystemDataModel(ITreeNode objRootNode) {
- super(objRootNode);
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getObject(Object)
- */
- public Object getObject(Object objUniqueKey) {
- return findNode(objUniqueKey, (IFileSystemTreeNode)getRoot());
- }
- private IFileSystemTreeNode findNode(Object objUniqueKey,
- IFileSystemTreeNode objParentNode) {
- String strUniqueKey = (String) objUniqueKey;
- String strParentUniqueKey = objParentNode.getAbsolutePath();
- if (strUniqueKey.equals(strParentUniqueKey)) {
- return objParentNode;
- }
- IFileSystemTreeNode obj = null;
- if(strUniqueKey.startsWith(strParentUniqueKey))
- {
- for (Iterator iter = objParentNode.getChildren().iterator(); iter.hasNext();) {
- IFileSystemTreeNode element = (IFileSystemTreeNode) iter.next();
- obj = findNode(objUniqueKey, element);
- if (obj != null) {
- break;
- }
- }
- }
- return obj;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getUniqueKey(Object, Object)
- */
- public Object getUniqueKey(Object objTarget, Object objParentUniqueKey) {
- IFileSystemTreeNode objNode = (IFileSystemTreeNode) objTarget;
- return objNode.getAbsolutePath();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#isAncestorOf(Object, Object)
- */
- public boolean isAncestorOf(Object objChildUniqueKey,
- Object objParentUniqueKey) {
- String strChildAbsolutePath = (String)objChildUniqueKey;
- String strParentAbsolutePath = (String)objParentUniqueKey;
- if("".equals(strParentAbsolutePath)) {
- return true;
- }
- return strChildAbsolutePath.lastIndexOf(strParentAbsolutePath) > -1;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeDataModel#getParentUniqueKey(Object)
- */
- public Object getParentUniqueKey(Object objChildUniqueKey) {
- IFileSystemTreeNode objNode =
- (IFileSystemTreeNode) getObject(objChildUniqueKey);
- return objNode.getParent();
- }
- }
FileSystemStateManager.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
- import org.apache.tapestry.contrib.tree.model.ITreeModel;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
- import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
- /**
- * @author ceco
- */
- public class FileSystemStateManager implements ITreeSessionStateManager {
- private String m_strRootDir;
- /**
- * Constructor for FileSystemStateManager.
- */
- public FileSystemStateManager(String strRootDir) {
- super();
- m_strRootDir = strRootDir;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager#getSessionState(ITreeModel)
- */
- public Object getSessionState(ITreeModel objModel) {
- return objModel.getTreeStateModel();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager#getModel(Object)
- */
- public ITreeModel getModel(Object objSessionState) {
- ITreeStateModel objStateModel = (ITreeStateModel) objSessionState;
- ITreeNode objParent;
- if (m_strRootDir == null || "".equals(m_strRootDir)) {
- objParent = new FileSystem();
- } else {
- FolderObject objFolder = new FolderObject(null, new File(m_strRootDir), true);
- objFolder.reload();
- objParent = objFolder;
- }
- ITreeDataModel objDataModel = new FileSystemDataModel(objParent);
- ITreeModel objModel = new SimpleTreeModel(objDataModel,
- objStateModel);
- return objModel;
- }
- }
FileSystemTree.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import java.util.Collection;
- import java.util.Date;
- import org.apache.tapestry.contrib.tree.components.INodeRenderFactory;
- import org.apache.tapestry.contrib.tree.components.TreeView;
- import fsmodel.FileSystem;
- import fsmodel.FileSystemDataModel;
- import fsmodel.FileSystemStateManager;
- import fsmodel.FolderObject;
- import fsmodel.NodeRenderFactory;
- import org.apache.tapestry.contrib.tree.model.TreeStateEvent;
- import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
- import org.apache.tapestry.contrib.tree.model.ITreeModel;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
- import org.apache.tapestry.contrib.tree.model.ITreeStateListener;
- import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
- import org.apache.tapestry.html.BasePage;
- public class FileSystemTree extends BasePage implements ISelectedFolderSource, ITreeStateListener{
- private ITreeSessionStateManager m_objTreeSessionStateManager = null;
- private ITreeDataModel m_objDataModel;
- private ITreeModel m_objModel;
- private Object m_objValue;
- public FileSystemTree() {
- super();
- }
- protected void initialize() {
- super.initialize();
- m_objDataModel = null;
- m_objValue = null;
- m_objTreeSessionStateManager = null;
- }
- public void initTableModel() {
- ITreeNode objParent;
- String strRootDir = getRequestCycle().getRequestContext().getServlet().getInitParameter("TreeRootDir");
- System.out.println("strRootDir = " + strRootDir);
- if (strRootDir == null || "".equals(strRootDir)) {
- objParent = new FileSystem();
- } else{
- FolderObject objFolder = new FolderObject(null, new File(strRootDir), true);
- objFolder.reload();
- objParent = objFolder;
- }
- m_objDataModel = new FileSystemDataModel(objParent);
- m_objModel = new SimpleTreeModel(m_objDataModel);
- }
- public Date getCurrentTime() {
- return new Date();
- }
- public ITreeModel getTreeModel() {
- if (m_objDataModel == null) {
- initTableModel();
- }
- System.out.println("getting TreeModel");
- return m_objModel;
- }
- /**
- * Returns the value.
- * @return Object
- */
- public Object getValue() {
- return m_objValue;
- }
- /**
- * Sets the value.
- * @param value The value to set
- */
- public void setValue(Object value) {
- m_objValue = value;
- }
- public INodeRenderFactory getRenderFactory() {
- return new NodeRenderFactory();
- }
- public ITreeSessionStateManager getSessionStateManager() {
- //IPage objPage = getRequestCycle().getPage("contrib:TreeNodeViewPage");
- //System.out.println("TreeNodeViewPage NamespaceId : "+objPage.getNamespace().getNamespaceId());
- if (m_objTreeSessionStateManager == null) {
- String strRootDir = getRequestCycle().getRequestContext().getServlet().getInitParameter("TreeRootDir");
- //System.out.println("strRootDir = " + strRootDir);
- m_objTreeSessionStateManager =
- new FileSystemStateManager(strRootDir);
- }
- return m_objTreeSessionStateManager;
- }
- /**
- * @see org.apache.tapestry.workbench.tree.examples.ISelectedFolderSource#getSelectedFolder()
- */
- public Collection getSelectedFolderChildren() {
- TreeView objTreeView = (TreeView)getComponent("treeView");
- ITreeStateModel objTreeStateModel = objTreeView.getTreeModel().getTreeStateModel();
- Object objSelectedNodeUID = objTreeStateModel.getSelectedNode();
- ITreeNode objSelectedNode = null;
- if(objSelectedNodeUID != null)
- objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getObject(objSelectedNodeUID);
- else{
- objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getRoot();
- }
- return objSelectedNode.getChildren();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
- */
- public void treeStateChanged(TreeStateEvent objEvent) {
- DirectoryTableView objDirectoryTableView = (DirectoryTableView)getComponent("directoryTableView");
- objDirectoryTableView.resetState();
- }
- public ITreeStateListener getTreeStateListener(){
- return this;
- }
- public ISelectedFolderSource getSelectedFolderSource(){
- return this;
- }
- /**
- * @see org.apache.tapestry.workbench.tree.examples.ISelectedFolderSource#getSelectedNodeName()
- */
- public String getSelectedNodeName() {
- TreeView objTreeView = (TreeView)getComponent("treeView");
- ITreeStateModel objTreeStateModel = objTreeView.getTreeModel().getTreeStateModel();
- Object objSelectedNodeUID = objTreeStateModel.getSelectedNode();
- ITreeNode objSelectedNode = null;
- if(objSelectedNodeUID != null)
- objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getObject(objSelectedNodeUID);
- else{
- objSelectedNode = (ITreeNode)getTreeModel().getTreeDataModel().getRoot();
- }
- return objSelectedNode.toString();
- }
- }
FolderObject.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Vector;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- public class FolderObject extends SFObject{
- /**
- * @associates <{File}>
- * @supplierCardinality 0..*
- * @link aggregation
- */
- private Vector m_vFiles = null;
- /**
- * @associates <{FolderObject}>
- * @supplierCardinality 0..*
- * @link aggregation
- */
- private Vector m_vFolders = null;
- private boolean m_bShared;
- public FolderObject(ITreeNode objParent, File objFile, boolean bInvokeInit) {
- super(objParent, objFile);
- if(bInvokeInit)
- init();
- }
- public void reload() {
- m_vFolders = new Vector();
- m_vFiles = new Vector();
- File[] arrFiles = getFile().listFiles();
- if (arrFiles == null) {
- return;
- }
- for (int i=0; i<arrFiles.length; i++) {
- if (arrFiles[i].isDirectory()) {
- m_vFolders.addElement(new FolderObject(this, arrFiles[i], true));
- } else {
- m_vFiles.addElement(new FileObject(this, arrFiles[i]));
- }
- }
- }
- public boolean isShared() {
- return m_bShared;
- }
- public Vector getFolders() {
- if (m_vFolders == null) {
- reload();
- }
- return m_vFolders;
- }
- public Vector getFiles() {
- if (m_vFiles == null) {
- reload();
- }
- return m_vFiles;
- }
- public int getChildNumber(Object objChild) {
- for(int i = 0; i < m_vFolders.size(); i++) {
- Object objChildFolder = m_vFolders.elementAt(i);
- if (objChildFolder.equals(objChild)) {
- return i;
- }
- }
- return -1;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
- */
- public boolean containsChild(ITreeNode node) {
- return true;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
- */
- public boolean getAllowsChildren() {
- return true;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
- */
- public int getChildCount() {
- return getFolders().size() + getFiles().size();
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
- */
- public Collection getChildren() {
- ArrayList arrChildrens = new ArrayList();
- arrChildrens.addAll(getFolders());
- arrChildrens.addAll(getFiles());
- return arrChildrens;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
- */
- public boolean isLeaf() {
- return false;
- }
- private final static String openImage =
- "/fsmodel/TreeOpen.gif";
- private final static String closedImage =
- "/fsmodel/TreeClosed.gif";
- public AssetsHolder getAssets() {
- if (m_objAssetsHolder == null) {
- m_objAssetsHolder = new AssetsHolder(openImage, closedImage);
- }
- return m_objAssetsHolder;
- }
- }
IFileSystemTreeNode.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.util.Date;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- /**
- * @author ceco
- */
- public interface IFileSystemTreeNode extends ITreeNode {
- String getAbsolutePath();
- AssetsHolder getAssets();
- Date getDate();
- }
ISelectedFolderSource.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.util.Collection;
- /**
- * All right reserved.
- * Copyright (c) by Rushmore Digital Ltd.
- *
- * Created on Sep 4, 2003
- *
- * @author ceco
- */
- public interface ISelectedFolderSource {
- Collection getSelectedFolderChildren();
- String getSelectedNodeName();
- }
NodeRenderFactory.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import org.apache.tapestry.IMarkupWriter;
- import org.apache.tapestry.IRender;
- import org.apache.tapestry.IRequestCycle;
- import org.apache.tapestry.asset.PrivateAsset;
- import org.apache.tapestry.contrib.tree.components.INodeRenderFactory;
- import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
- import org.apache.tapestry.contrib.tree.model.ITreeModelSource;
- import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
- /**
- * @author ceco
- */
- public class NodeRenderFactory implements INodeRenderFactory {
- /**
- * Constructor for NodeRenderFactory.
- */
- public NodeRenderFactory() {
- super();
- }
- public IRender getRenderByID(Object objUniqueKey,
- ITreeModelSource objTreeModelSource,
- IRequestCycle objCycle) {
- Object objValue = objTreeModelSource.getTreeModel().getTreeDataModel().getObject(objUniqueKey);
- return getRender(objValue, objTreeModelSource, objCycle);
- }
- public IRender getRender(Object objValue,
- ITreeModelSource objTreeModelSource,
- IRequestCycle objCycle) {
- return new CFileSystemRender(objValue, objTreeModelSource);
- }
- public class CFileSystemRender implements IRender{
- private Object m_objNode;
- private ITreeModelSource m_objTreeModelSource;
- public CFileSystemRender(Object objNode, ITreeModelSource objTreeModelSource) {
- super();
- m_objNode = objNode;
- m_objTreeModelSource = objTreeModelSource;
- }
- public boolean isOpen() {
- ITreeDataModel objDataModel =
- m_objTreeModelSource.getTreeModel().getTreeDataModel();
- ITreeStateModel objStateModel =
- m_objTreeModelSource.getTreeModel().getTreeStateModel();
- Object objUniqueKey = objDataModel.getUniqueKey(m_objNode, null);
- return objStateModel.isUniqueKeyExpanded(objUniqueKey);
- }
- public boolean isSelected(){
- ITreeDataModel objDataModel =
- m_objTreeModelSource.getTreeModel().getTreeDataModel();
- ITreeStateModel objStateModel =
- m_objTreeModelSource.getTreeModel().getTreeStateModel();
- Object objUniqueKey = objDataModel.getUniqueKey(m_objNode, null);
- return objUniqueKey.equals(objStateModel.getSelectedNode());
- }
- public void render(IMarkupWriter objWriter, IRequestCycle objCycle) {
- PrivateAsset objAsset = getAsset();
- objWriter.begin("img");
- objWriter.attribute("border", "0");
- objWriter.attribute("src", objAsset.buildURL(objCycle));
- objWriter.attribute("align", "bottom");
- objWriter.end();
- objWriter.print(" ");
- objWriter.begin("span");
- String strClassName = "fsNodeValue";
- objWriter.attribute("class", strClassName);
- objWriter.closeTag();
- objWriter.print(getNode().toString().trim());
- objWriter.end();
- }
- public IFileSystemTreeNode getNode(){
- return (IFileSystemTreeNode) m_objNode;
- }
- private PrivateAsset getAsset(){
- PrivateAsset objAsset;
- if (!isOpen()) {
- objAsset = getNode().getAssets().getAssetForCloseNode();
- } else {
- objAsset = getNode().getAssets().getAssetForOpenNode();
- }
- return objAsset;
- }
- }
- }
SFObject.java
- // Copyright 2004 The Apache Software Foundation
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package fsmodel;
- import java.io.File;
- import java.util.Collection;
- import java.util.Date;
- import org.apache.tapestry.contrib.tree.model.ITreeNode;
- public abstract class SFObject implements IFileSystemTreeNode{
- protected File m_objFile;
- protected ITreeNode m_objParent;
- private Date m_objDate;
- protected transient AssetsHolder m_objAssetsHolder = null;
- public SFObject(ITreeNode objParent, File objFile) {
- m_objParent = objParent;
- m_objFile = objFile;
- // init();
- }
- protected void init() {
- if(m_objFile.isFile() || m_objFile.isDirectory())
- m_objDate = new Date(m_objFile.lastModified());
- }
- public String getName() {
- if (m_objFile.getName().equals("")) {
- return m_objFile.toString();
- }
- return m_objFile.getName();
- }
- public Date getDate() {
- return m_objDate;
- }
- public Object getAttributes() {
- return null;
- }
- protected File getFile() {
- return m_objFile;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getParent()
- */
- public ITreeNode getParent() {
- return m_objParent;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
- */
- public boolean containsChild(ITreeNode node) {
- return false;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
- */
- public boolean getAllowsChildren() {
- return false;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
- */
- public int getChildCount() {
- return 0;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
- */
- public Collection getChildren() {
- return null;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
- */
- public boolean isLeaf() {
- return false;
- }
- /**
- * @see java.lang.Object#equals(Object)
- */
- public boolean equals(Object arg0) {
- if (!(arg0 instanceof SFObject)) {
- return false;
- }
- SFObject objSF = (SFObject)arg0;
- if (getFile().equals(objSF.getFile())) {
- return true;
- }
- return false;
- }
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return m_objFile.hashCode();
- }
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return getName();
- }
- /**
- * @see fsmodel.IFileSystemTreeNode#getAbsolutePath()
- */
- public String getAbsolutePath() {
- return getFile().getAbsolutePath();
- }
- }
FirstTreePage.java
- /*
- * Created on Oct 21, 2004
- *
- */
- package tapestrytrees;
- import org.apache.tapestry.IEngine;
- import org.apache.tapestry.contrib.tree.components.TreeView;
- import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
- import org.apache.tapestry.contrib.tree.model.ITreeModel;
- import org.apache.tapestry.contrib.tree.model.ITreeStateListener;
- import org.apache.tapestry.contrib.tree.model.TreeStateEvent;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
- import org.apache.tapestry.contrib.tree.simple.TreeNode;
- import org.apache.tapestry.html.BasePage;
- /**
- * @author John Reynolds
- *
- */
- public class FirstTreePage extends BasePage implements ITreeStateListener {
- private ITreeDataModel treeDataModel;
- private ITreeModel treeModel;
- private Object value;
- public void attach(IEngine value) {
- super.attach(value);
- }
- public void detach() {
- super.detach();
- treeDataModel = null;
- value = null;
- }
- public ITreeStateListener getTreeStateListener() {
- return this;
- }
- /*
- * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
- */
- public void treeStateChanged(TreeStateEvent objEvent) {
- // Get the StringTreeNode object that was selected
- TreeView treeView = (TreeView)getComponent("treeView");
- if(treeView != null){
- ITreeDataModel thisTreeDataModel = treeView.getTreeModel().getTreeDataModel();
- Object selectedNode = thisTreeDataModel.getObject(objEvent.getNodeUID());
- if(selectedNode instanceof StringTreeNode){
- lastNodeSelectedValue = ((StringTreeNode)selectedNode).getValue();
- }
- } else { // This shouldn't happen
- lastNodeSelectedValue = objEvent.getNodeUID().toString();
- }
- }
- String lastNodeSelectedValue;
- public String getLastNodeSelectedMsg()
- {
- if(lastNodeSelectedValue==null){
- return null;
- }
- return lastNodeSelectedValue + " was the last node selected.";
- }
- ITreeDataModel getTreeDataModel() {
- if (treeDataModel == null) {
- StringTreeSource firstTreeSource = new StringTreeSource();
- treeDataModel = firstTreeSource.getTreeDataModel();
- }
- return treeDataModel;
- }
- /**
- * Get the TreeModel that contains the nodes to be rendered
- *
- * @return ITreeModel
- */
- public ITreeModel getTreeModel() {
- if (treeModel == null) {
- System.out.println("creating SimpleTreeModel");
- // Create and "connect" all the nodes
- TreeNode node1 = new StringTreeNode("Root Node");
- TreeNode node2 = new StringTreeNode("Child One");
- TreeNode node2a = new StringTreeNode("Grandchild One");
- node2.insert(node2a);
- node1.insert(node2);
- TreeNode node3 = new StringTreeNode("Child Two");
- TreeNode node3a = new StringTreeNode("GrandChild Two");
- node3.insert(node3a);
- TreeNode node3a1 = new StringTreeNode("Great Grandchild One");
- node3a.insert(node3a1);
- node1.insert(node3);
- // Wrap the root node in a SimpleTreeDataModel
- treeDataModel = new SimpleTreeDataModel(node1);
- // Wrap the SimpleTreeDataModel in a SimpleTreeModel
- treeModel = new SimpleTreeModel(treeDataModel);
- }
- return treeModel;
- }
- }
SecondTreePage.java
- /*
- * Created on Oct 21, 2004
- *
- */
- package tapestrytrees;
- import org.apache.tapestry.IEngine;
- import org.apache.tapestry.contrib.tree.components.INodeRenderFactory;
- import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
- import org.apache.tapestry.contrib.tree.model.ITreeModel;
- import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
- import org.apache.tapestry.contrib.tree.model.ITreeStateListener;
- import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
- import org.apache.tapestry.contrib.tree.model.TreeStateEvent;
- import org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory;
- import org.apache.tapestry.contrib.tree.simple.SimpleSessionStateManager;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeStateModel;
- import org.apache.tapestry.html.BasePage;
- /**
- * @author John Reynolds
- *
- */
- public class SecondTreePage extends BasePage implements ITreeStateListener {
- private ITreeDataModel treeDataModel;
- private ITreeModel treeModel;
- private Object value;
- public void attach(IEngine value) {
- super.attach(value);
- }
- public void detach() {
- super.detach();
- treeDataModel = null;
- value = null;
- }
- /* (non-Javadoc)
- * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
- */
- public void treeStateChanged(TreeStateEvent objEvent) {
- System.out.println("TreeStateChanged: " + objEvent.getEventType());
- ITreeStateModel tsm = objEvent.getTreeStateModel();
- if (tsm instanceof SimpleTreeStateModel)
- {
- System.out.println("The ITreeStateModel is a SimpleTreeStateModel");
- }
- tsm.expandPath(objEvent.getNodeUID());
- }
- ITreeDataModel getTreeDataModel()
- {
- if(treeDataModel==null)
- {
- StringTreeSource firstTreeSource = new StringTreeSource();
- treeDataModel = firstTreeSource.getTreeDataModel();
- }
- return treeDataModel;
- }
- public ITreeModel getTreeModel()
- {
- if(treeModel == null)
- {
- treeModel = new SimpleTreeModel(getTreeDataModel());
- System.out.println("creating SimpleTreeModel");
- } else {
- System.out.println("getting SimpleTreeModel");
- }
- return treeModel;
- }
- /*
- ITreeSessionStateManager treeSessionStateManager;
- public ITreeSessionStateManager getTreeSessionStateManager()
- {
- if(treeSessionStateManager == null)
- {
- treeSessionStateManager = new SimpleSessionStateManager();
- System.out.println("creating SimpleSessionStateManager");
- } else {
- System.out.println("getting SimpleSessionStateManager");
- }
- return treeSessionStateManager;
- }
- */
- public ITreeStateListener getTreeStateListener(){
- return this;
- }
- /*
- public INodeRenderFactory getNodeRenderFactory() {
- System.out.println("creating SimpleNodeRenderFactory");
- return new SimpleNodeRenderFactory();
- }
- */
- }
StringTreeNode.java
- /*
- * Created on Oct 20, 2004
- *
- */
- package tapestrytrees;
- import org.apache.tapestry.contrib.tree.model.IMutableTreeNode;
- import org.apache.tapestry.contrib.tree.simple.TreeNode;
- /**
- * @author John Ryenolds
- * This is a simple extension of TreeNode that can be used for
- * trees that display Strings.
- */
- public class StringTreeNode extends TreeNode {
- String strValue;
- /**
- */
- public String getValue() {
- return strValue;
- }
- public StringTreeNode( String strValue)
- {
- super();
- this.strValue = strValue;
- }
- public StringTreeNode( String strValue, IMutableTreeNode parent)
- {
- super(parent);
- this.strValue = strValue;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory
- * SimpleNodeRenderFactory.getRender() returns a RenderString
- * instanciated by object.toString()
- *
- * If we want anything other then the serialized object displayed
- * we have to overwrite toString()
- */
- public String toString(){
- return getValue();
- }
- /**
- * Overwrite hashCode to match getValue().hashCode()
- */
- public int hashCode(){
- return getValue().hashCode();
- }
- /**
- * Overwrite equals to match getValue().equals()
- */
- public boolean equals(Object objTarget){
- if(objTarget == this)
- return true;
- if(! (objTarget instanceof StringTreeNode))
- return false;
- StringTreeNode objTargetNode = (StringTreeNode)objTarget;
- return this.getValue().equals(objTargetNode.getValue());
- }
- }
StringTreeSource.java
- /*
- * Created on Oct 20, 2004
- *
- */
- package tapestrytrees;
- import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
- import org.apache.tapestry.contrib.tree.simple.SimpleTreeDataModel;
- /**
- * @author John Ryenolds
- * This is the source of the data for the tree examples
- */
- public class StringTreeSource {
- ITreeDataModel treeDataModel;
- public ITreeDataModel getTreeDataModel()
- {
- if( treeDataModel == null)
- {
- StringTreeNode node1 = new StringTreeNode("node1");
- StringTreeNode node2 = new StringTreeNode("node2");
- StringTreeNode node2a = new StringTreeNode("node2a");
- node2.insert(node2a);
- node1.insert(node2);
- StringTreeNode node3 = new StringTreeNode("node3");
- StringTreeNode node3a = new StringTreeNode("node3a");
- node3.insert(node3a);
- StringTreeNode node3a1 = new StringTreeNode("node3a1");
- node3a.insert(node3a1);
- node1.insert(node3);
- System.out.println("node1 has " + node1.getChildCount() + " children" );
- treeDataModel = new SimpleTreeDataModel(node1);
- }
- System.out.println("getting TreeDataModel");
- return treeDataModel;
- }
- }
TapestryTreesVisit.java
- /* Contributed by John Reynolds - October 2004
- * This work is hereby released into the Public Domain.
- * To view a copy of the public domain dedication, visit
- * http://creativecommons.org/licenses/publicdomain/
- * or send a letter to Creative Commons, 559 Nathan Abbott Way,
- * Stanford, California 94305, USA.
- *
- * This class pretty much corresponds to a users session object
- * It is accessible from all of the pages in the application
- */
- package tapestrytrees;
- import java.io.Serializable;
- public class TapestryTreesVisit implements Serializable
- {
- public TapestryTreesVisit()
- {
- }
- }
style.css
- body
- {
- font-family : Trebuchet MS, san serif;
- font-weight : normal;
- }
- tr.even
- {
- background-color: lightblue;
- }
- tr.odd
- {
- background-color: rgb(228,255,228);
- }
- code.snippet, div.snippet
- {
- color: red;
- }
- div.code
- {
- color: red;
- background-color: rgb(255,255,228);
- }
- code.highlight, div.highlight
- {
- color: red;
- background-color: rgb(255,255,128);
- }
- span.inputerror
- {
- color: red;
- font-weight : strong;
- background-color: yellow;
- }
- div.note
- {
- background-color: rgb(228,255,228);
- }
- .tree .selectedNodeViewClass A:visited .fsNodeValue, .tree .selectedNodeViewClass A:active .fsNodeValue, .tree .selectedNodeViewClass A:link .fsNodeValue {
- color: white;
- background-color: #3163CE;
- text-decoration: none
- }
- .tree .selectedNodeViewClass A:hover .fsNodeValue{
- color: white;
- background-color: #3163CE;
- text-decoration: underline;
- }
- .tree .selectedNodeViewClass A:link, .tree .selectedNodeViewClass A:visited, .tree .selectedNodeViewClass A:active, .tree .selectedNodeViewClass A:hover {
- text-decoration: none;
- }
- .tree .notSelectedNodeViewClass A:visited .fsNodeValue, .tree .notSelectedNodeViewClass A:active .fsNodeValue, .tree .notSelectedNodeViewClass A:link .fsNodeValue{
- color: black;
- text-decoration: none
- }
- .tree .notSelectedNodeViewClass A:hover .fsNodeValue{
- color: black;
- text-decoration: underline;
- }
- .tree .notSelectedNodeViewClass A:link, .tree .notSelectedNodeViewClass A:visited, .tree .notSelectedNodeViewClass A:active, .tree .notSelectedNodeViewClass A:hover {
- text-decoration: none;
- }
- <span jwcid="$content$">
- <table height="100%">
- <tr>
- <td valign="top">Table View Of Folder : <span jwcid="@Insert" value="ognl:selectedNodeName"/></td>
- </tr>
- <tr>
- <td valign="top"><span jwcid="table"/></td>
- </tr>
- </table>
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Copyright 2004 The Apache Software Foundation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <!-- $Id: DirectoryTableView.jwc,v 1.2 2004/02/29 18:49:07 harishkswamy Exp $ -->
- <!DOCTYPE component-specification PUBLIC
- "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <component-specification class="fsmodel.DirectoryTableView"
- allow-body="yes" allow-informal-parameters="yes">
- <component id="table" type="contrib:Table">
- <binding name="tableModel" expression="tableModel"/>
- <!--binding name="tableSessionStateManager" expression="tableSessionStateManager"/-->
- </component>
- </component-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>File System Tree</h1>
- <div class="note">
- This page demonstates the using the Tree components to display the server's File System
- </div>
- <p>
- As a starting point, here is Tsvetelin's File System Tree example from the
- Tapestry Workbench:
- <p>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeData">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- <td valign="top" height="100%">
- <span jwcid="directoryTableView"/>
- </td>
- </tr>
- </table>
- <p>
- This is a great example of what the tree is capable of, but
- it's a bit involved for a neophyte. We'll start off with something
- a bit simpler.
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Copyright 2004 The Apache Software Foundation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <!-- $Id: FileSystemTree.page,v 1.2 2004/02/29 18:49:07 harishkswamy Exp $ -->
- <!DOCTYPE page-specification PUBLIC
- "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <page-specification class="fsmodel.FileSystemTree">
- <context-asset name="stylesheet" path="css/style.css"/>
- <component id="currentTime" type="Insert">
- <binding name="value" expression='currentTime'/>
- </component>
- <component id="treeData" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="makeNodeDirect" expression="true"/>
- <binding name="nodeRenderFactory" expression='renderFactory'/>
- <binding name="showNodeImages" expression="false"/>
- <binding name="treeDataView" expression='components.treeData'/>
- </component>
- <component id="treeView" type="contrib:TreeView">
- <binding name="sessionStateManager" expression='sessionStateManager'/>
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="directoryTableView" type="DirectoryTableView">
- <binding name="selectedFolderSource" expression='selectedFolderSource'/>
- </component>
- <!--component id="showInspector" type="contrib:InspectorButton"/-->
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>First Tree</h1>
- <div class="note">
- This page demonstrates how to use the Tree components to implement
- a simple tree.
- </div>
- The simple tree that follows uses the <code>contrib:TreeView</code>,
- <code>contrib:TreeDataView</code> and <code>contrib:TreeView</code>
- components. Click on the nodes to expand and contract the tree.
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- </table>
- <p>
- The files <code>FirstTree.html</code>, <code>FirstTree.page</code>,
- <code>FirstTreePage.java</code> and <code>StringTreeNode.java</code>
- are used to implement this page.
- <p>
- Here is a snippet from <code>FirstTree.html</code> that shows how the
- tree is set up on the HTML template:
- <div class="code">
- <pre>
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </pre>
- </div>
- <p>
- Here is a snippet from <code>FirstTree.page</code> that shows how the
- tree is set up:
- <div class="code">
- <pre>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" <code class="highlight">expression='treeModel'</code>/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- </component>
- </pre>
- </div>
- <p>
- The expression <code>'treeModel'</code> resolves
- to the method <code>getTreeModel()</code> in <code>FirstTreePage.java</code>.
- Before examining that code, we need to discuss the objects that provide
- data to the tree components.
- <p>
- To use <code>contrib:TreeView</code> on a page, you must first create a populated TreeModel
- by performing the following steps:
- <ul>
- <li>Create a class that implements the ITreeNode interface</li>
- <li>Create a "tree" of ITreeNode objects</li>
- <li>Create an ITreeDataModel object to wrap the "tree"</li>
- <li>Create an ITreeModel that wraps the ITreeDataModel</li>
- </ul>
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree1">Creating a class that implements ITreeNode...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="tapestrytrees.FirstTreePage">
- <context-asset name="stylesheet" path="css/style.css"/>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- </component>
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>Creating a class that implements ITreeNode</h1>
- <div class="note">
- This page demonstrates a simple class that implements the ITreeNode interface.
- </div>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- </table>
- <p>
- The Tapestry Tree components render ITreeNode objects.
- This is a simple interface that defines nodes which can have a single
- parent and multiple children.
- <p>
- The distribution contains a "building block" implementation of
- ITreeNode called TreeNode. TreeNode provides much of the
- functionality that you will need, but you must extend it to
- provide the data that you want the tree to render. For this
- example, I have extended TreeNode to contain a String that
- will be displayed in the tree.
- <p>
- Here is a snippet from <code>StringTreeNode.java</code>:
- </p>
- <div class="code">
- <pre>
- public class StringTreeNode extends TreeNode {
- String strValue;
- /**
- */
- public String getValue() {
- return strValue;
- }
- public StringTreeNode( String strValue)
- {
- super();
- this.strValue = strValue;
- }
- public StringTreeNode( String strValue, IMutableTreeNode parent)
- {
- super(parent);
- this.strValue = strValue;
- }
- /**
- * @see org.apache.tapestry.contrib.tree.simple.SimpleNodeRenderFactory
- * SimpleNodeRenderFactory.getRender() returns a RenderString
- * instanciated by object.toString()
- *
- * If we want anything other then the serialized object displayed
- * we have to overwrite toString()
- */
- public String toString(){
- return getValue();
- }
- /**
- * Overwrite hashCode to match getValue().hashCode()
- */
- public int hashCode(){
- return getValue().hashCode();
- }
- /**
- * Overwrite equals to match getValue().equals()
- */
- public boolean equals(Object objTarget){
- if(objTarget == this)
- return true;
- if(! (objTarget instanceof StringTreeNode))
- return false;
- StringTreeNode objTargetNode = (StringTreeNode)objTarget;
- return this.getValue().equals(objTargetNode.getValue());
- }
- }
- </pre>
- </div>
- <p>
- Note that you
- must overwrite hashCode() and equals() for your tree to expand
- and collapse properly.
- <p>
- Once you've created your own implementation of ITreeNode, you
- need to create the nodes and use them to initialize an object
- that implements ITreeTable.
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree2">Creating a populated ITreeModel...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="tapestrytrees.FirstTreePage">
- <context-asset name="stylesheet" path="css/style.css"/>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- </component>
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>Creating a populated ITreeModel</h1>
- <div class="note">
- This page demonstrates how to create a populated ITreeModel
- using SimpleTreeDataModel and SimpleTreeModel with our custom
- StringTreeNode.
- </div>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- </table>
- <p>
- The distribution includes the classes SimpleTreeDataModel
- and SimpleTreeModel that can be used to wrap our custom
- StringTreeNode objects.
- Here is a code
- snippet from <code>FirstTreePage.java</code> that demonstrates how you
- can use these classes:
- <div class="code">
- <pre>
- public ITreeModel getTreeModel() {
- if (treeModel == null) {
- System.out.println("creating SimpleTreeModel");
- // Create and "connect" all the nodes
- TreeNode node1 = new StringTreeNode("Root Node");
- TreeNode node2 = new StringTreeNode("Child One");
- TreeNode node2a = new StringTreeNode("Grandchild One");
- node2.insert(node2a);
- node1.insert(node2);
- TreeNode node3 = new StringTreeNode("Child Two");
- TreeNode node3a = new StringTreeNode("GrandChild Two");
- node3.insert(node3a);
- TreeNode node3a1 = new StringTreeNode("Great Grandchild One");
- node3a.insert(node3a1);
- node1.insert(node3);
- // Wrap the root node in a SimpleTreeDataModel
- treeDataModel = new SimpleTreeDataModel(node1);
- // Wrap the SimpleTreeDataModel in a SimpleTreeModel
- treeModel = new SimpleTreeModel(treeDataModel);
- }
- return treeModel;
- }
- </pre>
- </div>
- <p>
- That's about all you have to do to create a simple tree that renders
- Strings. Most likely you will want to perform some action when
- the user clicks on a node. We'll do that next.
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree3">Performing an action when a node is clicked...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="tapestrytrees.FirstTreePage">
- <context-asset name="stylesheet" path="css/style.css"/>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- </component>
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>Performing an action when a node is clicked</h1>
- <div class="note">
- This page demonstrates how to use a TreeStateListener to
- respond when a node is clicked.
- </div>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- <tr>
- <td colspan="4">
- <code class="highlight"><span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/></code>
- <td>
- </tr>
- </table>
- <p>
- Here is a snippet from FirstTree3.hmtl that adds a dynamic string
- to the page to indicate the last node that was selected:
- <div class="code">
- <pre>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- <tr>
- <td colspan="4"><code class="highlight">
- <code class="highlight">
- <span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/>
- </code></code>
- <td>
- </tr>
- </table>
- </pre>
- </div>
- <p>
- The TreeView's TreeStateListener is notified any time a node
- of the tree is selected. In our case the page is the TreeStateListener.
- This was set up on <code>FirstTree3.page</code> in the following snippet:
- <div class="code">
- <pre>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" expression='treeModel'/>
- <code class="highlight"><binding name="treeStateListener" expression='treeStateListener'/></code>
- </component>
- </pre>
- </div>
- Here are some code
- snippets from <code>FirstTreePage.java</code> that demonstrate how
- to respond to events from the tree:
- <div class="code">
- <pre>
- public class FirstTreePage extends BasePage
- implements <code class="highlight">ITreeStateListener</code> {
- public ITreeStateListener getTreeStateListener() {
- return this;
- }
- /*
- * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)
- */
- public void treeStateChanged(TreeStateEvent objEvent) {
- // Get the StringTreeNode object that was selected
- TreeView treeView = (TreeView)getComponent("treeView");
- if(treeView != null){
- ITreeDataModel thisTreeDataModel = treeView.getTreeModel().getTreeDataModel();
- Object selectedNode = thisTreeDataModel.getObject(objEvent.getNodeUID());
- if(selectedNode instanceof StringTreeNode){
- lastNodeSelectedValue = ((StringTreeNode)selectedNode).getValue();
- }
- } else { // This shouldn't happen
- lastNodeSelectedValue = objEvent.getNodeUID().toString();
- }
- }
- String lastNodeSelectedValue;
- public String getLastNodeSelectedMsg()
- {
- if(lastNodeSelectedValue==null){
- return null;
- }
- return lastNodeSelectedValue + " was the last node selected.";
- }
- </pre>
- </div>
- <p>
- As you can see, in the <code>TreeStateChanged</code> event handler
- it is fairly easy to get the ITreeNode that was
- selected. With that information you can do whatever is appropriate for
- your application.
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree4">Changing the open and close icons...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="tapestrytrees.FirstTreePage">
- <context-asset name="stylesheet" path="css/style.css"/>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- </component>
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>Changing the open and close icons</h1>
- <div class="note">
- This page demonstrates how to supply custom open and close icons
- to the <code>TreeNodeView</code>.
- </div>
- <p>
- It's really quite simple to change the open and close icons in
- the tree:
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- <tr>
- <td colspan="4">
- <code class="highlight"><span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/></code>
- <td>
- </tr>
- </table>
- <p>
- Here are the relevent snippets from <code>FirstTree4.page</code>
- that change the open and close icons:
- <div class="code">
- <pre>
- <code class="highlight"> <context-asset name="closeNodeImage" path="images/TreeClosed.gif"/>
- <context-asset name="openNodeImage" path="images/TreeOpen.gif"/>
- </code>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- <code class="highlight"> <binding name="closeNodeImage" expression="assets.closeNodeImage"/>
- <binding name="openNodeImage" expression="assets.openNodeImage"/>
- </code> </component>
- </pre>
- </div>
- <p>
- Unfortunately, TreeNodeView does not differentiate between nodes
- that have children and leaf nodes. The same icons will be displayed
- for every node. If this doesn't meet your needs you will have to
- create some custom Java classes.
- <p>
- If you do not want open and close icons to be displayed, add the
- following binding to the <code>"treeNodeView"</code> component:
- <div class="code">
- <pre>
- <binding name="showNodeImages" expression="false"/>
- </pre>
- </div>
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="tapestrytrees.FirstTreePage">
- <context-asset name="stylesheet" path="css/style.css"/>
- <context-asset name="closeNodeImage" path="images/TreeClosed.gif"/>
- <context-asset name="openNodeImage" path="images/TreeOpen.gif"/>
- <component id="treeView" type="contrib:TreeView">
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <binding name="makeNodeDirect" expression="true"/>
- <binding name="closeNodeImage" expression="assets.closeNodeImage"/>
- <binding name="openNodeImage" expression="assets.openNodeImage"/>
- <!--<binding name="showNodeImages" expression="false"/>-->
- </component>
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>Using The Tapestry Tree Control</h1>
- <div class="note">
- by John Reynolds: Updated on October 22nd 2004
- </div>
- <p>
- This application demonstrates some common ways to use the Tapestry Tree components.
- Thanks to
- Howard Lewis Ship and the many subscribers of the Tapestry Users List who offered
- suggestions and guidance.
- </p><p>
- This application provides a series of pages that demonstrate one way of configuring
- the Tree to produce desired behaviors. The chosen techniques may not be optimal,
- but hopefully they will be understandable and will help you figure out how to reach
- your own objectives.
- </p><p>
- Below is a static HTML representation of the first tree that we will
- implement:
- <p>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree">
- <span style="padding-left: 0px" class="notSelectedNodeViewClass">
- <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
- Root Node<br>
- </span>
- <span style="padding-left: 15px" class="notSelectedNodeViewClass">
- <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
- Child One<br>
- </span>
- <span style="padding-left: 30px" class="notSelectedNodeViewClass">
- <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
- Grandchild One<br>
- </span>
- <span style="padding-left: 15px" class="notSelectedNodeViewClass">
- <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
- Child Two<br>
- </span>
- <span style="padding-left: 30px" class="notSelectedNodeViewClass">
- <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
- GrandChild Two<br>
- </span>
- <span style="padding-left: 45px" class="selectedNodeViewClass">
- <img src="/TapestryTrees/app?service=asset&sp=S%2Forg%2Fapache%2Ftapestry%2Fcontrib%2Ftree%2Fcomponents%2Fminus.gif" border="0"/>
- Great Grandchild One<br>
- </span>
- </span>
- </td>
- </tr>
- </table>
- <p>
- The Tree components require creating a bit of custom Java to use, but
- the results are pretty nice. If you want to skip ahead and see something
- impressive,
- follow the link to the <a href="#" jwcid="@PageLink" page="FileSystemTree">Tapestry Workbench File System Tree</a>.
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree">Getting Started...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree1">Creating a class that implements ITreeNode...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree2">Creating a populated ITreeModel...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree3">Performing an action when a node is clicked...</a>
- <p>
- <a href="#" jwcid="@PageLink" page="FirstTree4">Changing the open and close icons...</a>
- <p>
- <p>
- <a href="#" jwcid="@PageLink" page="FileSystemTree">The Tapestry Workbench File System Tree...</a>
- </body>
- </html>
- <!--
- * Released in the Public Domain by John Reynolds: http://weblogs.java.net/blog/johnreynolds/
- * October 2004
- * This work is hereby released into the Public Domain.
- * To view a copy of the public domain dedication, visit
- * http://creativecommons.org/licenses/publicdomain/
- * or send a letter to Creative Commons, 559 Nathan Abbott Way,
- * Stanford, California 94305, USA.
- -->
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="org.apache.tapestry.html.BasePage">
- <description><![CDATA[ add a description ]]></description>
- <context-asset name="stylesheet" path="css/style.css"/>
- </page-specification>
- <html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet">
- <head jwcid="@Block">
- <link rel="stylesheet" type="text/css" href="../css/style.css"/>
- </head>
- <body jwcid="@Body">
- <h1>First Tree</h1>
- <div class="note">
- This page demonstates the using the Tree components to implement
- a simple tree.
- </div>
- <p>
- The Tapestry Tree components render ITreeNode objects.
- This is a simple interface that defines nodes which can have a single
- parent and multiple children.
- <p>
- To display a Tree, you must first perform the following steps:
- <ul>
- <li>Create a "tree" of ITreeNode objects</li>
- <li>Create an ITreeDataModel object to wrap the "tree"</li>
- <li>Create an ITreeModel that wraps the ITreeDataModel</li>
- </ul>
- <p>
- <table border="1">
- <tr>
- <td valign="top">
- <span class="tree" jwcid="treeView">
- <span jwcid="treeDataView">
- <span jwcid="treeNodeView"/>
- </span>
- </span>
- </td>
- </tr>
- </table>
- <p>
- <a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE page-specification
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <page-specification class="tapestrytrees.SecondTreePage">
- <context-asset name="stylesheet" path="css/style.css"/>
- <component id="treeView" type="contrib:TreeView">
- <!--<binding name="sessionStateManager" expression='treeSessionStateManager'/>-->
- <binding name="treeModel" expression='treeModel'/>
- <binding name="treeStateListener" expression='treeStateListener'/>
- </component>
- <component id="treeDataView" type="contrib:TreeDataView">
- <binding name="treeView" expression='components.treeView'/>
- <binding name="value" expression='value'/>
- </component>
- <component id="treeNodeView" type="contrib:TreeNodeView">
- <binding name="treeDataView" expression='components.treeDataView'/>
- <!--<binding name="nodeRenderFactory" expression='nodeRenderFactory'/>-->
- <binding name="makeNodeDirect" expression="true"/>
- <!--<binding name="showNodeImages" expression="false"/>-->
- </component>
- </page-specification>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE application
- PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <application name="TapestryTrees" engine-class="org.apache.tapestry.engine.BaseEngine" >
- <description><![CDATA[ This application demonstrates the Tapestry Tree component ]]></description>
- <property name="org.apache.tapestry.visit-class">tapestrytrees.TapestryTreesVisit</property>
- <library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
- <page name="Home" specification-path="Home.page"/>
- </application>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE web-app
- PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
- <!-- generated by Spindle, http://spindle.sourceforge.net -->
- <web-app>
- <display-name>TapestryTrees</display-name>
- <filter>
- <filter-name>redirect</filter-name>
- <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>redirect</filter-name>
- <url-pattern>/</url-pattern>
- </filter-mapping>
- <servlet>
- <servlet-name>TapestryTrees</servlet-name>
- <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>TapestryTrees</servlet-name>
- <url-pattern>/app</url-pattern>
- </servlet-mapping>
- </web-app>