1 11 package org.eclipse.debug.core.sourcelookup.containers; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 20 import org.eclipse.debug.core.sourcelookup.ISourceContainerType; 21 22 32 33 public class DirectorySourceContainer extends CompositeSourceContainer { 34 35 private File fDirectory; 37 private boolean fSubfolders = false; 39 43 public static final String TYPE_ID = DebugPlugin.getUniqueIdentifier() + ".containerType.directory"; 45 53 public DirectorySourceContainer(IPath dirPath, boolean subfolders) { 54 this(dirPath.toFile(), subfolders); 55 } 56 57 65 public DirectorySourceContainer(File dir, boolean subfolders) { 66 fDirectory = dir; 67 fSubfolders = subfolders; 68 } 69 70 73 public String getName() { 74 return fDirectory.getName(); 75 } 76 77 84 public File getDirectory() { 85 return fDirectory; 86 } 87 88 91 public ISourceContainerType getType() { 92 return getSourceContainerType(TYPE_ID); 93 } 94 95 98 public Object [] findSourceElements(String name) throws CoreException { 99 ArrayList sources = new ArrayList (); 100 File directory = getDirectory(); 101 File file = new File (directory, name); 102 if (file.exists() && file.isFile()) { 103 sources.add(new LocalFileStorage(file)); 104 } 105 106 if ((isFindDuplicates() && fSubfolders) || (sources.isEmpty() && fSubfolders)) { 108 ISourceContainer[] containers = getSourceContainers(); 109 for (int i=0; i < containers.length; i++) { 110 Object [] objects = containers[i].findSourceElements(name); 111 if (objects == null || objects.length == 0) { 112 continue; 113 } 114 if (isFindDuplicates()) { 115 for(int j=0; j < objects.length; j++) 116 sources.add(objects[j]); 117 } else { 118 sources.add(objects[0]); 119 break; 120 } 121 } 122 } 123 124 if(sources.isEmpty()) 125 return EMPTY; 126 return sources.toArray(); 127 } 128 129 132 public boolean isComposite() { 133 return fSubfolders; 134 } 135 136 139 public boolean equals(Object obj) { 140 if (obj instanceof DirectorySourceContainer) { 141 DirectorySourceContainer container = (DirectorySourceContainer) obj; 142 return container.getDirectory().equals(getDirectory()); 143 } 144 return false; 145 } 146 149 public int hashCode() { 150 return getDirectory().hashCode(); 151 } 152 153 156 protected ISourceContainer[] createSourceContainers() throws CoreException { 157 if (isComposite()) { 158 String [] files = fDirectory.list(); 159 if (files != null) { 160 List dirs = new ArrayList (); 161 for (int i = 0; i < files.length; i++) { 162 String name = files[i]; 163 File file = new File (getDirectory(), name); 164 if (file.exists() && file.isDirectory()) { 165 dirs.add(new DirectorySourceContainer(file, true)); 166 } 167 } 168 ISourceContainer[] containers = (ISourceContainer[]) dirs.toArray(new ISourceContainer[dirs.size()]); 169 for (int i = 0; i < containers.length; i++) { 170 ISourceContainer container = containers[i]; 171 container.init(getDirector()); 172 } 173 return containers; 174 } 175 } 176 return new ISourceContainer[0]; 177 } 178 179 } 180 | Popular Tags |