1 11 12 package org.eclipse.ui.internal.ide.model; 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.HashSet ; 17 import java.util.List ; 18 import java.util.Set ; 19 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.core.resources.mapping.ModelProvider; 22 import org.eclipse.core.resources.mapping.ResourceMapping; 23 import org.eclipse.core.resources.mapping.ResourceMappingContext; 24 import org.eclipse.core.resources.mapping.ResourceTraversal; 25 import org.eclipse.core.runtime.CoreException; 26 import org.eclipse.core.runtime.IAdaptable; 27 import org.eclipse.core.runtime.IProgressMonitor; 28 import org.eclipse.core.runtime.NullProgressMonitor; 29 import org.eclipse.core.runtime.SubProgressMonitor; 30 import org.eclipse.ui.IWorkingSet; 31 32 35 public class WorkingSetResourceMapping extends ResourceMapping { 36 37 private IWorkingSet set; 38 39 43 public WorkingSetResourceMapping(IWorkingSet workingSet) { 44 set = workingSet; 45 } 46 47 50 public Object getModelObject() { 51 return set; 52 } 53 54 57 public String getModelProviderId() { 58 return ModelProvider.RESOURCE_MODEL_PROVIDER_ID; 59 } 60 61 64 public IProject[] getProjects() { 65 Set result = new HashSet (); 66 ResourceMapping[] mappings = getMappings(); 67 for (int i = 0; i < mappings.length; i++) { 68 ResourceMapping mapping = mappings[i]; 69 IProject[] projects = mapping.getProjects(); 70 for (int j = 0; j < projects.length; j++) { 71 IProject project = projects[j]; 72 result.add(project); 73 } 74 } 75 return (IProject[]) result.toArray(new IProject[result.size()]); 76 } 77 78 81 public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 82 if (monitor == null) 83 monitor = new NullProgressMonitor(); 84 try { 85 ResourceMapping[] mappings = getMappings(); 86 monitor.beginTask("", 100 * mappings.length); List result = new ArrayList (); 88 for (int i = 0; i < mappings.length; i++) { 89 ResourceMapping mapping = mappings[i]; 90 result.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100)))); 91 } 92 return (ResourceTraversal[]) result.toArray(new ResourceTraversal[result.size()]); 93 } finally { 94 monitor.done(); 95 } 96 } 97 98 102 private ResourceMapping[] getMappings() { 103 IAdaptable[] elements = set.getElements(); 104 List result = new ArrayList (); 105 for (int i = 0; i < elements.length; i++) { 106 IAdaptable element = elements[i]; 107 ResourceMapping mapping = WorkingSetAdapterFactory.getContributedResourceMapping(element); 108 if (mapping == null) { 109 mapping = WorkingSetAdapterFactory.getResourceMapping(element); 110 } 111 if (mapping != null) { 112 result.add(mapping); 113 } 114 } 115 return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); 116 } 117 118 121 public boolean contains(ResourceMapping mapping) { 122 ResourceMapping[] mappings = getMappings(); 123 for (int i = 0; i < mappings.length; i++) { 124 ResourceMapping childMapping = mappings[i]; 125 if (childMapping.contains(mapping)) { 126 return true; 127 } 128 } 129 return false; 130 } 131 132 } 133 | Popular Tags |