1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.ui.ISharedImages; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.model.IWorkbenchAdapter; 25 import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider; 26 27 class MinimizedFileSystemElement implements IWorkbenchAdapter, IAdaptable { 28 private boolean populated = false; 29 private List folders = null; 30 private List files = null; 31 private String name; 32 private boolean isDirectory = false; 33 private MinimizedFileSystemElement parent; 34 private Object fileSystemObject; 35 36 42 public MinimizedFileSystemElement(String name, MinimizedFileSystemElement parent, boolean isDirectory) { 43 this.name = name; 44 this.parent = parent; 45 this.isDirectory = isDirectory; 46 if (parent != null) { 47 parent.addChild(this); 48 } 49 } 50 51 54 public Object getAdapter(Class adapter) { 55 if (adapter == IWorkbenchAdapter.class) { 56 return this; 57 } 58 return Platform.getAdapterManager().getAdapter(this, adapter); 60 } 61 62 66 public boolean isDirectory() { 67 return isDirectory; 68 } 69 70 75 private void addChild(MinimizedFileSystemElement child) { 76 if (child.isDirectory()) { 77 if (folders == null) { 78 folders = new ArrayList (1); 79 } 80 folders.add(child); 81 } else { 82 if (files == null) { 83 files = new ArrayList (1); 84 } 85 files.add(child); 86 } 87 } 88 92 protected List getFiles(IImportStructureProvider provider) { 93 if (!populated) { 94 populate(provider); 95 } 96 97 if (files == null) { 98 return Collections.EMPTY_LIST; 99 } 100 return files; 101 102 } 103 107 protected List getFolders(IImportStructureProvider provider) { 108 if (!populated) { 109 populate(provider); 110 } 111 112 return getFolders(); 113 114 } 115 116 protected List getFolders() { 117 if (folders == null){ 118 return Collections.EMPTY_LIST; 119 } 120 return folders; 121 } 122 125 protected boolean isPopulated() { 126 return this.populated; 127 } 128 131 protected boolean notPopulated() { 132 return !this.populated; 133 } 134 139 private void populate(IImportStructureProvider provider) { 140 141 List children = provider.getChildren(fileSystemObject); 142 if (children == null) { 143 children = new ArrayList (1); 144 } 145 Iterator childrenEnum = children.iterator(); 146 while (childrenEnum.hasNext()) { 147 Object child = childrenEnum.next(); 148 149 String elementLabel = provider.getLabel(child); 150 boolean isFolder= provider.isFolder(child); 151 if (!isFolder && !elementLabel.endsWith(".class")) { continue; 153 } 154 MinimizedFileSystemElement result = new MinimizedFileSystemElement(elementLabel, this, isFolder); 156 result.setFileSystemObject(child); 157 } 158 setPopulated(); 159 } 160 161 166 protected Object getFileSystemObject() { 167 return fileSystemObject; 168 } 169 170 175 protected void setFileSystemObject(Object value) { 176 fileSystemObject = value; 177 } 178 181 protected void setPopulated() { 182 this.populated = true; 183 } 184 187 public Object [] getChildren(Object o) { 188 return getFolders().toArray(); 189 } 190 191 194 public ImageDescriptor getImageDescriptor(Object object) { 195 if (isDirectory()) { 196 return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER); 197 } 198 return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(name); 199 } 200 201 204 public String getLabel(Object o) { 205 return name; 206 } 207 208 211 public Object getParent(Object o) { 212 return parent; 213 } 214 215 } 216 217 | Popular Tags |