1 15 package org.apache.tapestry.workbench.tree.examples.fsmodel; 16 17 import java.io.File ; 18 import java.util.Collection ; 19 import java.util.Date ; 20 import java.util.Vector ; 21 22 import org.apache.tapestry.contrib.tree.model.ITreeNode; 23 24 public class FileSystem implements IFileSystemTreeNode 25 { 26 27 private transient AssetsHolder m_objAssetsHolder = null; 28 31 32 private Vector m_vDrives; 33 34 public FileSystem() 35 { 36 } 38 39 private void initDrives() 40 { 41 m_vDrives = new Vector (); 42 File [] arrFile = File.listRoots(); 43 44 if (arrFile != null) 45 for(int i=0; i<arrFile.length; i++) 46 { 47 File objFile = arrFile[i]; 48 boolean bFloppy = objFile.getAbsolutePath().startsWith("A:") || objFile.getAbsolutePath().startsWith("B:"); 49 if(!bFloppy) 50 m_vDrives.addElement(new Drive(this, objFile)); 51 } 52 } 53 54 public Vector getDrives() 55 { 56 if(m_vDrives == null){ 57 initDrives(); 58 } 59 return m_vDrives; 60 } 61 public int getChildNumber(Object objChild) 62 { 63 for(int i=0;i<m_vDrives.size();i++) 64 { 65 Object objChildDrive = m_vDrives.elementAt(i); 66 if(objChildDrive.equals(objChild)) 67 { 68 return i; 69 } 70 } 71 return -1; 72 } 73 76 public boolean containsChild(ITreeNode node) { 77 return true; 78 } 79 80 83 public boolean getAllowsChildren() { 84 return true; 85 } 86 87 90 public int getChildCount() { 91 return getDrives().size(); 92 } 93 94 97 public Collection getChildren() { 98 return getDrives(); 99 } 100 101 104 public ITreeNode getParent() { 105 return null; 106 } 107 108 111 public boolean isLeaf() { 112 return false; 113 } 114 115 118 public String toString() { 119 return getName(); 120 } 121 public String getName(){ 122 return "FileSystem"; 123 } 124 125 128 public boolean equals(Object arg0) { 129 if(!(arg0 instanceof FileSystem)) 130 return false; 131 FileSystem objFileSystem = (FileSystem)arg0; 132 if(getName().equals(objFileSystem.getName())) 133 return true; 134 return false; 135 } 136 137 140 public int hashCode() { 141 return getName().hashCode(); 142 } 143 144 147 public String getAbsolutePath() { 148 return ""; 149 } 150 151 154 public AssetsHolder getAssets() { 155 if(m_objAssetsHolder == null){ 156 m_objAssetsHolder = new AssetsHolder("/org/apache/tapestry/workbench/tree/examples/fsmodel/computer.gif", "/org/apache/tapestry/workbench/tree/examples/fsmodel/computer.gif"); 157 } 158 return m_objAssetsHolder; 159 } 160 161 164 public Date getDate() { 165 return null; 166 } 167 168 } 169 | Popular Tags |