KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > mapping > ResourceMappingScope


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.mapping;
12
13 import java.util.*;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.ResourcesPlugin;
17 import org.eclipse.core.resources.mapping.*;
18 import org.eclipse.team.core.mapping.ISynchronizationScope;
19 import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager;
20
21 /**
22  * Concrete implementation of the {@link ISynchronizationScope}
23  * interface for use by clients.
24  * <p>
25  * This class is not intended to be subclasses by clients.
26  *
27  * @see org.eclipse.core.resources.mapping.ResourceMapping
28  *
29  * @since 3.2
30  */

31 public class ResourceMappingScope extends AbstractResourceMappingScope {
32     
33     private ResourceMapping[] inputMappings;
34     private final Map mappingsToTraversals = Collections.synchronizedMap(new HashMap());
35     private boolean hasAdditionalMappings;
36     private boolean hasAdditionalResources;
37     private final CompoundResourceTraversal compoundTraversal = new CompoundResourceTraversal();
38     private final SynchronizationScopeManager manager;
39     
40     public ResourceMappingScope(ResourceMapping[] selectedMappings, SynchronizationScopeManager manager) {
41         inputMappings = selectedMappings;
42         this.manager = manager;
43     }
44     
45     /**
46      * Add the mapping and its traversals to the scope. This method should
47      * only be invoked during the scope building process.
48      * @param mapping the mapping being added to the scope
49      * @param traversals the traversals for that mapping
50      * @return the added traversals
51      */

52     public ResourceTraversal[] addMapping(ResourceMapping mapping, ResourceTraversal[] traversals) {
53         ResourceTraversal[] newTraversals = compoundTraversal.getUncoveredTraversals(traversals);
54         mappingsToTraversals.put(mapping, traversals);
55         compoundTraversal.addTraversals(traversals);
56         return newTraversals;
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.team.ui.mapping.IResourceMappingOperationScope#getInputMappings()
61      */

62     public ResourceMapping[] getInputMappings() {
63         return inputMappings;
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.team.ui.mapping.IResourceMappingOperationScope#getMappings()
68      */

69     public ResourceMapping[] getMappings() {
70         if (mappingsToTraversals.isEmpty())
71             return inputMappings;
72         return (ResourceMapping[]) mappingsToTraversals.keySet().toArray(new ResourceMapping[mappingsToTraversals.size()]);
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.team.ui.mapping.IResourceMappingOperationScope#getTraversals()
77      */

78     public ResourceTraversal[] getTraversals() {
79         return compoundTraversal.asTraversals();
80     }
81
82     /* (non-Javadoc)
83      * @see org.eclipse.team.ui.mapping.IResourceMappingOperationScope#getTraversals(org.eclipse.core.resources.mapping.ResourceMapping)
84      */

85     public ResourceTraversal[] getTraversals(ResourceMapping mapping) {
86         return (ResourceTraversal[])mappingsToTraversals.get(mapping);
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.team.ui.mapping.IResourceMappingOperationScope#hasAdditionalMappings()
91      */

92     public boolean hasAdditionalMappings() {
93         return hasAdditionalMappings;
94     }
95     
96     /**
97      * Set whether the scope has additional mappings to the input mappings.
98      * This method should only be invoked during the scope building process.
99      * @param hasAdditionalMappings whether the scope has additional mappings
100      */

101     public void setHasAdditionalMappings(boolean hasAdditionalMappings) {
102         this.hasAdditionalMappings = hasAdditionalMappings;
103     }
104
105     /**
106      * Set whether this scope has additional resources.
107      * This method should only be invoked during the scope building process.
108      * @param hasAdditionalResources whether the scope has additional resources
109      */

110     public void setHasAdditionalResources(boolean hasAdditionalResources) {
111         this.hasAdditionalResources = hasAdditionalResources;
112     }
113     
114     /* (non-Javadoc)
115      * @see org.eclipse.team.core.mapping.IResourceMappingScope#hasAdditonalResources()
116      */

117     public boolean hasAdditonalResources() {
118         return hasAdditionalResources;
119     }
120
121     public CompoundResourceTraversal getCompoundTraversal() {
122         return compoundTraversal;
123     }
124     
125     /* (non-Javadoc)
126      * @see org.eclipse.team.core.mapping.IResourceMappingScope#asInputScope()
127      */

128     public ISynchronizationScope asInputScope() {
129         return new ResourceMappingInputScope(this);
130     }
131
132     /* (non-Javadoc)
133      * @see org.eclipse.team.core.mapping.ISynchronizationScope#getProjects()
134      */

135     public IProject[] getProjects() {
136         ResourceMappingContext context = getContext();
137         if (context instanceof RemoteResourceMappingContext) {
138             RemoteResourceMappingContext rrmc = (RemoteResourceMappingContext) context;
139             return rrmc.getProjects();
140         }
141         return ResourcesPlugin.getWorkspace().getRoot().getProjects();
142     }
143
144     /* (non-Javadoc)
145      * @see org.eclipse.team.core.mapping.ISynchronizationScope#getContext()
146      */

147     public ResourceMappingContext getContext() {
148         return manager.getContext();
149     }
150
151     public void refresh(ResourceMapping[] mappings) {
152         manager.refresh(mappings);
153     }
154     
155     public void reset() {
156         mappingsToTraversals.clear();
157         compoundTraversal.clear();
158         hasAdditionalMappings = false;
159         hasAdditionalResources = false;
160     }
161 }
162
Popular Tags