1 15 package org.apache.tapestry.workbench.tree.examples.fsmodel; 16 17 import java.io.File ; 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Vector ; 21 22 import org.apache.tapestry.contrib.tree.model.ITreeNode; 23 24 public class FolderObject extends SFObject{ 25 26 31 private Vector m_vFiles = null; 32 33 38 private Vector m_vFolders = null; 39 private boolean m_bShared; 40 41 public FolderObject(ITreeNode objParent, File objFile, boolean bInvokeInit) { 42 super(objParent, objFile); 43 if(bInvokeInit) 44 init(); 45 } 46 47 public void reload() { 48 m_vFolders = new Vector (); 49 m_vFiles = new Vector (); 50 51 File [] arrFiles = getFile().listFiles(); 52 53 if (arrFiles == null) { 54 return; 55 } 56 57 for (int i=0; i<arrFiles.length; i++) { 58 if (arrFiles[i].isDirectory()) { 59 m_vFolders.addElement(new FolderObject(this, arrFiles[i], true)); 60 } else { 61 m_vFiles.addElement(new FileObject(this, arrFiles[i])); 62 } 63 } 64 } 65 66 public boolean isShared() { 67 return m_bShared; 68 } 69 70 public Vector getFolders() { 71 if (m_vFolders == null) { 72 reload(); 73 } 74 return m_vFolders; 75 } 76 77 public Vector getFiles() { 78 if (m_vFiles == null) { 79 reload(); 80 } 81 return m_vFiles; 82 } 83 84 public int getChildNumber(Object objChild) { 85 for(int i = 0; i < m_vFolders.size(); i++) { 86 Object objChildFolder = m_vFolders.elementAt(i); 87 if (objChildFolder.equals(objChild)) { 88 return i; 89 } 90 } 91 return -1; 92 } 93 94 97 public boolean containsChild(ITreeNode node) { 98 return true; 99 } 100 101 104 public boolean getAllowsChildren() { 105 return true; 106 } 107 108 111 public int getChildCount() { 112 return getFolders().size() + getFiles().size(); 113 } 114 115 118 public Collection getChildren() { 119 ArrayList arrChildrens = new ArrayList (); 120 arrChildrens.addAll(getFolders()); 121 arrChildrens.addAll(getFiles()); 122 return arrChildrens; 123 } 124 125 128 public boolean isLeaf() { 129 return false; 130 } 131 132 private final static String openImage = 133 "/org/apache/tapestry/workbench/tree/examples/fsmodel/TreeOpen.gif"; 134 135 private final static String closedImage = 136 "/org/apache/tapestry/workbench/tree/examples/fsmodel/TreeClosed.gif"; 137 138 public AssetsHolder getAssets() { 139 if (m_objAssetsHolder == null) { 140 m_objAssetsHolder = new AssetsHolder(openImage, closedImage); 141 } 142 return m_objAssetsHolder; 143 } 144 } 145 | Popular Tags |