KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > operations > WorkspaceResourceMapper


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.operations;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.mapping.*;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IProgressMonitor;
21
22 /**
23  * Utility class used to warp an set of resources in a resource mapper.
24  * The resulting mapper will return the workspace root as the model
25  * object.
26  *
27  * TODO: The ability to wrap multiple resources in a single mapping
28  * should be provided by the resources plugin.
29  *
30  * @since 3.1
31  */

32 public final class WorkspaceResourceMapper extends ResourceMapping {
33     
34     private final IResource resource;
35     private final int depth;
36     
37     /**
38      * Convert the provided resources to one or more resource mappers
39      * that traverse the elements deeply. The model element of the resource
40      * mappers will be the workspace root.
41      * @param resources the resources
42      * @return a resource mappers that traverses the resources
43      */

44     public static ResourceMapping[] asResourceMappers(final IResource[] resources, int depth) {
45         List JavaDoc result = new ArrayList JavaDoc();
46         for (int i = 0; i < resources.length; i++) {
47             IResource resource = resources[i];
48             result.add(new WorkspaceResourceMapper(resource, depth));
49         }
50         return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]);
51     }
52     
53     public WorkspaceResourceMapper(IResource resource, int depth) {
54         this.resource = resource;
55         this.depth = depth;
56     }
57     public Object JavaDoc getModelObject() {
58         return resource;
59     }
60     public IProject[] getProjects() {
61         return new IProject[] { resource.getProject() };
62     }
63     public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
64         return asTraversal(resource, depth, context);
65     }
66     private ResourceTraversal[] asTraversal(IResource resource, final int depth, ResourceMappingContext context) {
67         return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { resource }, depth, IResource.NONE)} ;
68     }
69     public boolean contains(ResourceMapping mapping) {
70         return false;
71     }
72
73     public String JavaDoc getModelProviderId() {
74         return ModelProvider.RESOURCE_MODEL_PROVIDER_ID;
75     }
76 }
77
Popular Tags