1 19 package org.openharmonise.him.swing.resourcetree; 20 21 import java.util.*; 22 import java.util.Iterator ; 23 24 import javax.swing.Icon ; 25 import javax.swing.JTree ; 26 import javax.swing.tree.DefaultMutableTreeNode ; 27 import javax.swing.tree.DefaultTreeModel ; 28 import javax.swing.tree.TreePath ; 29 30 import org.openharmonise.vfs.*; 31 import org.openharmonise.vfs.event.*; 32 33 34 41 public class TreeNode extends DefaultMutableTreeNode implements VirtualFileListener { 42 43 46 private String m_sFullPath = null; 47 48 51 private AbstractVirtualFileSystem m_vfs = null; 52 53 56 private String m_sDisplayName = ""; 57 58 61 private Icon m_iDisplayIcon = null; 62 63 66 private Icon m_iDisplayIconExpanded = null; 67 68 71 private boolean m_bIsLeaf=false; 72 73 76 private boolean m_bChildrenPopulated = false; 77 78 private AbstractResourceFilter m_resourceFilter = null; 79 80 83 private JTree m_tree = null; 84 85 92 public TreeNode(AbstractVirtualFileSystem vfs, String sFullPath, JTree tree, AbstractResourceFilter resourceFilter) { 93 super(sFullPath); 94 m_sFullPath = sFullPath; 95 m_vfs = vfs; 96 this.m_tree = tree; 97 VirtualFileSystemView vfsView = vfs.getVirtualFileSystemView(); 98 VirtualFile vfFile = vfs.getVirtualFile(sFullPath).getResource(); 99 100 vfFile.addVirtualFileListener(this); 101 102 this.m_sDisplayName = vfsView.getDisplayName(vfFile); 103 this.m_iDisplayIcon = vfsView.getIcon(vfFile); 104 this.m_iDisplayIconExpanded = vfsView.getIcon(vfFile, true); 105 this.m_bIsLeaf = !vfFile.isDirectory(); 106 107 this.m_resourceFilter = resourceFilter; 108 } 109 110 116 public Icon getDisplayIcon(boolean bExpanded) { 117 if(bExpanded) { 118 return this.m_iDisplayIconExpanded; 119 } else { 120 return this.m_iDisplayIcon; 121 } 122 } 123 124 129 public String getDisplayName() { 130 return this.m_sDisplayName; 131 } 132 133 136 public boolean isLeaf() { 137 return this.m_bIsLeaf; 138 } 139 140 145 public boolean isShowChildren() { 146 return !this.m_resourceFilter.isShowCollectionsOnly(); 147 } 148 149 154 public boolean isShowApprovedOnly() { 155 return this.m_resourceFilter.isShowLiveResourcesOnly(); 156 } 157 158 164 protected void populateChildren() { 165 if(!this.m_bIsLeaf && !m_bChildrenPopulated) { 166 Iterator itor = this.m_vfs.getVirtualFile(this.m_sFullPath).getResource().getChildren().iterator(); 167 int nCount = 0; 168 while(itor.hasNext()) { 169 String sPath = (String )itor.next(); 170 VirtualFile vfChild =this.m_vfs.getVirtualFile(sPath).getResource(); 171 if(sPath!=null && (vfChild.isDirectory() || !this.m_resourceFilter.isShowCollectionsOnly()) && (!this.m_resourceFilter.isShowLiveResourcesOnly() || vfChild.getState()==VirtualFile.STATE_LIVE) && this.m_resourceFilter.checkResource(vfChild)) { 172 this.add( new TreeNode(this.m_vfs, sPath, this.m_tree, this.m_resourceFilter) ); 173 nCount++; 174 } 175 } 176 m_bChildrenPopulated = true; 177 } 178 } 179 180 public boolean isChildrenPopulated() { 181 return this.m_bChildrenPopulated; 182 } 183 184 188 private void refreshChildren() { 189 TreePath treePath = this.m_tree.getSelectionPath(); 190 if(treePath!=null) { 191 Object treeComp = treePath.getLastPathComponent(); 192 } 193 this.m_bChildrenPopulated=false; 194 this.removeAllChildren(); 195 this.populateChildren(); 196 DefaultTreeModel model = (DefaultTreeModel ) this.m_tree.getModel(); 197 model.reload(this); 198 VirtualFile vfFile = this.m_vfs.getVirtualFile(this.m_sFullPath).getResource(); 199 vfFile.addVirtualFileListener(this); 200 this.m_tree.revalidate(); 201 if(treePath!=null) { 202 this.m_tree.expandPath(treePath); 203 } 204 } 205 206 211 public String getFilePath() { 212 return this.m_sFullPath; 213 } 214 215 220 public AbstractVirtualFileSystem getVFS() { 221 return this.m_vfs; 222 } 223 224 227 private TreeNode(Object userObject) { 228 super(userObject); 229 } 230 231 235 private TreeNode(Object userObject, boolean allowsChildren) { 236 super(userObject, allowsChildren); 237 } 238 239 242 public void virtualFileChanged(VirtualFileEvent vfe) { 243 if(vfe.getEventType()==VirtualFileEvent.FILE_MEMBERS_CHANGED) { 244 this.refreshChildren(); 245 } 246 } 247 248 251 public Enumeration children() { 252 populateChildren(); 253 return super.children(); 254 } 255 256 } 257 | Popular Tags |