1 15 package org.apache.tapestry.workbench.tree.examples; 16 17 import java.io.File ; 18 import java.util.Collection ; 19 import java.util.Date ; 20 21 import org.apache.tapestry.contrib.tree.components.INodeRenderFactory; 22 import org.apache.tapestry.contrib.tree.components.TreeView; 23 import org.apache.tapestry.contrib.tree.model.ITreeDataModel; 24 import org.apache.tapestry.contrib.tree.model.ITreeModel; 25 import org.apache.tapestry.contrib.tree.model.ITreeNode; 26 import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager; 27 import org.apache.tapestry.contrib.tree.model.ITreeStateListener; 28 import org.apache.tapestry.contrib.tree.model.ITreeStateModel; 29 import org.apache.tapestry.contrib.tree.model.TreeStateEvent; 30 import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel; 31 import org.apache.tapestry.html.BasePage; 32 import org.apache.tapestry.workbench.tree.examples.fsmodel.FileSystem; 33 import org.apache.tapestry.workbench.tree.examples.fsmodel.FileSystemDataModel; 34 import org.apache.tapestry.workbench.tree.examples.fsmodel.FileSystemStateManager; 35 import org.apache.tapestry.workbench.tree.examples.fsmodel.FolderObject; 36 import org.apache.tapestry.workbench.tree.examples.fsmodel.NodeRenderFactory; 37 38 public abstract class FileSystemTree extends BasePage implements ISelectedFolderSource, 39 ITreeStateListener 40 { 41 private ITreeSessionStateManager m_objTreeSessionStateManager = null; 42 43 private ITreeDataModel m_objDataModel; 44 45 private ITreeModel m_objModel; 46 47 private Object m_objValue; 48 49 54 public abstract String getTreeRootDir(); 55 56 public FileSystemTree() 57 { 58 super(); 59 } 60 61 protected void initialize() 62 { 63 super.initialize(); 64 m_objDataModel = null; 65 m_objValue = null; 66 m_objTreeSessionStateManager = null; 67 } 68 69 public void initTableModel() 70 { 71 ITreeNode objParent; 72 73 String strRootDir = getTreeRootDir(); 74 75 System.out.println("strRootDir = " + strRootDir); 76 77 if (strRootDir == null || "".equals(strRootDir)) 78 { 79 objParent = new FileSystem(); 80 } 81 else 82 { 83 FolderObject objFolder = new FolderObject(null, new File (strRootDir), true); 84 objFolder.reload(); 85 objParent = objFolder; 86 } 87 88 m_objDataModel = new FileSystemDataModel(objParent); 89 m_objModel = new SimpleTreeModel(m_objDataModel); 90 } 91 92 public Date getCurrentTime() 93 { 94 return new Date (); 95 } 96 97 public ITreeModel getTreeModel() 98 { 99 if (m_objDataModel == null) 100 { 101 initTableModel(); 102 } 103 return m_objModel; 104 } 105 106 111 public Object getValue() 112 { 113 return m_objValue; 114 } 115 116 122 public void setValue(Object value) 123 { 124 m_objValue = value; 125 } 126 127 public INodeRenderFactory getRenderFactory() 128 { 129 return new NodeRenderFactory(); 130 } 131 132 public ITreeSessionStateManager getSessionStateManager() 133 { 134 138 if (m_objTreeSessionStateManager == null) 139 { 140 String strRootDir = getTreeRootDir(); 141 143 m_objTreeSessionStateManager = new FileSystemStateManager(strRootDir); 144 } 145 return m_objTreeSessionStateManager; 146 } 147 148 151 public Collection getSelectedFolderChildren() 152 { 153 TreeView objTreeView = (TreeView) getComponent("treeView"); 154 ITreeStateModel objTreeStateModel = objTreeView.getTreeModel().getTreeStateModel(); 155 Object objSelectedNodeUID = objTreeStateModel.getSelectedNode(); 156 ITreeNode objSelectedNode = null; 157 if (objSelectedNodeUID != null) 158 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getObject( 159 objSelectedNodeUID); 160 else 161 { 162 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getRoot(); 163 } 164 return objSelectedNode.getChildren(); 165 } 166 167 170 public void treeStateChanged(TreeStateEvent objEvent) 171 { 172 DirectoryTableView objDirectoryTableView = (DirectoryTableView) getComponent("directoryTableView"); 173 objDirectoryTableView.resetState(); 174 } 175 176 public ITreeStateListener getTreeStateListener() 177 { 178 return this; 179 } 180 181 public ISelectedFolderSource getSelectedFolderSource() 182 { 183 return this; 184 } 185 186 189 public String getSelectedNodeName() 190 { 191 TreeView objTreeView = (TreeView) getComponent("treeView"); 192 ITreeStateModel objTreeStateModel = objTreeView.getTreeModel().getTreeStateModel(); 193 Object objSelectedNodeUID = objTreeStateModel.getSelectedNode(); 194 ITreeNode objSelectedNode = null; 195 if (objSelectedNodeUID != null) 196 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getObject( 197 objSelectedNodeUID); 198 else 199 { 200 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getRoot(); 201 } 202 return objSelectedNode.toString(); 203 } 204 205 } | Popular Tags |