1 11 package org.eclipse.core.resources.mapping; 12 13 import java.util.*; 14 import org.eclipse.core.internal.resources.mapping.ModelProviderManager; 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.runtime.*; 17 18 31 public abstract class ModelProvider extends PlatformObject { 32 33 36 public static final String RESOURCE_MODEL_PROVIDER_ID = "org.eclipse.core.resources.modelProvider"; 38 private IModelProviderDescriptor descriptor; 39 40 47 public static IModelProviderDescriptor getModelProviderDescriptor(String id) { 48 IModelProviderDescriptor[] descs = ModelProviderManager.getDefault().getDescriptors(); 49 for (int i = 0; i < descs.length; i++) { 50 IModelProviderDescriptor descriptor = descs[i]; 51 if (descriptor.getId().equals(id)) { 52 return descriptor; 53 } 54 } 55 return null; 56 } 57 58 63 public static IModelProviderDescriptor[] getModelProviderDescriptors() { 64 return ModelProviderManager.getDefault().getDescriptors(); 65 } 66 67 70 public boolean equals(Object obj) { 71 if (obj instanceof ModelProvider) { 72 ModelProvider other = (ModelProvider) obj; 73 return other.getDescriptor().getId().equals(getDescriptor().getId()); 74 } 75 return super.equals(obj); 76 } 77 78 84 public final IModelProviderDescriptor getDescriptor() { 85 return descriptor; 86 } 87 88 100 public final String getId() { 101 return descriptor.getId(); 102 } 103 104 119 public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 120 return new ResourceMapping[0]; 121 } 122 123 139 public ResourceMapping[] getMappings(IResource[] resources, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 140 Set mappings = new HashSet(); 141 for (int i = 0; i < resources.length; i++) { 142 IResource resource = resources[i]; 143 ResourceMapping[] resourceMappings = getMappings(resource, context, monitor); 144 if (resourceMappings.length > 0) 145 mappings.addAll(Arrays.asList(resourceMappings)); 146 } 147 return (ResourceMapping[]) mappings.toArray(new ResourceMapping[mappings.size()]); 148 } 149 150 166 public ResourceMapping[] getMappings(ResourceTraversal[] traversals, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 167 Set result = new HashSet(); 168 for (int i = 0; i < traversals.length; i++) { 169 ResourceTraversal traversal = traversals[i]; 170 ResourceMapping[] mappings = getMappings(traversal.getResources(), context, monitor); 171 for (int j = 0; j < mappings.length; j++) 172 result.add(mappings[j]); 173 } 174 return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); 175 } 176 177 195 public ResourceTraversal[] getTraversals(ResourceMapping[] mappings, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 196 try { 197 monitor.beginTask("", 100 * mappings.length); List traversals = new ArrayList(); 199 for (int i = 0; i < mappings.length; i++) { 200 ResourceMapping mapping = mappings[i]; 201 traversals.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100)))); 202 } 203 return (ResourceTraversal[]) traversals.toArray(new ResourceTraversal[traversals.size()]); 204 } finally { 205 monitor.done(); 206 } 207 } 208 209 212 public int hashCode() { 213 return getDescriptor().getId().hashCode(); 214 } 215 216 225 public final void init(IModelProviderDescriptor desc) { 226 if (descriptor != null) 227 return; 229 descriptor = desc; 230 initialize(); 231 } 232 233 237 protected void initialize() { 238 } 240 241 263 public IStatus validateChange(IResourceDelta delta, IProgressMonitor monitor) { 264 return new ModelStatus(IStatus.OK, ResourcesPlugin.PI_RESOURCES, descriptor.getId(), Status.OK_STATUS.getMessage()); 265 } 266 } 267 | Popular Tags |