diff options
author | Robin Stocker | 2013-04-25 20:12:01 +0000 |
---|---|---|
committer | Robin Stocker | 2013-04-25 20:12:01 +0000 |
commit | ffcec8c46e120f76d5238ed02c7cad811e05ea46 (patch) | |
tree | d5d4406d02063728c95952299da64cabf94329b0 | |
parent | 29f2ca999749bcebd028ef91ca5581c6b036c6ef (diff) | |
download | egit-ffcec8c46e120f76d5238ed02c7cad811e05ea46.tar.gz egit-ffcec8c46e120f76d5238ed02c7cad811e05ea46.tar.xz egit-ffcec8c46e120f76d5238ed02c7cad811e05ea46.zip |
Fix order of projects as returned by ResourceMapping
When executing a pull on a working set, WorkingSetResourceMapping
returns the projects in unpredictable order. This makes the listed
repositories in the result dialog look messy.
So sort the projects by name so that it corresponds to the navigator
sort order.
Change-Id: Ibd4500d7fb18fb773aadb1fe08d1a7bf83f29176
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java | 18 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java | 19 |
2 files changed, 31 insertions, 6 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java index 7ad8ea208f..4007972446 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org> - * Copyright (C) 2011, Robin Stocker <robin@nibor.org> + * Copyright (C) 2011, 2013 Robin Stocker <robin@nibor.org> * Copyright (C) 2011, Bernard Leach <leachbj@bouncycastle.org> * * All rights reserved. This program and the accompanying materials @@ -18,6 +18,8 @@ import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.common.CommandException; import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.util.Policy; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jgit.lib.Ref; import org.eclipse.ui.ISources; @@ -87,6 +89,20 @@ public class CommonUtils { }; /** + * Comparator for comparing {@link IResource} by the result of + * {@link IResource#getName()}. + */ + public static final Comparator<IResource> RESOURCE_NAME_COMPARATOR = new Comparator<IResource>() { + @SuppressWarnings("unchecked") + private final Comparator<String> stringComparator = Policy + .getComparator(); + + public int compare(IResource r1, IResource r2) { + return stringComparator.compare(r1.getName(), r2.getName()); + } + }; + + /** * Programatically run command based on it id and given selection * * @param commandId diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java index d751ddc959..1380d97589 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java @@ -4,7 +4,7 @@ * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> * Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org> - * Copyright (C) 2012, Robin Stocker <robin@nibor.org> + * Copyright (C) 2012, 2013 Robin Stocker <robin@nibor.org> * Copyright (C) 2012, François Rey <eclipse.org_@_francois_._rey_._name> * * All rights reserved. This program and the accompanying materials @@ -39,6 +39,7 @@ import org.eclipse.core.runtime.PlatformObject; import org.eclipse.egit.core.AdapterUtils; import org.eclipse.egit.core.project.RepositoryMapping; import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.internal.CommonUtils; import org.eclipse.egit.ui.internal.UIText; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.TextSelection; @@ -75,6 +76,7 @@ import org.eclipse.ui.ide.ResourceUtil; * A helper class for Team Actions on Git controlled projects */ abstract class RepositoryActionHandler extends AbstractHandler { + private IEvaluationContext evaluationContext; private IStructuredSelection mySelection; @@ -110,9 +112,17 @@ abstract class RepositoryActionHandler extends AbstractHandler { Set<IProject> ret = new LinkedHashSet<IProject>(); for (ResourceMapping mapping : (ResourceMapping[]) getSelectedAdaptables( selection, ResourceMapping.class)) { - IProject[] projects = mapping.getProjects(); - if (projects != null) - ret.addAll(Arrays.asList(projects)); + IProject[] mappedProjects = mapping.getProjects(); + if (mappedProjects != null && mappedProjects.length != 0) { + // Some mappings (WorkingSetResourceMapping) return the projects + // in unpredictable order. Sort them like the navigator to + // correspond to the order the user usually sees. + List<IProject> projects = new ArrayList<IProject>( + Arrays.asList(mappedProjects)); + Collections + .sort(projects, CommonUtils.RESOURCE_NAME_COMPARATOR); + ret.addAll(projects); + } } return ret; } @@ -722,5 +732,4 @@ abstract class RepositoryActionHandler extends AbstractHandler { this.path = path; } } - } |