Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-07-19 17:52:17 +0000
committerMichael Valenta2007-07-19 17:52:17 +0000
commitf03abe7d51a58a785c7ebe3c7cd894db3460f437 (patch)
tree24463d239857c2f61825ad5a2e180f3adcf7741f /bundles
parent6c41530260b0a9b7f10a69d1f6b1c2d262c85445 (diff)
downloadeclipse.platform.team-f03abe7d51a58a785c7ebe3c7cd894db3460f437.tar.gz
eclipse.platform.team-f03abe7d51a58a785c7ebe3c7cd894db3460f437.tar.xz
eclipse.platform.team-f03abe7d51a58a785c7ebe3c7cd894db3460f437.zip
Bug 196475 [Repo View] Ordering in the CVS Repositories view
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java4
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties5
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesSortingActionGroup.java143
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java58
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryComparator.java63
5 files changed, 261 insertions, 12 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
index 707fb935a..672119c03 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
@@ -96,6 +96,10 @@ public class CVSUIMessages extends NLS {
public static String RemoveRootAction_RepositoryRemovalDialogMessageSingle;
public static String RemoveRootAction_RepositoryRemovalDialogTitle;
public static String ReplaceWithLatestRevisionAction_error;
+ public static String RepositoriesSortingActionGroup_host;
+ public static String RepositoriesSortingActionGroup_label;
+ public static String RepositoriesSortingActionGroup_location;
+ public static String RepositoriesSortingActionGroup_sortBy;
public static String ShowAnnotationOperation_QDAnnotateMessage;
public static String ShowAnnotationOperation_QDAnnotateTitle;
public static String SyncAction_1;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
index e42ec2303..e3eeb1805 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
@@ -262,7 +262,6 @@ CVSRepositoryLocationPropertySource_port=Port
CVSRepositoryLocationPropertySource_root=Repository path
CVSRepositoryLocationPropertySource_method=Connection method
-
CVSParticipant_0=Remote File ({0} - {1})
CVSParticipant_1=Common Ancestor ({0} - {1})
CVSParticipant_2=C&VS
@@ -501,9 +500,13 @@ RepositoriesView_editWorkingSet=Edit Active Working Set...
RepositoriesView_workingSetMenuItem={0} {1}
RepositoriesView_collapseAll=Collapse All
RepositoriesView_collapseAllTooltip=Collapse All
+RepositoriesSortingActionGroup_host=&Host
RepositoriesView_NItemsSelected={0} items selected
RepositoriesView_OneItemSelected=1 item selected
RepositoriesView_ResourceInRepository={0} in {1}
+RepositoriesSortingActionGroup_label=&Label
+RepositoriesSortingActionGroup_location=L&ocation
+RepositoriesSortingActionGroup_sortBy=Sort By
RepositoriesView_CannotGetRevision=Cannot get revision
RemoteViewPart_workingSetToolTip=Working Set: {0}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesSortingActionGroup.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesSortingActionGroup.java
new file mode 100644
index 000000000..7deed3b97
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesSortingActionGroup.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.repo;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.actions.ActionGroup;
+
+public class RepositoriesSortingActionGroup extends ActionGroup {
+ // Sorting actions
+ private Action labelSortingAction;
+ private Action locationSortingAction;
+ private Action hostSortingAction;
+
+ /**
+ * Current comparator set.
+ */
+ private RepositoryComparator comparator;
+ private IPropertyChangeListener comparatorUpdater;
+
+ /* package */static final RepositoryComparator orderByLabelComparator = new RepositoryComparator(/* default */);
+ /* package */static final RepositoryComparator orderByLocationComparator = new RepositoryComparator(
+ RepositoryComparator.ORDER_LOCATION);
+ /* package */static final RepositoryComparator orderByHostComparator = new RepositoryComparator(
+ RepositoryComparator.ORDER_HOST);
+
+ /**
+ * Indicates if comparator was changed
+ */
+ public static final String CHANGE_COMPARATOR = "changeComparator"; //$NON-NLS-1$
+
+ private static final String REPOSITORIES_SORTING_ACTION_GROUP = "repositoriesSortingActionGroup"; //$NON-NLS-1$
+
+ public RepositoriesSortingActionGroup(Shell shell,
+ IPropertyChangeListener comparatorUpdater) {
+ Assert.isNotNull(shell);
+
+ this.comparatorUpdater = comparatorUpdater;
+ labelSortingAction = new Action(
+ CVSUIMessages.RepositoriesSortingActionGroup_label, Action.AS_RADIO_BUTTON) {
+ public void run() {
+ if (labelSortingAction.isChecked())
+ setComparator(orderByLabelComparator);
+ }
+ };
+ locationSortingAction = new Action(
+ CVSUIMessages.RepositoriesSortingActionGroup_location,
+ Action.AS_RADIO_BUTTON) {
+ public void run() {
+ if (locationSortingAction.isChecked())
+ setComparator(orderByLocationComparator);
+ }
+ };
+ hostSortingAction = new Action(CVSUIMessages.RepositoriesSortingActionGroup_host,
+ Action.AS_RADIO_BUTTON) {
+ public void run() {
+ if (hostSortingAction.isChecked())
+ setComparator(orderByHostComparator);
+ }
+ };
+ // set sorting by label as default
+ setComparator(orderByLabelComparator);
+ labelSortingAction.setChecked(true);
+ }
+
+ /* package */void setComparator(RepositoryComparator newComparator) {
+ RepositoryComparator oldComparator = this.comparator;
+ this.comparator = newComparator;
+ firePropertyChange(newComparator, oldComparator);
+ }
+
+ private void firePropertyChange(RepositoryComparator newComparator,
+ RepositoryComparator oldComparator) {
+ // Update viewer
+ if (comparatorUpdater != null) {
+ comparatorUpdater.propertyChange(new PropertyChangeEvent(this,
+ CHANGE_COMPARATOR, oldComparator, newComparator));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ IMenuManager menuManager = actionBars.getMenuManager();
+
+ if (menuManager.find(IWorkbenchActionConstants.MB_ADDITIONS) != null)
+ menuManager.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS,
+ new Separator(REPOSITORIES_SORTING_ACTION_GROUP));
+ else
+ menuManager.add(new Separator(REPOSITORIES_SORTING_ACTION_GROUP));
+
+ IMenuManager sortSubmenu = new MenuManager(
+ CVSUIMessages.RepositoriesSortingActionGroup_sortBy);
+ menuManager.appendToGroup(REPOSITORIES_SORTING_ACTION_GROUP,
+ sortSubmenu);
+ sortSubmenu.add(labelSortingAction);
+ sortSubmenu.add(locationSortingAction);
+ sortSubmenu.add(hostSortingAction);
+ }
+
+ public void setSelectedComparator(String selectedComparator) {
+
+ //uncheck all
+ labelSortingAction.setChecked(false);
+ locationSortingAction.setChecked(false);
+ hostSortingAction.setChecked(false);
+
+ try {
+ switch (Integer.parseInt(selectedComparator)) {
+ case RepositoryComparator.ORDER_LOCATION:
+ locationSortingAction.setChecked(true);
+ firePropertyChange(orderByLocationComparator, null);
+ return;
+ case RepositoryComparator.ORDER_HOST:
+ hostSortingAction.setChecked(true);
+ firePropertyChange(orderByHostComparator, null);
+ return;
+ }
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ // default comparator
+ labelSortingAction.setChecked(true);
+ firePropertyChange(orderByLabelComparator, null);
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java
index a859bb908..6ad9d6ca5 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java
@@ -15,6 +15,9 @@ import java.util.Properties;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.*;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.osgi.util.NLS;
@@ -56,6 +59,11 @@ public class RepositoriesView extends RemoteViewPart {
private RemoveRootAction removeRootAction;
private RemoveDateTagAction removeDateTagAction;
+ private RepositoriesSortingActionGroup repositoriesSortingActionGroup;
+ private IDialogSettings dialogSettings;
+ private static final String SELECTED_COMPARATOR = "selectedComparator"; //$NON-NLS-1$
+ private String savedComparator;
+
IRepositoryListener listener = new IRepositoryListener() {
public void repositoryAdded(final ICVSRepositoryLocation root) {
getViewer().getControl().getDisplay().asyncExec(new Runnable() {
@@ -132,6 +140,12 @@ public class RepositoriesView extends RemoteViewPart {
*/
public RepositoriesView() {
super(VIEW_ID);
+ IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings();
+ dialogSettings = workbenchSettings.getSection(VIEW_ID);
+ if (dialogSettings == null) {
+ dialogSettings = workbenchSettings.addNewSection(VIEW_ID);
+ }
+ savedComparator = dialogSettings.get(SELECTED_COMPARATOR);
}
/**
@@ -205,8 +219,48 @@ public class RepositoriesView extends RemoteViewPart {
IActionBars bars = getViewSite().getActionBars();
bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), removeAction);
+ // Working Set action group
+ IPropertyChangeListener comparatorUpdater = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ if (RepositoriesSortingActionGroup.CHANGE_COMPARATOR
+ .equals(property)) {
+ Object newValue = event.getNewValue();
+ getViewer().setComparator((ViewerComparator) newValue);
+ saveSelectedComparator(((RepositoryComparator) newValue).getOrder()+""); //$NON-NLS-1$
+ }
+ }
+
+ };
+ setActionGroup(new RepositoriesSortingActionGroup(shell, comparatorUpdater));
+ getRepositoriesSortingActionGroup().setSelectedComparator(savedComparator);
+
super.contributeActions();
}
+
+ private void saveSelectedComparator(String selectedComparator) {
+ if (dialogSettings != null) {
+ dialogSettings.put(SELECTED_COMPARATOR, selectedComparator);
+ }
+ }
+
+ /**
+ * Returns the action group.
+ *
+ * @return the action group
+ */
+ private RepositoriesSortingActionGroup getRepositoriesSortingActionGroup() {
+ return repositoriesSortingActionGroup;
+ }
+
+ /**
+ * Sets the action group.
+ *
+ * @param actionGroup the action group
+ */
+ private void setActionGroup(RepositoriesSortingActionGroup actionGroup) {
+ this.repositoriesSortingActionGroup = actionGroup;
+ }
/**
* Method includeEclipseConnection.
@@ -250,6 +304,7 @@ public class RepositoriesView extends RemoteViewPart {
public void createPartControl(Composite parent) {
super.createPartControl(parent);
CVSUIPlugin.getPlugin().getRepositoryManager().addRepositoryListener(listener);
+ getRepositoriesSortingActionGroup().fillActionBars(getViewSite().getActionBars());
}
/*
@@ -257,6 +312,9 @@ public class RepositoriesView extends RemoteViewPart {
*/
public void dispose() {
CVSUIPlugin.getPlugin().getRepositoryManager().removeRepositoryListener(listener);
+ if (getRepositoriesSortingActionGroup() != null) {
+ getRepositoriesSortingActionGroup().dispose();
+ }
super.dispose();
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryComparator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryComparator.java
index 178c91fd2..a972a2f07 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryComparator.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryComparator.java
@@ -11,19 +11,37 @@
package org.eclipse.team.internal.ccvs.ui.repo;
-import org.eclipse.jface.viewers.*;
-import org.eclipse.team.internal.ccvs.core.CVSTag;
-import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
-import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
-import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
-import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
-import org.eclipse.team.internal.ccvs.ui.model.BranchCategory;
-import org.eclipse.team.internal.ccvs.ui.model.CVSTagElement;
-import org.eclipse.team.internal.ccvs.ui.model.DateTagCategory;
-import org.eclipse.team.internal.ccvs.ui.model.RemoteModule;
-import org.eclipse.team.internal.ccvs.ui.model.VersionCategory;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.team.internal.ccvs.ui.model.*;
public class RepositoryComparator extends ViewerComparator {
+
+ /**
+ * Default sorting order, by label.
+ */
+ public static final int ORDER_DEFAULT = 0;
+
+ public static final int ORDER_LOCATION = 1;
+
+ public static final int ORDER_HOST = 2;
+
+ private int order = ORDER_DEFAULT;
+
+ public RepositoryComparator(int order) {
+ super();
+ this.order = order;
+ }
+
+ public RepositoryComparator() {
+ super();
+ }
+
+ public int getOrder() {
+ return order;
+ }
+
public int category(Object element) {
if (element instanceof ICVSRemoteFolder) {
if (((ICVSRemoteFolder)element).isDefinedModule()) {
@@ -98,6 +116,29 @@ public class RepositoryComparator extends ViewerComparator {
return ((ICVSRepositoryLocation)o1).getLocation(false).compareTo(((ICVSRepositoryLocation)o2).getLocation(false));
}
+ if (o1 instanceof RepositoryRoot && o2 instanceof RepositoryRoot) {
+ RepositoryRoot rr1 = (RepositoryRoot) o1;
+ RepositoryRoot rr2 = (RepositoryRoot) o2;
+
+ // use repository location strings to compare RepositoryRoots
+ ICVSRepositoryLocation rl1 = rr1.getRoot();
+ ICVSRepositoryLocation rl2 = rr2.getRoot();
+
+ switch (order) {
+ case ORDER_DEFAULT:
+ // for default order use super.compare
+ break;
+ case ORDER_HOST:
+ if (rl1.getHost().compareTo(rl2.getHost()) != 0)
+ return rl1.getHost().compareTo(rl2.getHost());
+ // no break
+ // add other cases here
+ case ORDER_LOCATION:
+ default:
+ return (rl1.getLocation(false).compareTo(rl2.getLocation(false)));
+ }
+ }
+
return super.compare(viewer, o1, o2);
}

Back to the top