1 15 package org.apache.tapestry.workbench.tree.examples; 16 17 import java.io.File ; 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Date ; 21 22 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; 23 import org.apache.tapestry.contrib.tree.components.INodeRenderFactory; 24 import org.apache.tapestry.contrib.tree.components.table.TreeTable; 25 import org.apache.tapestry.contrib.tree.model.ITreeDataModel; 26 import org.apache.tapestry.contrib.tree.model.ITreeModel; 27 import org.apache.tapestry.contrib.tree.model.ITreeModelSource; 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.model.TreeRowObject; 33 import org.apache.tapestry.contrib.tree.model.TreeStateEvent; 34 import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel; 35 import org.apache.tapestry.html.BasePage; 36 import org.apache.tapestry.workbench.tree.examples.fsmodel.FileSystem; 37 import org.apache.tapestry.workbench.tree.examples.fsmodel.FileSystemDataModel; 38 import org.apache.tapestry.workbench.tree.examples.fsmodel.FileSystemStateManager; 39 import org.apache.tapestry.workbench.tree.examples.fsmodel.FolderObject; 40 import org.apache.tapestry.workbench.tree.examples.fsmodel.IFileSystemTreeNode; 41 import org.apache.tapestry.workbench.tree.examples.fsmodel.NodeRenderFactory; 42 43 public abstract class FileSystemTreeTable extends BasePage implements ISelectedFolderSource, 44 ITreeStateListener 45 { 46 private ITreeSessionStateManager m_objTreeSessionStateManager = null; 47 48 private ITreeDataModel m_objDataModel; 49 50 private ITreeModel m_objModel; 51 52 private Object m_objValue; 53 54 private ArrayList m_arrTableColumns = null; 55 56 61 62 public abstract String getTreeRootDir(); 63 64 public FileSystemTreeTable() 65 { 66 super(); 67 } 68 69 protected void initialize() 70 { 71 super.initialize(); 72 m_objDataModel = null; 73 m_objValue = null; 74 m_objTreeSessionStateManager = null; 75 } 76 77 public void initTableModel() 78 { 79 ITreeNode objParent; 80 String strRootDir = getTreeRootDir(); 81 82 System.out.println("strRootDir = " + strRootDir); 83 84 if (strRootDir == null || "".equals(strRootDir)) 85 { 86 objParent = new FileSystem(); 87 } 88 else 89 { 90 FolderObject objFolder = new FolderObject(null, new File (strRootDir), true); 91 objFolder.reload(); 92 objParent = objFolder; 93 } 94 95 m_objDataModel = new FileSystemDataModel(objParent); 96 m_objModel = new SimpleTreeModel(m_objDataModel); 97 } 98 99 public Date getCurrentTime() 100 { 101 return new Date (); 102 } 103 104 public ITreeModel getTreeModel() 105 { 106 if (m_objDataModel == null) 107 { 108 initTableModel(); 109 } 110 return m_objModel; 111 } 112 113 118 public Object getValue() 119 { 120 return m_objValue; 121 } 122 123 129 public void setValue(Object value) 130 { 131 m_objValue = value; 132 } 133 134 public INodeRenderFactory getRenderFactory() 135 { 136 return new NodeRenderFactory(); 137 } 138 139 public ITreeSessionStateManager getSessionStateManager() 140 { 141 if (m_objTreeSessionStateManager == null) 142 { 143 String strRootDir = getTreeRootDir(); 144 m_objTreeSessionStateManager = new FileSystemStateManager(strRootDir); 145 } 146 return m_objTreeSessionStateManager; 147 } 148 149 152 public ArrayList getTableColumns() 153 { 154 if (m_arrTableColumns == null) 155 { 156 m_arrTableColumns = new ArrayList (); 157 m_arrTableColumns.add(new SimpleTableColumn("Date", true) 158 { 159 public Object getColumnValue(Object objValue) 160 { 161 TreeRowObject objRowObject = (TreeRowObject) objValue; 162 IFileSystemTreeNode objFileSystemTreeNode = (IFileSystemTreeNode) objRowObject 164 .getTreeNode(); 165 return objFileSystemTreeNode.getDate(); 166 } 167 }); 168 } 169 return m_arrTableColumns; 170 } 171 172 175 public Collection getSelectedFolderChildren() 176 { 177 TreeTable objTreeTable = (TreeTable) getComponent("tree"); 178 ITreeModelSource objTreeModelSource = objTreeTable.getTreeModelSource(); 179 ITreeStateModel objTreeStateModel = objTreeModelSource.getTreeModel().getTreeStateModel(); 180 Object objSelectedNodeUID = objTreeStateModel.getSelectedNode(); 181 ITreeNode objSelectedNode = null; 182 if (objSelectedNodeUID != null) 183 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getObject( 184 objSelectedNodeUID); 185 else 186 { 187 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getRoot(); 188 } 189 return objSelectedNode.getChildren(); 190 } 191 192 195 public void treeStateChanged(TreeStateEvent objEvent) 196 { 197 DirectoryTableView objDirectoryTableView = (DirectoryTableView) getComponent("directoryTableView"); 198 objDirectoryTableView.resetState(); 199 } 200 201 public ITreeStateListener getTreeStateListener() 202 { 203 return this; 204 } 205 206 public ISelectedFolderSource getSelectedFolderSource() 207 { 208 return this; 209 } 210 211 214 public String getSelectedNodeName() 215 { 216 TreeTable objTreeTable = (TreeTable) getComponent("tree"); 217 ITreeModelSource objTreeModelSource = objTreeTable.getTreeModelSource(); 218 ITreeStateModel objTreeStateModel = objTreeModelSource.getTreeModel().getTreeStateModel(); 219 Object objSelectedNodeUID = objTreeStateModel.getSelectedNode(); 220 ITreeNode objSelectedNode = null; 221 if (objSelectedNodeUID != null) 222 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getObject( 223 objSelectedNodeUID); 224 else 225 { 226 objSelectedNode = (ITreeNode) getTreeModel().getTreeDataModel().getRoot(); 227 } 228 return objSelectedNode.toString(); 229 } 230 } | Popular Tags |