KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > subscribers > RootResourceSynchronizationScope


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.core.subscribers;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.*;
17 import org.eclipse.core.resources.mapping.*;
18 import org.eclipse.team.core.mapping.ISynchronizationScope;
19 import org.eclipse.team.internal.core.mapping.AbstractResourceMappingScope;
20
21 /**
22  * A synchronization scope for a set of resources.
23  */

24 public class RootResourceSynchronizationScope extends AbstractResourceMappingScope {
25
26     private IResource[] roots;
27
28     public RootResourceSynchronizationScope(IResource[] roots) {
29         this.roots = roots;
30     }
31
32     public ResourceTraversal[] getTraversals() {
33         return new ResourceTraversal[] {new ResourceTraversal(roots, IResource.DEPTH_INFINITE, IResource.NONE)};
34     }
35
36     /**
37      * Set the traversal of this scope to a single traversal
38      * of infinite depth on the given resources.
39      * @param roots the new roots of the scope
40      */

41     public void setRoots(IResource[] roots) {
42         this.roots = roots;
43         fireTraversalsChangedEvent(getTraversals(), getMappings());
44     }
45
46     public ResourceMapping[] getInputMappings() {
47         return getMappings();
48     }
49
50     public ISynchronizationScope asInputScope() {
51         return this;
52     }
53
54     public ResourceMapping[] getMappings() {
55         List JavaDoc result = new ArrayList JavaDoc();
56         for (int i = 0; i < roots.length; i++) {
57             IResource resource = roots[i];
58             Object JavaDoc o = resource.getAdapter(ResourceMapping.class);
59             if (o instanceof ResourceMapping) {
60                 result.add(o);
61             }
62         }
63         return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]);
64     }
65
66     public ResourceTraversal[] getTraversals(ResourceMapping mapping) {
67         Object JavaDoc object = mapping.getModelObject();
68         if (object instanceof IResource) {
69             IResource resource = (IResource) object;
70             return new ResourceTraversal[] {new ResourceTraversal(new IResource[] { resource }, IResource.DEPTH_INFINITE, IResource.NONE)};
71         }
72         return null;
73     }
74
75     public boolean hasAdditionalMappings() {
76         return false;
77     }
78
79     public boolean hasAdditonalResources() {
80         return false;
81     }
82
83     public IProject[] getProjects() {
84         return ResourcesPlugin.getWorkspace().getRoot().getProjects();
85     }
86
87     public ResourceMappingContext getContext() {
88         return ResourceMappingContext.LOCAL_CONTEXT;
89     }
90
91     public void refresh(ResourceMapping[] mappings) {
92         // Not supported
93
}
94
95 }
96
Popular Tags