summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-06-17 17:16:29 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-06-25 12:55:20 (EDT)
commitb36528c1c41a7b24936004d0e29c823f1068187c (patch)
tree0c74bfff72437738e072043387b89e80d441fb3e
parent6a27e8dc89e5548ee1c7cac2ce84518ad529f745 (diff)
downloadorg.eclipse.mylyn.tasks-b36528c1c41a7b24936004d0e29c823f1068187c.zip
org.eclipse.mylyn.tasks-b36528c1c41a7b24936004d0e29c823f1068187c.tar.gz
org.eclipse.mylyn.tasks-b36528c1c41a7b24936004d0e29c823f1068187c.tar.bz2
322855: New Query > Select a Repo wizard page should sort repos by namerefs/changes/58/13858/4
Change-Id: Ia573ba39558f18c51b7c42e7fbb9d4532736958a Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=322855
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositorySorterTest.java61
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryViewSorterTest.java36
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesSorter.java14
3 files changed, 90 insertions, 21 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositorySorterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositorySorterTest.java
index 646618c..8d7be79 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositorySorterTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositorySorterTest.java
@@ -13,7 +13,9 @@ package org.eclipse.mylyn.tasks.tests;
import junit.framework.TestCase;
+import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
+import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskRepositoriesSorter;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -22,50 +24,57 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
*/
public class TaskRepositorySorterTest extends TestCase {
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
+ private final static ViewerComparator sorter = new TaskRepositoriesSorter();
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ public void testConnectorKindSorting() {
+ TaskRepository t1 = new TaskRepository("t1", "http://a");
+ TaskRepository t2 = new TaskRepository("t2", "http://a");
+ TaskRepository t3 = new TaskRepository("t3", "http://a");
+
+ // connector kind no longer affects sorting order
+ assertTrue(sorter.compare(null, t1, t2) == 0);
+ assertTrue(sorter.compare(null, t2, t3) == 0);
+ assertTrue(sorter.compare(null, t3, t1) == 0);
}
public void testCategorySorting() {
- TaskRepositoriesSorter sorter = new TaskRepositoriesSorter();
TaskRepository t1 = new TaskRepository("t1", "http://a");
+ t1.setCategory(IRepositoryConstants.CATEGORY_OTHER);
TaskRepository t2 = new TaskRepository("t2", "http://a");
+ t2.setCategory(IRepositoryConstants.CATEGORY_OTHER);
TaskRepository t3 = new TaskRepository("t3", "http://a");
- assertTrue(sorter.compare(null, t1, t2) < 0);
- assertTrue(sorter.compare(null, t3, t1) > 0);
+ t3.setCategory(TaskRepository.CATEGORY_TASKS);
+
+ // TaskRepositoriesSorter is not aware of categories, see TaskRepositoryViewSorterTest
+ assertTrue(sorter.compare(null, t1, t2) == 0);
+ assertTrue(sorter.compare(null, t2, t3) == 0);
+ assertTrue(sorter.compare(null, t3, t1) == 0);
}
public void testUrlSorting() {
- TaskRepositoriesSorter sorter = new TaskRepositoriesSorter();
TaskRepository t1 = new TaskRepository("t", "http://a");
TaskRepository t2 = new TaskRepository("t", "http://b");
TaskRepository t3 = new TaskRepository("t", "http://c");
+
assertTrue(sorter.compare(null, t1, t2) < 0);
assertTrue(sorter.compare(null, t2, t3) < 0);
assertTrue(sorter.compare(null, t3, t1) > 0);
}
public void testUrlSortingWithEmptyLabels() {
- TaskRepositoriesSorter sorter = new TaskRepositoriesSorter();
TaskRepository t1 = new TaskRepository("t", "http://a");
t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "");
TaskRepository t2 = new TaskRepository("t", "http://b");
t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, "");
TaskRepository t3 = new TaskRepository("t", "http://c");
t3.setProperty(IRepositoryConstants.PROPERTY_LABEL, "");
+
assertTrue(sorter.compare(null, t1, t2) < 0);
assertTrue(sorter.compare(null, t2, t3) < 0);
assertTrue(sorter.compare(null, t3, t1) > 0);
}
public void testLabelSorting() {
- TaskRepositoriesSorter sorter = new TaskRepositoriesSorter();
TaskRepository t1 = new TaskRepository("kind", "http://a");
t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "a");
TaskRepository t2 = new TaskRepository("kind", "http://a");
@@ -78,7 +87,6 @@ public class TaskRepositorySorterTest extends TestCase {
}
public void testLabelVsNoLabel() {
- TaskRepositoriesSorter sorter = new TaskRepositoriesSorter();
TaskRepository t1 = new TaskRepository("kind", "http://a");
t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "a");
TaskRepository t2 = new TaskRepository("kind", "http://a");
@@ -86,4 +94,29 @@ public class TaskRepositorySorterTest extends TestCase {
assertTrue(sorter.compare(null, t1, t2) < 0);
}
+ public void testLocalAlwaysFirst() {
+ TaskRepository t1 = new TaskRepository("kind", "http://a");
+ TaskRepository t2 = new TaskRepository("kind", "http://a");
+ t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, LocalRepositoryConnector.REPOSITORY_LABEL);
+
+ assertTrue(sorter.compare(null, t1, t2) > 0);
+ }
+
+ public void testCaseInsensitiveOrdering() {
+ TaskRepository t1 = new TaskRepository("kind", "http://a");
+ t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "B");
+ TaskRepository t2 = new TaskRepository("kind", "http://a");
+ t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, "a");
+
+ assertTrue(sorter.compare(null, t1, t2) > 0);
+ }
+
+ public void testNullRepositoryUrl() {
+ TaskRepository t1 = new TaskRepository("kind", "http://a");
+ t1.setProperty(IRepositoryConstants.PROPERTY_URL, null);
+ TaskRepository t2 = new TaskRepository("kind", "http://a");
+
+ assertTrue(sorter.compare(null, t1, t2) > 0);
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryViewSorterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryViewSorterTest.java
new file mode 100644
index 0000000..b5eb46c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryViewSorterTest.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskRepositoriesViewSorter;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+
+public class TaskRepositoryViewSorterTest extends TestCase {
+
+ public void testCategorySorting() {
+ ViewerSorter sorter = new TaskRepositoriesViewSorter();
+ TaskRepository t1 = new TaskRepository("kind", "http://a");
+ t1.setCategory(IRepositoryConstants.CATEGORY_OTHER);
+ TaskRepository t2 = new TaskRepository("kind", "http://b");
+ t2.setCategory(IRepositoryConstants.CATEGORY_OTHER);
+ TaskRepository t3 = new TaskRepository("kind", "http://c");
+ t3.setCategory(TaskRepository.CATEGORY_TASKS);
+
+ assertTrue(sorter.compare(null, t1, t2) < 0);
+ assertTrue(sorter.compare(null, t2, t3) > 0);
+ assertTrue(sorter.compare(null, t3, t1) < 0);
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesSorter.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesSorter.java
index 79cfe1f..c209515 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesSorter.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesSorter.java
@@ -30,19 +30,19 @@ public class TaskRepositoriesSorter extends ViewerSorter {
String label1 = t1.getRepositoryLabel();
String label2 = t2.getRepositoryLabel();
+ if (label1 == null) {
+ return (label2 != null) ? 1 : 0;
+ } else if (label2 == null) {
+ return -1;
+ }
+
if (LocalRepositoryConnector.REPOSITORY_LABEL.equals(label1)) {
return -1;
} else if (LocalRepositoryConnector.REPOSITORY_LABEL.equals(label2)) {
return 1;
}
- if (!t1.getConnectorKind().equals(t2.getConnectorKind())) {
- return (t1.getConnectorKind()).compareTo(t2.getConnectorKind());
- } else {
- if (label1 != null) {
- return label1.compareTo(label2);
- }
- }
+ return label1.compareToIgnoreCase(label2);
}
return super.compare(viewer, e1, e2);
}