1 11 package org.eclipse.team.internal.core.mapping; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.resources.mapping.*; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.team.internal.core.Policy; 21 import org.eclipse.team.internal.core.TeamPlugin; 22 23 public class ModelProviderResourceMapping extends ResourceMapping { 24 25 ModelProvider provider; 26 27 public ModelProviderResourceMapping(ModelProvider provider) { 28 this.provider = provider; 29 } 30 31 34 public Object getModelObject() { 35 return provider; 36 } 37 38 41 public String getModelProviderId() { 42 return ModelProvider.RESOURCE_MODEL_PROVIDER_ID; 45 } 46 47 50 public IProject[] getProjects() { 51 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); 52 try { 53 IResource[] resources = provider.getDescriptor().getMatchingResources(projects); 54 Set result = new HashSet (); 55 for (int i = 0; i < resources.length; i++) { 56 IResource resource = resources[i]; 57 if (resource.isAccessible()) 58 result.add(resource.getProject()); 59 } 60 return (IProject[]) result.toArray(new IProject[result.size()]); 61 } catch (CoreException e) { 62 TeamPlugin.log(e); 63 } 64 return projects; 65 } 66 67 70 public ResourceTraversal[] getTraversals(ResourceMappingContext context, 71 IProgressMonitor monitor) throws CoreException { 72 monitor = Policy.monitorFor(monitor); 73 try { 74 monitor.beginTask(null, 100); 75 ResourceMapping[] mappings = provider.getMappings(getProviderResources(context), context, Policy.subMonitorFor(monitor, 50)); 76 return provider.getTraversals(mappings, context, Policy.subMonitorFor(monitor, 50)); 77 } finally { 78 monitor.done(); 79 } 80 } 81 82 private IResource[] getProviderResources(ResourceMappingContext context) { 83 try { 84 if (context instanceof RemoteResourceMappingContext) { 85 RemoteResourceMappingContext rrmc = (RemoteResourceMappingContext) context; 86 return provider.getDescriptor().getMatchingResources(rrmc.getProjects()); 87 } 88 } catch (CoreException e) { 89 TeamPlugin.log(e); 90 } 91 return getProjects(); 92 } 93 94 public boolean contains(ResourceMapping mapping) { 95 return (mapping.getModelProviderId().equals(getModelProviderId())); 96 } 97 98 } 99 | Popular Tags |