Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-07-31 13:47:27 +0000
committerMichael Valenta2007-07-31 13:47:27 +0000
commitadf8bf7074eae06960266267af031156e0c5cb20 (patch)
tree196b1c7605f791f29131d732f3e58cb1247e8728 /bundles
parentc6571cf5e96252143c89105a89b7bd0eb574e9a8 (diff)
downloadeclipse.platform.team-adf8bf7074eae06960266267af031156e0c5cb20.tar.gz
eclipse.platform.team-adf8bf7074eae06960266267af031156e0c5cb20.tar.xz
eclipse.platform.team-adf8bf7074eae06960266267af031156e0c5cb20.zip
Bug 197166 [Repo View] Ascending/descending sorting order in the repo view
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java1
-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.java68
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoriesView.java33
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryComparator.java69
5 files changed, 123 insertions, 53 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 672119c03..2850be0f2 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
@@ -100,6 +100,7 @@ public class CVSUIMessages extends NLS {
public static String RepositoriesSortingActionGroup_label;
public static String RepositoriesSortingActionGroup_location;
public static String RepositoriesSortingActionGroup_sortBy;
+ public static String RepositoriesSortingActionGroup_descending;
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 df3cc94cc..4c315468e 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
@@ -500,13 +500,14 @@ 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_sortBy=Sort By
RepositoriesSortingActionGroup_label=&Label
+RepositoriesSortingActionGroup_host=&Host
RepositoriesSortingActionGroup_location=L&ocation
-RepositoriesSortingActionGroup_sortBy=Sort By
+RepositoriesSortingActionGroup_descending=D&escending
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
index 7deed3b97..9895697ad 100644
--- 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
@@ -25,6 +25,8 @@ public class RepositoriesSortingActionGroup extends ActionGroup {
private Action labelSortingAction;
private Action locationSortingAction;
private Action hostSortingAction;
+ // action for switching between asc/desc sorting order
+ private Action reverseSortingOrderAction;
/**
* Current comparator set.
@@ -51,7 +53,8 @@ public class RepositoriesSortingActionGroup extends ActionGroup {
this.comparatorUpdater = comparatorUpdater;
labelSortingAction = new Action(
- CVSUIMessages.RepositoriesSortingActionGroup_label, Action.AS_RADIO_BUTTON) {
+ CVSUIMessages.RepositoriesSortingActionGroup_label,
+ Action.AS_RADIO_BUTTON) {
public void run() {
if (labelSortingAction.isChecked())
setComparator(orderByLabelComparator);
@@ -65,24 +68,44 @@ public class RepositoriesSortingActionGroup extends ActionGroup {
setComparator(orderByLocationComparator);
}
};
- hostSortingAction = new Action(CVSUIMessages.RepositoriesSortingActionGroup_host,
+ hostSortingAction = new Action(
+ CVSUIMessages.RepositoriesSortingActionGroup_host,
Action.AS_RADIO_BUTTON) {
public void run() {
if (hostSortingAction.isChecked())
setComparator(orderByHostComparator);
}
};
+ reverseSortingOrderAction = new Action(
+ CVSUIMessages.RepositoriesSortingActionGroup_descending,
+ Action.AS_CHECK_BOX) {
+ public void run() {
+ switchOrder(comparator);
+ }
+ };
// set sorting by label as default
- setComparator(orderByLabelComparator);
+ setSelectedComparator(orderByLabelComparator);
labelSortingAction.setChecked(true);
+ reverseSortingOrderAction.setChecked(!orderByLabelComparator.isAscending());
}
/* package */void setComparator(RepositoryComparator newComparator) {
RepositoryComparator oldComparator = this.comparator;
+ // preserve sorting order
+ if (oldComparator != null)
+ newComparator.setAscending(oldComparator.isAscending());
this.comparator = newComparator;
firePropertyChange(newComparator, oldComparator);
}
+ private void switchOrder(RepositoryComparator currentComparator) {
+ RepositoryComparator oldComparator = this.comparator;
+ RepositoryComparator switchedComparator = currentComparator
+ .getReversedComparator();
+ this.comparator = switchedComparator;
+ firePropertyChange(switchedComparator, oldComparator);
+ }
+
private void firePropertyChange(RepositoryComparator newComparator,
RepositoryComparator oldComparator) {
// Update viewer
@@ -113,31 +136,22 @@ public class RepositoriesSortingActionGroup extends ActionGroup {
sortSubmenu.add(labelSortingAction);
sortSubmenu.add(locationSortingAction);
sortSubmenu.add(hostSortingAction);
+ sortSubmenu.add(new Separator());
+ sortSubmenu.add(reverseSortingOrderAction);
}
- 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);
+ public void setSelectedComparator(RepositoryComparator selectedComparator) {
+ this.comparator = selectedComparator;
+
+ labelSortingAction
+ .setChecked(selectedComparator.getOrderBy() == RepositoryComparator.ORDER_DEFAULT);
+ locationSortingAction
+ .setChecked(selectedComparator.getOrderBy() == RepositoryComparator.ORDER_LOCATION);
+ hostSortingAction
+ .setChecked(selectedComparator.getOrderBy() == RepositoryComparator.ORDER_HOST);
+
+ reverseSortingOrderAction.setChecked(!selectedComparator.isAscending());
+
+ firePropertyChange(comparator, 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 6ad9d6ca5..06b7ae543 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
@@ -61,8 +61,9 @@ public class RepositoriesView extends RemoteViewPart {
private RepositoriesSortingActionGroup repositoriesSortingActionGroup;
private IDialogSettings dialogSettings;
- private static final String SELECTED_COMPARATOR = "selectedComparator"; //$NON-NLS-1$
- private String savedComparator;
+ private static final String SELECTED_ORDER_BY = "selectedOrderBy"; //$NON-NLS-1$
+ private static final String SELECTED_SORTING_ORDER = "selectedSortingOrder"; //$NON-NLS-1$
+ private RepositoryComparator savedComparator = RepositoriesSortingActionGroup.orderByLabelComparator;
IRepositoryListener listener = new IRepositoryListener() {
public void repositoryAdded(final ICVSRepositoryLocation root) {
@@ -133,10 +134,9 @@ public class RepositoriesView extends RemoteViewPart {
}
RepositoryDragSourceListener repositoryDragSourceListener;
-
+
/**
* Constructor for RepositoriesView.
- * @param partName
*/
public RepositoriesView() {
super(VIEW_ID);
@@ -145,7 +145,19 @@ public class RepositoriesView extends RemoteViewPart {
if (dialogSettings == null) {
dialogSettings = workbenchSettings.addNewSection(VIEW_ID);
}
- savedComparator = dialogSettings.get(SELECTED_COMPARATOR);
+
+ try {
+ // parse the values
+ String selectedOrderBy = dialogSettings.get(SELECTED_ORDER_BY);
+ String selectedSortingOrder = dialogSettings.get(SELECTED_SORTING_ORDER);
+
+ int orderBy = Integer.parseInt(selectedOrderBy);
+ boolean ascending = Boolean.valueOf(selectedSortingOrder).booleanValue();
+
+ savedComparator = new RepositoryComparator(orderBy, ascending);
+ } catch (NumberFormatException e) {
+ // ignore, use default comparator
+ }
}
/**
@@ -219,7 +231,7 @@ public class RepositoriesView extends RemoteViewPart {
IActionBars bars = getViewSite().getActionBars();
bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), removeAction);
- // Working Set action group
+ // Sort By action group
IPropertyChangeListener comparatorUpdater = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
@@ -227,20 +239,21 @@ public class RepositoriesView extends RemoteViewPart {
.equals(property)) {
Object newValue = event.getNewValue();
getViewer().setComparator((ViewerComparator) newValue);
- saveSelectedComparator(((RepositoryComparator) newValue).getOrder()+""); //$NON-NLS-1$
+ saveSelectedComparator((RepositoryComparator) newValue);
}
}
-
};
setActionGroup(new RepositoriesSortingActionGroup(shell, comparatorUpdater));
+ // restore comparator selection
getRepositoriesSortingActionGroup().setSelectedComparator(savedComparator);
super.contributeActions();
}
- private void saveSelectedComparator(String selectedComparator) {
+ private void saveSelectedComparator(RepositoryComparator selectedComparator) {
if (dialogSettings != null) {
- dialogSettings.put(SELECTED_COMPARATOR, selectedComparator);
+ dialogSettings.put(SELECTED_ORDER_BY, selectedComparator.getOrderBy());
+ dialogSettings.put(SELECTED_SORTING_ORDER, selectedComparator.isAscending());
}
}
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 a972a2f07..6e9059bfb 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
@@ -25,23 +25,45 @@ public class RepositoryComparator extends ViewerComparator {
public static final int ORDER_LOCATION = 1;
- public static final int ORDER_HOST = 2;
+ public static final int ORDER_HOST = 2;
+
+ private int orderBy = ORDER_DEFAULT;
- private int order = ORDER_DEFAULT;
+ private boolean ascending = true;
+
+ public RepositoryComparator(int order, boolean ascending) {
+ super();
+ this.orderBy = order;
+ this.ascending = ascending;
+ }
public RepositoryComparator(int order) {
super();
- this.order = order;
+ this.orderBy = order;
+ // default sorting order is ascending
}
public RepositoryComparator() {
super();
+ // default is sort by label ascending
}
- public int getOrder() {
- return order;
+ public int getOrderBy() {
+ return orderBy;
}
+ public void setOrder(int orderBy) {
+ this.orderBy = orderBy;
+ }
+
+ public void setAscending(boolean ascending) {
+ this.ascending = ascending;
+ }
+
+ public boolean isAscending() {
+ return ascending;
+ }
+
public int category(Object element) {
if (element instanceof ICVSRemoteFolder) {
if (((ICVSRemoteFolder)element).isDefinedModule()) {
@@ -124,19 +146,24 @@ public class RepositoryComparator extends ViewerComparator {
ICVSRepositoryLocation rl1 = rr1.getRoot();
ICVSRepositoryLocation rl2 = rr2.getRoot();
- switch (order) {
- case ORDER_DEFAULT:
- // for default order use super.compare
- break;
+ int compareResult = 0;
+ switch (orderBy) {
case ORDER_HOST:
- if (rl1.getHost().compareTo(rl2.getHost()) != 0)
- return rl1.getHost().compareTo(rl2.getHost());
- // no break
- // add other cases here
+ compareResult = rl1.getHost().compareTo(rl2.getHost());
+ if (compareResult != 0)
+ break;
case ORDER_LOCATION:
+ compareResult = rl1.getLocation(false).compareTo(
+ rl2.getLocation(false));
+ if (compareResult != 0)
+ break;
+ // add other cases here
+ case ORDER_DEFAULT:
+ // for default order use super.compare (i.e. compare labels)
default:
- return (rl1.getLocation(false).compareTo(rl2.getLocation(false)));
+ compareResult = super.compare(viewer, o1, o2);
}
+ return ascending ? compareResult : -compareResult;
}
return super.compare(viewer, o1, o2);
@@ -152,5 +179,19 @@ public class RepositoryComparator extends ViewerComparator {
if (tag2 == null) return -1;
return tag2.compareTo(tag1);
}
+
+ /**
+ * Returns a reversed RepositoryComparator.
+ *
+ * @return A comparator which sorts repositories by the same criterion but
+ * in a reversed order.
+ */
+ public RepositoryComparator getReversedComparator() {
+ RepositoryComparator repositoryComparator = new RepositoryComparator(
+ orderBy);
+ repositoryComparator.setAscending(!this.ascending);
+ return repositoryComparator;
+ }
+
}

Back to the top