1 11 package org.eclipse.core.internal.resources.mapping; 12 13 import java.util.*; 14 import org.eclipse.core.resources.IContainer; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.mapping.*; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 20 25 public final class ResourceModelProvider extends ModelProvider { 26 27 30 public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) { 31 return new ResourceMapping[] {new SimpleResourceMapping(resource)}; 32 } 33 34 37 public ResourceMapping[] getMappings(ResourceTraversal[] traversals, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 38 Set result = new HashSet(); 39 for (int i = 0; i < traversals.length; i++) { 40 ResourceTraversal traversal = traversals[i]; 41 IResource[] resources = traversal.getResources(); 42 int depth = traversal.getDepth(); 43 for (int j = 0; j < resources.length; j++) { 44 IResource resource = resources[j]; 45 switch (depth) { 46 case IResource.DEPTH_INFINITE : 47 result.add(resource); 48 break; 49 case IResource.DEPTH_ONE : 50 if (resource.getType() == IResource.FILE) { 51 result.add(resource); 52 } else { 53 result.add(new ShallowContainer((IContainer)resource)); 54 } 55 break; 56 case IResource.DEPTH_ZERO : 57 if (resource.getType() == IResource.FILE) 58 result.add(resource); 59 break; 60 } 61 } 62 } 63 ResourceMapping[] mappings = new ResourceMapping[result.size()]; 64 int i = 0; 65 for (Iterator iter = result.iterator(); iter.hasNext();) { 66 Object element = iter.next(); 67 if (element instanceof IResource) { 68 mappings[i++] = new SimpleResourceMapping((IResource) element); 69 } else { 70 mappings[i++] = new ShallowResourceMapping((ShallowContainer)element); 71 } 72 } 73 return mappings; 74 } 75 } 76 | Popular Tags |