1 11 package org.eclipse.ui.internal.ide.model; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.HashSet ; 16 import java.util.List ; 17 import java.util.Set ; 18 import org.eclipse.core.internal.resources.mapping.ResourceMapping; 19 import org.eclipse.core.internal.resources.mapping.ResourceMappingContext; 20 import org.eclipse.core.internal.resources.mapping.ResourceTraversal; 21 import org.eclipse.core.resources.IProject; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.NullProgressMonitor; 25 import org.eclipse.core.runtime.SubProgressMonitor; 26 27 30 public class CompositeResourceMapping extends ResourceMapping { 31 32 private final Object modelObject; 33 private final ResourceMapping[] mappings; 34 private final IProject[] projects; 35 36 41 public CompositeResourceMapping(Object modelObject, ResourceMapping[] mappings) { 42 this.modelObject = modelObject; 43 this.mappings = mappings; 44 this.projects = getProjects(mappings); 45 } 46 47 50 private IProject[] getProjects(ResourceMapping[] mappings) { 51 Set result = new HashSet (); 52 for (int i = 0; i < mappings.length; i++) { 53 ResourceMapping mapping = mappings[i]; 54 result.addAll(Arrays.asList(mapping.getProjects())); 55 } 56 return (IProject[]) result.toArray(new IProject[result.size()]); 57 } 58 59 62 public Object getModelObject() { 63 return modelObject; 64 } 65 66 69 public IProject[] getProjects() { 70 return projects; 71 } 72 73 76 public ResourceTraversal[] getTraversals(ResourceMappingContext context, 77 IProgressMonitor monitor) throws CoreException { 78 if (monitor == null) 79 monitor = new NullProgressMonitor(); 80 try { 81 monitor.beginTask(null, 100 * mappings.length); 82 List result = new ArrayList (); 83 for (int i = 0; i < mappings.length; i++) { 84 ResourceMapping mapping = mappings[i]; 85 result.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100)))); 86 } 87 return (ResourceTraversal[]) result.toArray(new ResourceTraversal[result.size()]); 88 } finally { 89 monitor.done(); 90 } 91 } 92 93 } 94 | Popular Tags |