Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-01-26 19:10:32 +0000
committerMichael Valenta2006-01-26 19:10:32 +0000
commit09c2df406e49707bab5d2ffc76b177b4b7e11a91 (patch)
tree40f946b17970f206c0a46ebb51f4b04bf1b9edd9
parent7091ddc69cba7e994ee1b50d36ca583a8060cc1f (diff)
downloadeclipse.platform.team-09c2df406e49707bab5d2ffc76b177b4b7e11a91.tar.gz
eclipse.platform.team-09c2df406e49707bab5d2ffc76b177b4b7e11a91.tar.xz
eclipse.platform.team-09c2df406e49707bab5d2ffc76b177b4b7e11a91.zip
Finished off support for scope refresh
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingScope.java13
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ISynchronizationScope.java4
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java122
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/CompoundResourceTraversal.java4
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java4
5 files changed, 105 insertions, 42 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingScope.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingScope.java
index ee8ad4b94..b7cb4b15d 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingScope.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingScope.java
@@ -37,6 +37,19 @@ import org.eclipse.team.core.mapping.provider.ScopeGenerator;
public interface IResourceMappingScope extends ISynchronizationScope {
/**
+ * Property change constant used to indicate that the mappings
+ * of the scope have changed. The input mappings of the scope
+ * do not change but it is possible that changes to resources
+ * will result in additional mappings in the scope due to
+ * relationships between models and the resources that contain them.
+ * A mapping propery change event may proceed a traversal change
+ * event if both properties have changed simultaneoulsy.
+ * The value associatd with the event will be an array of
+ * resource mappings (i.e. <code>ResourceMapping[]</code>)
+ */
+ public static final String MAPPINGS = "org.eclipse.team.core.traversalsChanged"; //$NON-NLS-1$
+
+ /**
* Return the array of mappings that acted as the input to the scope builder
* that was used to build this scope. This set usually come from a view
* selection but could come from another source. In most cases, clients will
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ISynchronizationScope.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ISynchronizationScope.java
index 8cddd66c6..3abd75d16 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ISynchronizationScope.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ISynchronizationScope.java
@@ -31,7 +31,9 @@ public interface ISynchronizationScope {
/**
* Property change constant used to indicate that the traversals
- * of the scope have changed.
+ * of the scope have changed. The value associated with the
+ * change event will be an array of traversals (i.e.
+ * <code>ResourceTraversal[]</code>
*/
public static final String TRAVERSALS = "org.eclipse.team.core.traversalsChanged"; //$NON-NLS-1$
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java
index 0d115433b..2288a0077 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java
@@ -58,6 +58,7 @@ import org.eclipse.team.internal.core.mapping.*;
*/
public class ScopeGenerator {
+ private static final int MAX_ITERATION = 10;
private final ResourceMappingContext context;
private final boolean consultModels;
@@ -91,24 +92,25 @@ public class ScopeGenerator {
ResourceMapping mapping = selectedMappings[i];
targetMappings.add(mapping);
}
- Set newResources;
+ IResource[] newResources;
boolean firstTime = true;
boolean hasAdditionalResources = false;
+ int count = 0;
do {
newResources = addMappingsToScope(scope, targetMappings,
Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
if (consultModels) {
- IResource[] adjusted = adjustNewResources(newResources);
+ IResource[] adjusted = adjustInputResources(newResources);
targetMappings = internalGetMappingsFromProviders(adjusted,
context,
Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
if (firstTime) {
firstTime = false;
} else if (!hasAdditionalResources) {
- hasAdditionalResources = !newResources.isEmpty();
+ hasAdditionalResources = newResources.length != 0;
}
}
- } while (consultModels & !newResources.isEmpty());
+ } while (consultModels & newResources.length != 0 && count++ < MAX_ITERATION);
setHasAdditionalMappings(scope, consultModels && hasAdditionalMappings(scope));
setHasAdditionalResources(scope, consultModels && hasAdditionalResources);
return scope;
@@ -136,48 +138,101 @@ public class ScopeGenerator {
private ResourceTraversal[] internalRefreshScope(IResourceMappingScope scope, ResourceMapping[] mappings, IProgressMonitor monitor) throws CoreException {
monitor.beginTask(null, 100 * mappings.length + 100);
+ ResourceMapping[] originalMappings = scope.getMappings();
ResourceTraversal[] originalTraversals = scope.getTraversals();
- Set newResources = new HashSet();
+ CompoundResourceTraversal refreshTraversals = new CompoundResourceTraversal();
+ boolean expanded = false;
for (int i = 0; i < mappings.length; i++) {
ResourceMapping mapping = mappings[i];
- ResourceTraversal[] oldTraversals = scope.getTraversals(mapping);
- // Only refresh mappings that are known to the scope
- if (oldTraversals != null) {
- ResourceTraversal[] newTraversals = mapping.getTraversals(context,
- Policy.subMonitorFor(monitor, 100));
- // Accumulate the new traversals
- IResource[] newOnes = addMappingToScope(scope, mapping, newTraversals);
- newResources.addAll(Arrays.asList(newOnes));
+ ResourceTraversal[] mappingTraversals = mapping.getTraversals(
+ context, Policy.subMonitorFor(monitor, 100));
+ refreshTraversals.addTraversals(mappingTraversals);
+ IResource[] uncovered = getUncoveredResources(scope, mappingTraversals);
+ if (uncovered.length > 0) {
+ expanded = true;
+ ResourceTraversal[] result = performExpandScope(scope, mapping, mappingTraversals, uncovered, monitor);
+ refreshTraversals.addTraversals(result);
}
}
- if (!newResources.isEmpty()) {
- addResourcesToScope(scope, (IResource[]) newResources.toArray(new IResource[newResources.size()]), Policy.subMonitorFor(monitor, 100));
+ if (scope.getMappings().length > originalMappings.length) {
+ fileMappingsChangedEvent(scope, originalMappings);
+ }
+ if (expanded) {
fireTraversalsChangedEvent(scope, originalTraversals);
}
monitor.done();
- return scope.getTraversals();
+ return refreshTraversals.asTraversals();
+ }
+
+ private ResourceTraversal[] performExpandScope(IResourceMappingScope scope,
+ ResourceMapping mapping, ResourceTraversal[] mappingTraversals,
+ IResource[] uncovered, IProgressMonitor monitor)
+ throws CoreException {
+ ResourceMapping ancestor = findAncestor(scope, mapping);
+ if (ancestor == null) {
+ uncovered = addMappingToScope(scope, mapping, mappingTraversals);
+ addResourcesToScope(scope, uncovered, monitor);
+ return mappingTraversals;
+ } else {
+ ResourceTraversal[] ancestorTraversals = ancestor.getTraversals(
+ context, Policy.subMonitorFor(monitor, 100));
+ uncovered = addMappingToScope(scope, ancestor, ancestorTraversals);
+ addResourcesToScope(scope, uncovered, monitor);
+ return ancestorTraversals;
+ }
+ }
+
+ private ResourceMapping findAncestor(IResourceMappingScope scope, ResourceMapping mapping) {
+ ResourceMapping[] mappings = scope.getMappings(mapping.getModelProviderId());
+ for (int i = 0; i < mappings.length; i++) {
+ ResourceMapping m = mappings[i];
+ if (m.contains(mapping)) {
+ return m;
+ }
+ }
+ return null;
+ }
+
+ private IResource[] getUncoveredResources(IResourceMappingScope scope, ResourceTraversal[] traversals) {
+ return ((ResourceMappingScope)scope).getCompoundTraversal().getUncoveredResources(traversals);
}
private void addResourcesToScope(IResourceMappingScope scope, IResource[] newResources, IProgressMonitor monitor) throws CoreException {
+ if (!consultModels)
+ return;
Set targetMappings;
+ int count = 0;
do {
- if (consultModels) {
- IResource[] adjusted = adjustInputResources(newResources);
- targetMappings = internalGetMappingsFromProviders(adjusted,
- context, Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
- addMappingsToScope(scope, targetMappings,
- Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
- // TODO: Need to iterate
- }
- } while (false /* consultModels & !moreNewResources.isEmpty() */);
+ IResource[] adjusted = adjustInputResources(newResources);
+ targetMappings = internalGetMappingsFromProviders(adjusted,
+ context, Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
+ newResources = addMappingsToScope(scope, targetMappings,
+ Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
+ } while (newResources.length != 0 && count++ < MAX_ITERATION);
+ if (!scope.hasAdditionalMappings()) {
+ setHasAdditionalMappings(scope, hasAdditionalMappings(scope));
+ }
+ if (!scope.hasAdditonalResources()) {
+ setHasAdditionalResources(scope, true);
+ }
}
/**
+ * Fire a mappings changed event to any listeners on the scope.
+ * The new mappings are obtained from the scope.
+ * @param scope the scope
+ * @param originalMappings the original mappings of the scope.
+ */
+ private void fileMappingsChangedEvent(IResourceMappingScope scope, ResourceMapping[] originalMappings) {
+ ((ResourceMappingScope)scope).fireMappingChangedEvent(originalMappings);
+ }
+
+ /**
* Fire a traversals changed event to any listeners on the scope.
* The new traversals are obtained from the scope.
* @param scope the scope
- * @param originalTraversals the original traversals on the scope.
+ * @param originalTraversals the original traversals of the scope.
*/
protected final void fireTraversalsChangedEvent(IResourceMappingScope scope, ResourceTraversal[] originalTraversals) {
((ResourceMappingScope)scope).fireTraversalsChangedEvent(originalTraversals);
@@ -238,7 +293,7 @@ public class ScopeGenerator {
return resources;
}
- private Set addMappingsToScope(IResourceMappingScope scope,
+ private IResource[] addMappingsToScope(IResourceMappingScope scope,
Set targetMappings,
IProgressMonitor monitor) throws CoreException {
Set newResources = new HashSet();
@@ -251,7 +306,7 @@ public class ScopeGenerator {
newResources.addAll(Arrays.asList(newOnes));
}
}
- return newResources;
+ return (IResource[]) newResources.toArray(new IResource[newResources.size()]);
}
/**
@@ -269,17 +324,6 @@ public class ScopeGenerator {
return ((ResourceMappingScope)scope).addMapping(mapping, traversals);
}
- /*
- * Give the subclass a chance to add resources to the set of affected
- * resources
- */
- private IResource[] adjustNewResources(Set newResources) {
- IResource[] resources = (IResource[]) newResources
- .toArray(new IResource[newResources.size()]);
- IResource[] adjusted = adjustInputResources(resources);
- return adjusted;
- }
-
private Set internalGetMappingsFromProviders(IResource[] resources,
ResourceMappingContext context,
IProgressMonitor monitor) throws CoreException {
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/CompoundResourceTraversal.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/CompoundResourceTraversal.java
index 36742db9a..35ca69bf9 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/CompoundResourceTraversal.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/CompoundResourceTraversal.java
@@ -173,9 +173,9 @@ public class CompoundResourceTraversal {
}
/**
- * Return the resource contained in the given traversals that are not covered by this traversal
+ * Return the resources contained in the given traversals that are not covered by this traversal
* @param traversals the traversals being testes
- * @return the resource contained in the given traversals that are not covered by this traversal
+ * @return the resources contained in the given traversals that are not covered by this traversal
*/
public IResource[] getUncoveredResources(ResourceTraversal[] traversals) {
CompoundResourceTraversal newTraversals = new CompoundResourceTraversal();
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java
index ba9ace7bc..add1a91a8 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java
@@ -168,4 +168,8 @@ public class ResourceMappingScope extends AbstractResourceMappingScope {
public CompoundResourceTraversal getCompoundTraversal() {
return compoundTraversal;
}
+
+ public void fireMappingChangedEvent(ResourceMapping[] originalMappings) {
+ firePropertyChangedEvent(new PropertyChangeEvent(this, IResourceMappingScope.MAPPINGS, originalMappings, getMappings()));
+ }
}

Back to the top