1 11 package org.eclipse.debug.ui.sourcelookup; 12 13 import java.util.ArrayList ; 14 import org.eclipse.core.resources.IFolder; 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IAdaptable; 19 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 20 import org.eclipse.debug.core.sourcelookup.ISourceContainerType; 21 import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer; 22 import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer; 23 import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.ui.IWorkingSet; 26 27 35 public class WorkingSetSourceContainer extends CompositeSourceContainer{ 36 37 private IWorkingSet fWorkingSet; 38 42 public static final String TYPE_ID = DebugUIPlugin.getUniqueIdentifier()+".containerType.workingSet"; 44 48 public WorkingSetSourceContainer(IWorkingSet workingSet) { 49 fWorkingSet = workingSet; 50 } 51 52 55 public String getName() { 56 return fWorkingSet.getName(); 57 } 58 59 62 public boolean equals(Object obj) { 63 if (obj != null && obj instanceof WorkingSetSourceContainer) { 64 return ((WorkingSetSourceContainer)obj).fWorkingSet.equals(fWorkingSet); 65 } 66 return false; 67 } 68 69 public int hashCode() { 70 return fWorkingSet.hashCode(); 71 } 72 73 76 public ISourceContainerType getType() { 77 return getSourceContainerType(TYPE_ID); 78 } 79 80 83 protected ISourceContainer[] createSourceContainers() throws CoreException { 84 IAdaptable[] elements = fWorkingSet.getElements(); 85 86 if(elements == null) 87 return new ISourceContainer[0]; 88 89 ArrayList locationList = new ArrayList (); 90 for (int i = 0; i < elements.length; i++) { 91 IResource resource = (IResource) elements[i].getAdapter(IResource.class); 92 93 if (resource != null) { 94 switch (resource.getType()) { 95 case IResource.FOLDER: 96 locationList.add(new FolderSourceContainer((IFolder)resource, true)); 97 break; 98 case IResource.PROJECT: 99 locationList.add(new ProjectSourceContainer((IProject)resource, true)); 100 break; 101 } 103 } 104 } 105 return (ISourceContainer[])locationList.toArray(new ISourceContainer[locationList.size()]); 106 } 107 108 } 109 | Popular Tags |