diff options
author | Michael Valenta | 2006-01-07 03:48:56 +0000 |
---|---|---|
committer | Michael Valenta | 2006-01-07 03:48:56 +0000 |
commit | 4aae99ca7c866cbdaf99b8c15704ad46236e751f (patch) | |
tree | b1ba3151afe3285c59edba431837bf7ac68c8d9f | |
parent | b4547d3d6ad96ad109c3bd9479706fc1bf40088e (diff) | |
download | eclipse.platform.team-4aae99ca7c866cbdaf99b8c15704ad46236e751f.tar.gz eclipse.platform.team-4aae99ca7c866cbdaf99b8c15704ad46236e751f.tar.xz eclipse.platform.team-4aae99ca7c866cbdaf99b8c15704ad46236e751f.zip |
Bug 119921 [Mapping] Improve heterogeneous input promting
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java | 103 |
1 files changed, 98 insertions, 5 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java index eccf28c4e..da80dbff6 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java @@ -11,12 +11,16 @@ package org.eclipse.team.ui.operations; import java.lang.reflect.InvocationTargetException; +import java.util.*; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.mapping.*; import org.eclipse.core.runtime.*; import org.eclipse.jface.window.Window; -import org.eclipse.team.core.mapping.*; +import org.eclipse.team.core.mapping.IResourceMappingScope; +import org.eclipse.team.core.mapping.ISynchronizationContext; import org.eclipse.team.core.mapping.provider.ScopeGenerator; +import org.eclipse.team.internal.core.mapping.ResourceMappingScope; import org.eclipse.team.internal.ui.TeamUIMessages; import org.eclipse.team.internal.ui.dialogs.AdditionalMappingsDialog; import org.eclipse.ui.IWorkbenchPart; @@ -87,7 +91,13 @@ public abstract class ResourceMappingOperation extends ModelProviderOperation { /** * Adjust the input of the operation according to the selected - * resource mappings and the set of interested participants + * resource mappings and the set of interested participants. This method + * will prompt the user in the following cases: + * <ol> + * <li>The scope contains additional resources than those in the input. + * <li>The scope has additional mappings from a model in the input + * <li>The input contains elements from multiple models + * </ol> * @param monitor a progress monitor */ protected void buildScope(IProgressMonitor monitor) throws InvocationTargetException { @@ -124,9 +134,38 @@ public abstract class ResourceMappingOperation extends ModelProviderOperation { if (prompt) promptForInputChange(monitor); } else { - // The input had mixed mappings so just prompt with the additional mappings - // TODO: Perhaps we could do better (bug 119921) - promptForInputChange(monitor); + // We need to prompt if there are additional mappings from an input + // provider whose traversals overlap those of the input mappings. + boolean prompt = false; + for (int i = 0; i < inputModelProviders.length; i++) { + ModelProvider provider = inputModelProviders[i]; + String id = provider.getDescriptor().getId(); + ResourceMapping[] inputMappings = inputScope.getMappings(id); + ResourceMapping[] scopeMappings = scope.getMappings(id); + if (inputMappings.length != scopeMappings.length) { + // There are more mappings for this provider. + // We need to see if any of the new ones overlap the old ones. + for (int j = 0; j < scopeMappings.length; j++) { + ResourceMapping mapping = scopeMappings[j]; + ResourceTraversal[] inputTraversals = inputScope.getTraversals(mapping); + if (inputTraversals == null) { + // This mapping was not in the input. + // We need to prompt if the traversal for this mapping overlaps with + // the input mappings for the model provider + // TODO could check for project overlap first + ResourceTraversal[] scopeTraversals = scope.getTraversals(mapping); + ResourceTraversal[] inputModelTraversals = getTraversals(inputScope, inputMappings); + if (overlaps(scopeTraversals, inputModelTraversals)) { + prompt = true; + break; + } + } + } + } + } + + if (prompt) + promptForInputChange(monitor); } } } catch (CoreException e) { @@ -134,6 +173,60 @@ public abstract class ResourceMappingOperation extends ModelProviderOperation { } } + private boolean overlaps(ResourceTraversal[] scopeTraversals, ResourceTraversal[] inputModelTraversals) { + for (int i = 0; i < inputModelTraversals.length; i++) { + ResourceTraversal inputTraversal = inputModelTraversals[i]; + for (int j = 0; j < scopeTraversals.length; j++) { + ResourceTraversal scopeTraversal = scopeTraversals[j]; + if (overlaps(inputTraversal, scopeTraversal)) { + return true; + } + } + } + return false; + } + + private boolean overlaps(ResourceTraversal inputTraversal, ResourceTraversal scopeTraversal) { + IResource[] inputRoots = inputTraversal.getResources(); + IResource[] scopeRoots = scopeTraversal.getResources(); + for (int i = 0; i < scopeRoots.length; i++) { + IResource scopeResource = scopeRoots[i]; + for (int j = 0; j < inputRoots.length; j++) { + IResource inputResource = inputRoots[j]; + if (overlaps(scopeResource, scopeTraversal.getDepth(), inputResource, inputTraversal.getDepth())) + return true; + } + } + return false; + } + + private boolean overlaps(IResource scopeResource, int scopeDepth, IResource inputResource, int inputDepth) { + if (scopeResource.equals(inputResource)) + return true; + if (scopeDepth == IResource.DEPTH_INFINITE && scopeResource.getFullPath().isPrefixOf(inputResource.getFullPath())) { + return true; + } + if (scopeDepth == IResource.DEPTH_ONE && scopeResource.equals(inputResource.getParent())) { + return true; + } + if (inputDepth == IResource.DEPTH_INFINITE && inputResource.getFullPath().isPrefixOf(scopeResource.getFullPath())) { + return true; + } + if (inputDepth == IResource.DEPTH_ONE && inputResource.equals(scopeResource.getParent())) { + return true; + } + return false; + } + + private ResourceTraversal[] getTraversals(IResourceMappingScope inputScope, ResourceMapping[] inputMappings) { + List result = new ArrayList(); + for (int i = 0; i < inputMappings.length; i++) { + ResourceMapping mapping = inputMappings[i]; + result.addAll(Arrays.asList(inputScope.getTraversals(mapping))); + } + return ResourceMappingScope.combineTraversals((ResourceTraversal[]) result.toArray(new ResourceTraversal[result.size()])); + } + private boolean isIndependantModel(String modelProviderId, String id) { IModelProviderDescriptor desc1 = ModelProvider.getModelProviderDescriptor(modelProviderId); IModelProviderDescriptor desc2 = ModelProvider.getModelProviderDescriptor(id); |