diff options
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CVSActionSelectionProperties.java')
-rw-r--r-- | bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CVSActionSelectionProperties.java | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CVSActionSelectionProperties.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CVSActionSelectionProperties.java index efb33606d..15d44ad51 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CVSActionSelectionProperties.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CVSActionSelectionProperties.java @@ -26,127 +26,127 @@ import org.eclipse.team.internal.ui.Utils; * This class represents a selection for a set of CVS actions. */ public class CVSActionSelectionProperties { - - // Use a weak hash map so that the properties ae collected when the selection is no longer referenced + + // Use a weak hash map so that the properties ae collected when the selection is no longer referenced private static Map<IStructuredSelection, CVSActionSelectionProperties> selectionProperties = new WeakHashMap<>(); - - private Object[] selection; + + private Object[] selection; private Map<String, Object> properties = new HashMap<>(); - - private static final String SELECTED_RESOURCES = "selectedResources"; //$NON-NLS-1$ - private static final String NONOVERLAPPING_SELECTED_RESOURCES = "nonoverlappingSelectedResources"; //$NON-NLS-1$ - private static final String CVS_RESOURCE_MAP = "cvsResourceMap"; //$NON-NLS-1$ - - public static CVSActionSelectionProperties getProperties(IStructuredSelection selection) { - if (selection == null) return null; - CVSActionSelectionProperties props = selectionProperties.get(selection); - if (props == null) { - props = new CVSActionSelectionProperties(selection); - selectionProperties.put(selection, props); - } - return props; - } - - public CVSActionSelectionProperties(IStructuredSelection selection) { - // Copy the selection so that the WeakHashMap will not think the seleciton used for the key is still in use - this.selection = selection.toArray(); - } + + private static final String SELECTED_RESOURCES = "selectedResources"; //$NON-NLS-1$ + private static final String NONOVERLAPPING_SELECTED_RESOURCES = "nonoverlappingSelectedResources"; //$NON-NLS-1$ + private static final String CVS_RESOURCE_MAP = "cvsResourceMap"; //$NON-NLS-1$ + + public static CVSActionSelectionProperties getProperties(IStructuredSelection selection) { + if (selection == null) return null; + CVSActionSelectionProperties props = selectionProperties.get(selection); + if (props == null) { + props = new CVSActionSelectionProperties(selection); + selectionProperties.put(selection, props); + } + return props; + } + + public CVSActionSelectionProperties(IStructuredSelection selection) { + // Copy the selection so that the WeakHashMap will not think the seleciton used for the key is still in use + this.selection = selection.toArray(); + } - public void put(String key, Object value) { - properties.put(key, value); - } - - public Object get(String key) { - return properties.get(key); - } - - public IResource[] getAllSelectedResources() { - IResource[] resources = (IResource[])get(SELECTED_RESOURCES); - if (resources == null) { - resources = getResources(selection); - put(SELECTED_RESOURCES, resources); - } - return resources; - } + public void put(String key, Object value) { + properties.put(key, value); + } + + public Object get(String key) { + return properties.get(key); + } + + public IResource[] getAllSelectedResources() { + IResource[] resources = (IResource[])get(SELECTED_RESOURCES); + if (resources == null) { + resources = getResources(selection); + put(SELECTED_RESOURCES, resources); + } + return resources; + } - /* - * This method gets the resources from the given objects. - * It does so in a manner that is consistent with how the workbench does it. - * Tha is, it first uses IContributionResourceAdapter, then IResource, - * then ResourceMapping. - */ - private IResource[] getResources(Object[] objects) { - return Utils.getContributedResources(objects); - } - - public IResource[] getNonoverlappingSelectedResources() { - IResource[] resources = (IResource[])get(NONOVERLAPPING_SELECTED_RESOURCES); - if (resources == null) { - resources = getNonOverlapping(getAllSelectedResources()); - put (NONOVERLAPPING_SELECTED_RESOURCES, resources); - } - return resources; - } - - public ICVSResource getCVSResourceFor(IResource resource) { - Map map = (Map)get(CVS_RESOURCE_MAP); - if (map == null) { - map = new HashMap(); - put(CVS_RESOURCE_MAP, map); - } - ICVSResource cvsResource = (ICVSResource)map.get(resource); - if (cvsResource == null) { - cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); - map.put(resource, cvsResource); - } - return cvsResource; - } - - /** - * Method getNonOverlapping ensures that a resource is not covered more than once. - * @param resources - * @return IResource[] - */ - public static IResource[] getNonOverlapping(IResource[] resources) { - if (resources == null || resources.length == 0 || resources.length == 1) { - return resources; - } - // Sort the resources so the shortest paths are first + /* + * This method gets the resources from the given objects. + * It does so in a manner that is consistent with how the workbench does it. + * Tha is, it first uses IContributionResourceAdapter, then IResource, + * then ResourceMapping. + */ + private IResource[] getResources(Object[] objects) { + return Utils.getContributedResources(objects); + } + + public IResource[] getNonoverlappingSelectedResources() { + IResource[] resources = (IResource[])get(NONOVERLAPPING_SELECTED_RESOURCES); + if (resources == null) { + resources = getNonOverlapping(getAllSelectedResources()); + put (NONOVERLAPPING_SELECTED_RESOURCES, resources); + } + return resources; + } + + public ICVSResource getCVSResourceFor(IResource resource) { + Map map = (Map)get(CVS_RESOURCE_MAP); + if (map == null) { + map = new HashMap(); + put(CVS_RESOURCE_MAP, map); + } + ICVSResource cvsResource = (ICVSResource)map.get(resource); + if (cvsResource == null) { + cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); + map.put(resource, cvsResource); + } + return cvsResource; + } + + /** + * Method getNonOverlapping ensures that a resource is not covered more than once. + * @param resources + * @return IResource[] + */ + public static IResource[] getNonOverlapping(IResource[] resources) { + if (resources == null || resources.length == 0 || resources.length == 1) { + return resources; + } + // Sort the resources so the shortest paths are first List<IResource> sorted = new ArrayList<>(); - sorted.addAll(Arrays.asList(resources)); + sorted.addAll(Arrays.asList(resources)); Collections.sort(sorted, new Comparator<IResource>() { - @Override + @Override public int compare(IResource resource0, IResource resource1) { - return resource0.getFullPath().segmentCount() - resource1.getFullPath().segmentCount(); - } - @Override + return resource0.getFullPath().segmentCount() - resource1.getFullPath().segmentCount(); + } + @Override public boolean equals(Object arg0) { - return false; - } - }); - // Collect all non-overlapping resources + return false; + } + }); + // Collect all non-overlapping resources List<IPath> coveredPaths = new ArrayList<>(); - for (Iterator iter = sorted.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - IPath resourceFullPath = resource.getFullPath(); - boolean covered = false; - for (Iterator it = coveredPaths.iterator(); it.hasNext();) { - IPath path = (IPath) it.next(); - if(path.isPrefixOf(resourceFullPath)) { - covered = true; - } - } - if (covered) { - // if the resource is covered by a parent, remove it - iter.remove(); - } else { - // if the resource is a non-covered folder, add it to the covered paths - if (resource.getType() == IResource.FOLDER) { - coveredPaths.add(resource.getFullPath()); - } - } - } - return sorted.toArray(new IResource[sorted.size()]); - } - + for (Iterator iter = sorted.iterator(); iter.hasNext();) { + IResource resource = (IResource) iter.next(); + IPath resourceFullPath = resource.getFullPath(); + boolean covered = false; + for (Iterator it = coveredPaths.iterator(); it.hasNext();) { + IPath path = (IPath) it.next(); + if(path.isPrefixOf(resourceFullPath)) { + covered = true; + } + } + if (covered) { + // if the resource is covered by a parent, remove it + iter.remove(); + } else { + // if the resource is a non-covered folder, add it to the covered paths + if (resource.getType() == IResource.FOLDER) { + coveredPaths.add(resource.getFullPath()); + } + } + } + return sorted.toArray(new IResource[sorted.size()]); + } + } |