Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaxsun McCarthy Huggan2016-06-15 18:32:14 -0400
committerGerrit Code Review @ Eclipse.org2016-08-16 20:09:19 -0400
commit10d73213c4d6b5318b0606db516014fbc8de7dd0 (patch)
tree1fe577adbef1419caa893f804e4e00d5f51e30c7
parentf4f9a57fc83f397ab4b7c4704cd8e69003e94a6e (diff)
downloadorg.eclipse.mylyn.tasks-10d73213c4d6b5318b0606db516014fbc8de7dd0.tar.gz
org.eclipse.mylyn.tasks-10d73213c4d6b5318b0606db516014fbc8de7dd0.tar.xz
org.eclipse.mylyn.tasks-10d73213c4d6b5318b0606db516014fbc8de7dd0.zip
319889: Support sorting of scheduled presentation
The TaskComparator now maintains a list of sort criteria per presentation. The criteria will always be configured for the active presentation. The migration of old sorting mementos was removed. Change-Id: I5d9b594e4efda7b35ccdca2b19fb824a6590d5f1 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=319889
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java41
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java76
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/Messages.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java22
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/messages.properties1
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/Messages.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/SortCriterion.java18
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java179
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/messages.properties1
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListSorter.java17
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java96
11 files changed, 225 insertions, 230 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
index f0749de36..58dfa29e9 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
@@ -35,13 +35,10 @@ import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListInterestSorter;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListSorter;
-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.XMLMemento;
import junit.framework.TestCase;
@@ -53,44 +50,6 @@ import junit.framework.TestCase;
*/
public class TaskListSorterTest extends TestCase {
- private static final String MEMENTO_KEY_SORT_DIRECTION = "sortDirection"; //$NON-NLS-1$
-
- private static final String MEMENTO_KEY_SORT_INDEX = "sortIndex"; //$NON-NLS-1$
-
- private static final String MEMENTO_KEY_SORTER = "sorter"; //$NON-NLS-1$
-
- private static final String MEMENTO_KEY_SORTER2 = "sorter2"; //$NON-NLS-1$
-
- public void testPreferenceMigration() throws Exception {
- final TaskListSorter sorter = new TaskListSorter();
- TaskListView view = new TaskListView();
- XMLMemento memento = XMLMemento.createWriteRoot(MEMENTO_KEY_SORT_INDEX);
- IMemento child = memento.createChild(MEMENTO_KEY_SORTER);
- child.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
- child.putInteger(MEMENTO_KEY_SORT_DIRECTION, 1);
- child = memento.createChild(MEMENTO_KEY_SORTER2);
- child.putInteger(MEMENTO_KEY_SORT_INDEX, 1);
- child.putInteger(MEMENTO_KEY_SORT_DIRECTION, -1);
- view.migrateSorterState(sorter, memento);
- assertEquals(SortCriterion.SortKey.PRIORITY, sorter.getTaskComparator().getSortCriterion(0).getKey());
- assertEquals(1, sorter.getTaskComparator().getSortCriterion(0).getDirection());
- assertEquals(SortCriterion.SortKey.SUMMARY, sorter.getTaskComparator().getSortCriterion(1).getKey());
- assertEquals(-1, sorter.getTaskComparator().getSortCriterion(1).getDirection());
-
- memento = XMLMemento.createWriteRoot(MEMENTO_KEY_SORT_INDEX);
- child = memento.createChild(MEMENTO_KEY_SORTER);
- child.putInteger(MEMENTO_KEY_SORT_INDEX, 3);
- child.putInteger(MEMENTO_KEY_SORT_DIRECTION, -1);
- child = memento.createChild(MEMENTO_KEY_SORTER2);
- child.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
- child.putInteger(MEMENTO_KEY_SORT_DIRECTION, -1);
- view.migrateSorterState(sorter, memento);
- assertEquals(SortCriterion.SortKey.TASK_ID, sorter.getTaskComparator().getSortCriterion(0).getKey());
- assertEquals(-1, sorter.getTaskComparator().getSortCriterion(0).getDirection());
- assertEquals(SortCriterion.SortKey.DATE_CREATED, sorter.getTaskComparator().getSortCriterion(1).getKey());
- assertEquals(-1, sorter.getTaskComparator().getSortCriterion(1).getDirection());
- }
-
public void testSortWithError() {
final TaskListSorter sorter = new TaskListSorter();
ITask task1 = new LocalTask("1", null);
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java
index eaa65c5a0..29f559327 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java
@@ -15,12 +15,26 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.eclipse.mylyn.internal.tasks.core.TaskTask;
+import org.eclipse.mylyn.internal.tasks.ui.CategorizedPresentation;
+import org.eclipse.mylyn.internal.tasks.ui.ScheduledPresentation;
+import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion.SortKey;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.XMLMemento;
+import org.junit.Before;
import org.junit.Test;
+@SuppressWarnings("restriction")
public class TaskComparatorTest {
+ private TaskComparator taskComparator;
+
+ @Before
+ public void setup() {
+ taskComparator = new TaskComparator();
+ }
+
@Test
public void compareRank() {
assertCompare(taskWithRank("5"), taskWithRank("7"));
@@ -34,23 +48,65 @@ public class TaskComparatorTest {
assertCompare(taskWithRank("dsfhgS"), taskWithRank("dsfhgsd"));
assertCompare(taskWithRank("dsfhgs"), taskWithRank("dsfhgsd"));
- assertEquals(0, compare(taskWithRank("5"), taskWithRank("5")));
- assertEquals(0, compare(taskWithRank("17.1"), taskWithRank("17.1")));
- assertEquals(0, compare(taskWithRank("dsfhgs"), taskWithRank("dsfhgs")));
- assertEquals(0, compare(taskWithRank("ds#fHgs"), taskWithRank("ds#fHgs")));
+ assertEquals(0, taskComparator.compare(taskWithRank("5"), taskWithRank("5")));
+ assertEquals(0, taskComparator.compare(taskWithRank("17.1"), taskWithRank("17.1")));
+ assertEquals(0, taskComparator.compare(taskWithRank("dsfhgs"), taskWithRank("dsfhgs")));
+ assertEquals(0, taskComparator.compare(taskWithRank("ds#fHgs"), taskWithRank("ds#fHgs")));
}
- private void assertCompare(ITask task1, ITask task2) {
- assertTrue(compare(task1, task2) < 0);
- assertTrue(compare(task2, task1) > 0);
+ @Test
+ public void readLegacyMemento() {
+ XMLMemento memento = XMLMemento.createWriteRoot("sorter");
+ IMemento child1 = memento.createChild("sort0");
+ IMemento child2 = memento.createChild("sort1");
+ SortCriterion criterion1 = new SortCriterion(SortKey.PRIORITY, SortCriterion.ASCENDING);
+ SortCriterion criterion2 = new SortCriterion(SortKey.TASK_ID, SortCriterion.DESCENDING);
+ criterion1.saveState(child1);
+ criterion2.saveState(child2);
+ taskComparator.restoreState(memento);
+ assertCriterionEquals(criterion1, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2, taskComparator.getSortCriterion(1));
}
- private int compare(ITask task1, ITask task2) {
- return new TaskComparator().compare(task1, task2);
+ @Test
+ public void readPerspectiveMemento() {
+ XMLMemento memento = XMLMemento.createWriteRoot("sorter");
+ IMemento categorized1 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.categorized0");
+ IMemento categorized2 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.categorized1");
+ IMemento scheduled1 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.scheduled0");
+ IMemento scheduled2 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.scheduled1");
+ SortCriterion criterion1c = new SortCriterion(SortKey.PRIORITY, SortCriterion.ASCENDING);
+ SortCriterion criterion2c = new SortCriterion(SortKey.TASK_ID, SortCriterion.DESCENDING);
+ SortCriterion criterion1s = new SortCriterion(SortKey.DUE_DATE, SortCriterion.ASCENDING);
+ SortCriterion criterion2s = new SortCriterion(SortKey.SCHEDULED_DATE, SortCriterion.DESCENDING);
+ criterion1c.saveState(categorized1);
+ criterion2c.saveState(categorized2);
+ criterion1s.saveState(scheduled1);
+ criterion2s.saveState(scheduled2);
+
+ taskComparator.restoreState(memento);
+
+ assertCriterionEquals(criterion1c, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2c, taskComparator.getSortCriterion(1));
+ taskComparator.presentationChanged(new ScheduledPresentation());
+ assertCriterionEquals(criterion1s, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2s, taskComparator.getSortCriterion(1));
+ taskComparator.presentationChanged(new CategorizedPresentation());
+ assertCriterionEquals(criterion1c, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2c, taskComparator.getSortCriterion(1));
+ }
+
+ private void assertCriterionEquals(SortCriterion expected, SortCriterion actual) {
+ assertEquals(expected.getDirection(), actual.getDirection());
+ assertEquals(expected.getKey(), actual.getKey());
+ }
+
+ private void assertCompare(ITask task1, ITask task2) {
+ assertTrue(taskComparator.compare(task1, task2) < 0);
+ assertTrue(taskComparator.compare(task2, task1) > 0);
}
private ITask taskWithRank(String rank) {
- @SuppressWarnings("restriction")
ITask task = new TaskTask("kind", "http://mock", "1");
task.setPriority("");
task.setAttribute(TaskAttribute.RANK, rank);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/Messages.java
index c05712d5f..a3cc7b66e 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/Messages.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/Messages.java
@@ -29,6 +29,8 @@ public class Messages extends NLS {
public static String TaskCompareDialog_Descending;
+ public static String TaskCompareDialog_Presentation_warning;
+
public static String TaskCompareDialog_Sort_by;
public static String TaskCompareDialog_Sorting;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java
index ade2b685f..ba3770ed1 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java
@@ -79,6 +79,10 @@ public class TaskCompareDialog extends SelectionDialog {
prioritiesArea.setLayout(new GridLayout(3, false));
prioritiesArea.setText(Messages.TaskCompareDialog_Tasks);
+ Label label = new Label(prioritiesArea, SWT.WRAP);
+ label.setText(Messages.TaskCompareDialog_Presentation_warning);
+ label.setLayoutData(GridDataFactory.swtDefaults().span(3, 1).create());
+
ascendingButtons = new Button[SortCriterion.kindCount];
descendingButtons = new Button[SortCriterion.kindCount];
priorityCombos = new Combo[SortCriterion.kindCount];
@@ -153,7 +157,8 @@ public class TaskCompareDialog extends SelectionDialog {
for (int j = 0; j < availablePriorities.size(); j++) {
priorityCombos[k].add(availablePriorities.get(j));
}
- priorityCombos[k].select(priorityCombos[k].indexOf(propertyText[SortKey.NONE.ordinal()]));
+ priorityCombos[k]
+ .select(priorityCombos[k].indexOf(propertyText[SortKey.NONE.ordinal()]));
}
}
} else if (newSelection.equals(propertyText[SortKey.NONE.ordinal()])) {
@@ -168,7 +173,8 @@ public class TaskCompareDialog extends SelectionDialog {
for (int j = 0; j < availablePriorities.size(); j++) {
priorityCombos[k].add(availablePriorities.get(j));
}
- priorityCombos[k].select(priorityCombos[k].indexOf(propertyText[SortKey.NONE.ordinal()]));
+ priorityCombos[k]
+ .select(priorityCombos[k].indexOf(propertyText[SortKey.NONE.ordinal()]));
priorityCombos[k].setEnabled(false);
ascendingButtons[k].setEnabled(false);
descendingButtons[k].setEnabled(false);
@@ -180,16 +186,15 @@ public class TaskCompareDialog extends SelectionDialog {
//this combo's current selection is equal to newSelection
if (priorityCombos[j].getSelectionIndex() == newSelectionIndex) {
priorityCombos[j].remove(newSelection);
- int insertionPoint = -1
- - Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
- columnComparator);
+ int insertionPoint = -1 - Arrays.binarySearch(priorityCombos[j].getItems(),
+ oldSelection, columnComparator);
if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
priorityCombos[j].add(oldSelection, insertionPoint);
} else {
priorityCombos[j].add(oldSelection);
}
priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection));
-// remove the comment if you want to move the current ascending/descending
+// remove the comment if you want to move the current ascending/descending
// ascendingButtons[index].setSelection(ascendingButtons[j].getSelection());
// descendingButtons[index].setSelection(descendingButtons[j].getSelection());
// ascendingButtons[j].setSelection(oldSelectionDirection == 1);
@@ -199,9 +204,8 @@ public class TaskCompareDialog extends SelectionDialog {
else if (newSelectionIndex >= 0) {
String currentText = priorityCombos[j].getText();
priorityCombos[j].remove(newSelection);
- int insertionPoint = -1
- - Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
- columnComparator);
+ int insertionPoint = -1 - Arrays.binarySearch(priorityCombos[j].getItems(),
+ oldSelection, columnComparator);
if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
priorityCombos[j].add(oldSelection, insertionPoint);
priorityCombos[j].select(priorityCombos[j].indexOf(currentText));
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/messages.properties
index 76c4b7292..55bff2a2a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/messages.properties
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/messages.properties
@@ -10,6 +10,7 @@
###############################################################################
TaskCompareDialog_Ascending=Ascending
TaskCompareDialog_Descending=Descending
+TaskCompareDialog_Presentation_warning=The configured sorting criteria will apply to the currently selected Task List Presentation only.
TaskCompareDialog_Sort_by=Sort by:
TaskCompareDialog_Sorting=Sorting
TaskCompareDialog_Tasks=Tasks
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/Messages.java
index f0ad9228d..7149d8eb0 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/Messages.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/Messages.java
@@ -43,6 +43,8 @@ public class Messages extends NLS {
public static String SortCriterion_Modification_Date;
+ public static String SortCriterion_Scheduled_Date;
+
public static String SortCriterion_Type;
public static String SortKindEntry_Date_Created;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/SortCriterion.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/SortCriterion.java
index 9c0f7ce37..e47387dab 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/SortCriterion.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/SortCriterion.java
@@ -22,7 +22,7 @@ import org.eclipse.ui.IMemento;
public class SortCriterion {
public enum SortKey {
- NONE, DATE_CREATED, PRIORITY, RANK, SUMMARY, TASK_ID, TASK_TYPE, DUE_DATE, MODIFICATION_DATE;
+ NONE, DATE_CREATED, PRIORITY, RANK, SUMMARY, TASK_ID, TASK_TYPE, DUE_DATE, MODIFICATION_DATE, SCHEDULED_DATE;
public static SortKey valueOfLabel(String label) {
for (SortKey value : values()) {
@@ -53,6 +53,8 @@ public class SortCriterion {
return Messages.SortKindEntry_Due_Date;
case MODIFICATION_DATE:
return Messages.SortCriterion_Modification_Date;
+ case SCHEDULED_DATE:
+ return Messages.SortCriterion_Scheduled_Date;
default:
return null;
}
@@ -60,20 +62,24 @@ public class SortCriterion {
}
- private SortKey key;
-
- private int direction;
-
private static final String MEMENTO_KEY_SORT_KEY = "sortKey"; //$NON-NLS-1$
private static final String MEMENTO_KEY_SORT_DIRECTION = "sortDirection"; //$NON-NLS-1$
private static final SortKey DEFAULT_SORT_KIND = SortKey.NONE;
- private static final int DEFAULT_SORT_DIRECTION = 1;
+ public static final int ASCENDING = 1;
+
+ public static final int DESCENDING = -1;
+
+ private static final int DEFAULT_SORT_DIRECTION = ASCENDING;
public static final int kindCount = SortKey.values().length - 1;
+ private SortKey key;
+
+ private int direction;
+
public SortCriterion() {
key = DEFAULT_SORT_KIND;
direction = DEFAULT_SORT_DIRECTION;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java
index 5c5ecdc8e..a735f513a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java
@@ -15,31 +15,36 @@ package org.eclipse.mylyn.internal.tasks.ui.util;
import java.util.Comparator;
import java.util.Date;
+import java.util.List;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.DateRange;
+import org.eclipse.mylyn.internal.tasks.core.DayDateRange;
+import org.eclipse.mylyn.internal.tasks.ui.CategorizedPresentation;
+import org.eclipse.mylyn.internal.tasks.ui.ScheduledPresentation;
import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion.SortKey;
+import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTaskListPresentation;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.ui.IMemento;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
/**
* @author Mik Kersten
* @author Frank Becker
*/
public class TaskComparator implements Comparator<ITask> {
- private final SortCriterion[] sortCriteria;
-
- public static final int DEFAULT_SORT_DIRECTION = 1;
-
- private static final SortKey DEFAULT_SORT_INDEX = SortKey.PRIORITY;
-
- private static final SortKey DEFAULT_SORT_INDEX2 = SortKey.RANK;
+ private static final String MEMENTO_KEY_SORT = "sort"; //$NON-NLS-1$
- private static final SortKey DEFAULT_SORT_INDEX3 = SortKey.DATE_CREATED;
+ private final ListMultimap<String, SortCriterion> sortCriteria;
- private static final String MEMENTO_KEY_SORT = "sort"; //$NON-NLS-1$
+ private String currentPresentation;
/**
* Return a array of values to pass to taskKeyComparator.compare() for sorting
@@ -64,21 +69,43 @@ public class TaskComparator implements Comparator<ITask> {
public static final int CRITERIA_COUNT = SortKey.values().length - 1;
public TaskComparator() {
- sortCriteria = new SortCriterion[CRITERIA_COUNT];
- for (int index = 0; index < CRITERIA_COUNT; index++) {
- sortCriteria[index] = new SortCriterion();
+ sortCriteria = ArrayListMultimap.create();
+
+ for (AbstractTaskListPresentation presentation : TaskListView.getPresentations()) {
+ String presentationId = presentation.getId();
+ for (int i = 0; i < CRITERIA_COUNT; i++) {
+ sortCriteria.put(presentationId, new SortCriterion());
+ }
}
- sortCriteria[0].setKey(DEFAULT_SORT_INDEX);
- sortCriteria[1].setKey(DEFAULT_SORT_INDEX2);
- sortCriteria[2].setKey(DEFAULT_SORT_INDEX3);
+
+ for (String id : sortCriteria.keySet()) {
+ List<SortCriterion> presentationCriteria = sortCriteria.get(id);
+ if (id.equals(ScheduledPresentation.ID)) {
+ // scheduled presentation has specific defaults
+ presentationCriteria.get(0).setKey(SortKey.DUE_DATE);
+ presentationCriteria.get(0).setDirection(SortCriterion.ASCENDING);
+ presentationCriteria.get(1).setKey(SortKey.SCHEDULED_DATE);
+ presentationCriteria.get(1).setDirection(SortCriterion.ASCENDING);
+ presentationCriteria.get(2).setKey(SortKey.PRIORITY);
+ presentationCriteria.get(3).setKey(SortKey.RANK);
+ presentationCriteria.get(4).setKey(SortKey.DATE_CREATED);
+ } else {
+ // standard defaults
+ presentationCriteria.get(0).setKey(SortKey.PRIORITY);
+ presentationCriteria.get(1).setKey(SortKey.RANK);
+ presentationCriteria.get(2).setKey(SortKey.DATE_CREATED);
+ }
+ }
+
+ currentPresentation = CategorizedPresentation.ID;
}
public int compare(ITask element1, ITask element2) {
- for (SortCriterion key : sortCriteria) {
+ for (SortCriterion key : getCurrentCriteria()) {
int result;
switch (key.getKey()) {
case DATE_CREATED:
- result = sortByDate(element1, element2, key.getDirection());
+ result = sortByCreationDate(element1, element2, key.getDirection());
break;
case RANK:
result = sortByRank(element1, element2, key.getDirection());
@@ -101,6 +128,9 @@ public class TaskComparator implements Comparator<ITask> {
case MODIFICATION_DATE:
result = sortByModificationDate(element1, element2, key.getDirection());
break;
+ case SCHEDULED_DATE:
+ result = sortByScheduledDate(element1, element2, key.getDirection());
+ break;
default: // NONE
return 0;
}
@@ -113,15 +143,24 @@ public class TaskComparator implements Comparator<ITask> {
}
public SortCriterion getSortCriterion(int index) {
- return sortCriteria[index];
+ return getCurrentCriteria().get(index);
}
public void restoreState(IMemento memento) {
if (memento != null) {
- for (int index = 0; index < CRITERIA_COUNT; index++) {
- IMemento child = memento.getChild(MEMENTO_KEY_SORT + index);
- if (child != null && sortCriteria[index] != null) {
- sortCriteria[index].restoreState(child);
+ for (String presentationId : sortCriteria.keySet()) {
+ List<SortCriterion> criteria = sortCriteria.get(presentationId);
+ for (int i = 0; i < criteria.size(); i++) {
+ IMemento child = memento.getChild(MEMENTO_KEY_SORT + presentationId + i);
+ if (child != null) {
+ criteria.get(i).restoreState(child);
+ } else if (CategorizedPresentation.ID.equals(presentationId)) {
+ // attempt to read memento as it would have recorded before sort criteria were stored by presentation
+ child = memento.getChild(MEMENTO_KEY_SORT + i);
+ if (child != null) {
+ criteria.get(i).restoreState(child);
+ }
+ }
}
}
}
@@ -129,38 +168,66 @@ public class TaskComparator implements Comparator<ITask> {
public void saveState(IMemento memento) {
if (memento != null) {
- for (int index = 0; index < CRITERIA_COUNT; index++) {
- IMemento child = memento.createChild(MEMENTO_KEY_SORT + index);
- if (child != null && sortCriteria[index] != null) {
- sortCriteria[index].saveState(child);
+ for (String presentationId : sortCriteria.keySet()) {
+ List<SortCriterion> criteria = sortCriteria.get(presentationId);
+ for (int i = 0; i < criteria.size(); i++) {
+ IMemento child = memento.createChild(MEMENTO_KEY_SORT + presentationId + i);
+ if (child != null) {
+ criteria.get(i).saveState(child);
+ }
}
}
}
}
- private int sortByDate(ITask element1, ITask element2, int sortDirection) {
- Date date1 = element1.getCreationDate();
- Date date2 = element2.getCreationDate();
- if (date1 == null) {
- return (date2 != null) ? sortDirection : 0;
- } else if (date2 == null) {
- return -sortDirection;
- }
- return sortDirection * date1.compareTo(date2);
+ public void presentationChanged(AbstractTaskListPresentation presentation) {
+ currentPresentation = presentation.getId();
+ }
+
+ private List<SortCriterion> getCurrentCriteria() {
+ return sortCriteria.get(currentPresentation);
+ }
+
+ private int sortByCreationDate(ITask task1, ITask task2, int sortDirection) {
+ Date date1 = task1.getCreationDate();
+ Date date2 = task2.getCreationDate();
+ return compare(date1, date2, sortDirection);
}
- private int sortByDueDate(ITask element1, ITask element2, int sortDirection) {
- Date date1 = element1.getDueDate();
- Date date2 = element2.getDueDate();
+ private int sortByDueDate(ITask task1, ITask task2, int sortDirection) {
+ Date date1 = task1.getDueDate();
+ Date date2 = task2.getDueDate();
return compare(date1, date2, sortDirection);
}
- private int sortByModificationDate(ITask element1, ITask element2, int sortDirection) {
- Date date1 = element1.getModificationDate();
- Date date2 = element2.getModificationDate();
+ private int sortByModificationDate(ITask task1, ITask task2, int sortDirection) {
+ Date date1 = task1.getModificationDate();
+ Date date2 = task2.getModificationDate();
return compare(date1, date2, sortDirection);
}
+ private int sortByScheduledDate(ITask task1, ITask task2, int sortDirection) {
+ if (task1 instanceof AbstractTask && task2 instanceof AbstractTask) {
+ DateRange date1 = ((AbstractTask) task1).getScheduledForDate();
+ DateRange date2 = ((AbstractTask) task2).getScheduledForDate();
+ return compare(date1, date2, sortDirection);
+ }
+ return 0;
+ }
+
+ private int compare(DateRange date1, DateRange date2, int sortDirection) {
+ if (date1 == null) {
+ return date2 == null ? 0 : 1;
+ } else if (date2 == null) {
+ return -1;
+ } else if (date1 instanceof DayDateRange && !(date2 instanceof DayDateRange)) {
+ return -1;
+ } else if (date2 instanceof DayDateRange && !(date1 instanceof DayDateRange)) {
+ return 1;
+ }
+ return compare(date1.getEndDate(), date2.getEndDate(), sortDirection);
+ }
+
private <T> int compare(Comparable<T> key1, T key2, int sortDirection) {
if (key1 == null) {
return (key2 != null) ? sortDirection : 0;
@@ -170,9 +237,9 @@ public class TaskComparator implements Comparator<ITask> {
return sortDirection * key1.compareTo(key2);
}
- private int sortByID(ITask element1, ITask element2, int sortDirection) {
- String key1 = element1.getTaskKey();
- String key2 = element2.getTaskKey();
+ private int sortByID(ITask task1, ITask task2, int sortDirection) {
+ String key1 = task1.getTaskKey();
+ String key2 = task2.getTaskKey();
if (key1 == null) {
return (key2 != null) ? sortDirection : 0;
} else if (key2 == null) {
@@ -181,15 +248,15 @@ public class TaskComparator implements Comparator<ITask> {
return sortDirection * taskKeyComparator.compare2(key1, key2);
}
- private int sortByRank(ITask element1, ITask element2, int sortDirection) {
- if (element1.getConnectorKind() != null && element2.getConnectorKind() != null
- && element1.getConnectorKind().equals(element2.getConnectorKind())) {
+ private int sortByRank(ITask task1, ITask task2, int sortDirection) {
+ if (task1.getConnectorKind() != null && task2.getConnectorKind() != null
+ && task1.getConnectorKind().equals(task2.getConnectorKind())) {
// only compare rank of elements from the same connector
- if (element1.getRepositoryUrl() != null && element2.getRepositoryUrl() != null
- && element1.getRepositoryUrl().equals(element2.getRepositoryUrl())) {
+ if (task1.getRepositoryUrl() != null && task2.getRepositoryUrl() != null
+ && task1.getRepositoryUrl().equals(task2.getRepositoryUrl())) {
// only compare the rank of elements in the same repository
- String rankString1 = element1.getAttribute(TaskAttribute.RANK);
- String rankString2 = element2.getAttribute(TaskAttribute.RANK);
+ String rankString1 = task1.getAttribute(TaskAttribute.RANK);
+ String rankString2 = task2.getAttribute(TaskAttribute.RANK);
try {
Double rank1 = rankString1 == null || rankString1.length() == 0
? Double.valueOf(0)
@@ -206,13 +273,13 @@ public class TaskComparator implements Comparator<ITask> {
return 0;
}
- private int sortByPriority(ITask element1, ITask element2, int sortDirection) {
- return sortDirection * element1.getPriority().compareToIgnoreCase(element2.getPriority());
+ private int sortByPriority(ITask task1, ITask task2, int sortDirection) {
+ return sortDirection * task1.getPriority().compareToIgnoreCase(task2.getPriority());
}
- private int sortBySummary(ITask element1, ITask element2, int sortDirection) {
- String key1 = element1.getSummary();
- String key2 = element2.getSummary();
+ private int sortBySummary(ITask task1, ITask task2, int sortDirection) {
+ String key1 = task1.getSummary();
+ String key2 = task2.getSummary();
if (key1 == null) {
return (key2 != null) ? sortDirection : 0;
} else if (key2 == null) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/messages.properties
index 85fe46740..cc0eaa6f5 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/messages.properties
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/messages.properties
@@ -19,6 +19,7 @@ DownloadAttachmentJob_Copy_Attachment_to_Clipboard=Copy Attachment to Clipboard
DownloadAttachmentJob_Downloading_Attachment=Downloading Attachment
ImportExportUtil_Tasks_and_queries_Filter0=Mylyn Tasks and Queries (*{0})
SortCriterion_Modification_Date=Modification Date
+SortCriterion_Scheduled_Date=Scheduled Date
SortCriterion_Type=Type
SortKindEntry_Date_Created=Date Created
SortKindEntry_None=None
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListSorter.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListSorter.java
index 7206ed955..2cb87d7c7 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListSorter.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListSorter.java
@@ -99,10 +99,10 @@ public class TaskListSorter extends ViewerSorter {
@Override
public int compare(Viewer compareViewer, Object o1, Object o2) {
if (o1 instanceof AbstractTask && o2 instanceof AbstractTask) {
- // sort of the tasks within the container using the setting from the Sortdialog
+ // sort of the tasks within the container using the setting from the Sort Dialog
ITask element1 = (ITask) o1;
ITask element2 = (ITask) o2;
- return compareElements(element1, element2);
+ return taskComparator.compare(element1, element2);
} else if (o1 instanceof ScheduledTaskContainer && o2 instanceof ScheduledTaskContainer) {
// scheduled Mode compare
ScheduledTaskContainer dateRangeTaskContainer1 = (ScheduledTaskContainer) o1;
@@ -170,7 +170,7 @@ public class TaskListSorter extends ViewerSorter {
weight = 2;
} else {
key.values[0] = getRepositoryUrl(object);
- key.values[1] = weight + ""; //$NON-NLS-1$
+ key.values[1] = Integer.toString(weight);
key.values[2] = ((AbstractTaskContainer) object).getSummary();
weight = 3;
}
@@ -188,20 +188,9 @@ public class TaskListSorter extends ViewerSorter {
.getRepository(repositoryElement.getConnectorKind(), repositoryUrl);
return taskRepository != null ? taskRepository.getRepositoryLabel() : null;
}
-// if (object instanceof UnsubmittedTaskContainer) {
-// return ((UnsubmittedTaskContainer) object).getRepositoryUrl();
-// } else if (object instanceof RepositoryQuery) {
-// return ((RepositoryQuery) object).getRepositoryUrl();
-// } else if (object instanceof UnmatchedTaskContainer) {
-// return ((UnmatchedTaskContainer) object).getRepositoryUrl();
-// }
return null;
}
- private int compareElements(ITask element1, ITask element2) {
- return taskComparator.compare(element1, element2);
- }
-
public TaskComparator getTaskComparator() {
return taskComparator;
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
index 077d657c8..b7340e71c 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
@@ -92,8 +92,6 @@ import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListViewActionGroup;
import org.eclipse.mylyn.internal.tasks.ui.notifications.TaskListServiceMessageControl;
import org.eclipse.mylyn.internal.tasks.ui.search.AbstractSearchHandler;
import org.eclipse.mylyn.internal.tasks.ui.search.SearchUtil;
-import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion;
-import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion.SortKey;
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
@@ -128,8 +126,6 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
@@ -197,21 +193,6 @@ public class TaskListView extends AbstractTaskListView implements IPropertyChang
public static final String LABEL_VIEW = Messages.TaskListView_Task_List;
- @Deprecated
- private static final String MEMENTO_KEY_SORT_DIRECTION = "sortDirection"; //$NON-NLS-1$
-
- @Deprecated
- private static final String MEMENTO_KEY_SORTER = "sorter"; //$NON-NLS-1$
-
- @Deprecated
- private static final String MEMENTO_KEY_SORTER2 = "sorter2"; //$NON-NLS-1$
-
- @Deprecated
- private static final String MEMENTO_KEY_SORT_INDEX = "sortIndex"; //$NON-NLS-1$
-
- @Deprecated
- private static final String MEMENTO_SORT_INDEX = "org.eclipse.mylyn.tasklist.ui.views.tasklist.sortIndex"; //$NON-NLS-1$
-
private static final String MEMENTO_SORTER = "sorter"; //$NON-NLS-1$
private static final String MEMENTO_LINK_WITH_EDITOR = "linkWithEditor"; //$NON-NLS-1$
@@ -536,11 +517,6 @@ public class TaskListView extends AbstractTaskListView implements IPropertyChang
IMemento sorterMemento = taskListMemento.getChild(MEMENTO_SORTER);
if (sorterMemento != null) {
tableSorter.restoreState(sorterMemento);
- } else {
- sorterMemento = taskListMemento.getChild(MEMENTO_SORT_INDEX);
- if (sorterMemento != null) {
- migrateSorterState(tableSorter, sorterMemento);
- }
}
}
applyPresentation(taskListMemento.getString(MEMENTO_PRESENTATION));
@@ -579,67 +555,6 @@ public class TaskListView extends AbstractTaskListView implements IPropertyChang
getViewer().refresh();
}
- /**
- * Public for testing only.
- */
- public void migrateSorterState(TaskListSorter tableSorter, IMemento sorterMemento) {
- int restoredSortIndex = 0;
- if (sorterMemento != null) {
- int sortDirection = -1;
- IMemento m = sorterMemento.getChild(MEMENTO_KEY_SORTER);
- if (m != null) {
- Integer sortIndexInt = m.getInteger(MEMENTO_KEY_SORT_INDEX);
- if (sortIndexInt != null) {
- restoredSortIndex = sortIndexInt.intValue();
- }
- Integer sortDirInt = m.getInteger(MEMENTO_KEY_SORT_DIRECTION);
- if (sortDirInt != null) {
- sortDirection = sortDirInt.intValue();
- tableSorter.getTaskComparator().getSortCriterion(0).setDirection(sortDirection);
- switch (restoredSortIndex) {
- case 1:
- tableSorter.getTaskComparator().getSortCriterion(0).setKey(SortKey.SUMMARY);
- break;
- case 2:
- tableSorter.getTaskComparator().getSortCriterion(0).setKey(SortKey.DATE_CREATED);
- break;
- case 3:
- tableSorter.getTaskComparator().getSortCriterion(0).setKey(SortKey.TASK_ID);
- break;
- default:
- tableSorter.getTaskComparator().getSortCriterion(0).setKey(SortKey.PRIORITY);
- }
- }
- }
-
- IMemento m2 = sorterMemento.getChild(MEMENTO_KEY_SORTER2);
- if (m2 != null) {
- Integer sortIndexInt = m2.getInteger(MEMENTO_KEY_SORT_INDEX);
- if (sortIndexInt != null) {
- restoredSortIndex = sortIndexInt.intValue();
- }
- Integer sortDirInt = m2.getInteger(MEMENTO_KEY_SORT_DIRECTION);
- if (sortDirInt != null) {
- sortDirection = sortDirInt.intValue();
- tableSorter.getTaskComparator().getSortCriterion(1).setDirection(sortDirection);
- switch (restoredSortIndex) {
- case 1:
- tableSorter.getTaskComparator().getSortCriterion(1).setKey(SortKey.SUMMARY);
- break;
- case 2:
- tableSorter.getTaskComparator().getSortCriterion(1).setKey(SortKey.DATE_CREATED);
- break;
- case 3:
- tableSorter.getTaskComparator().getSortCriterion(1).setKey(SortKey.TASK_ID);
- break;
- default:
- tableSorter.getTaskComparator().getSortCriterion(1).setKey(SortKey.PRIORITY);
- }
- }
- }
- }
- }
-
@Override
public void createPartControl(Composite parent) {
Composite body = new Composite(parent, SWT.NONE);
@@ -913,6 +828,8 @@ public class TaskListView extends AbstractTaskListView implements IPropertyChang
currentPresentation = presentation;
updatePresentationSelectorImage();
+
+ tableSorter.getTaskComparator().presentationChanged(presentation);
} finally {
getViewer().getControl().setRedraw(true);
}
@@ -950,15 +867,6 @@ public class TaskListView extends AbstractTaskListView implements IPropertyChang
layout.setColumnData(columns[i], new ColumnPixelData(columnWidths[i]));
}
- columns[i].addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- SortCriterion criterion = tableSorter.getTaskComparator().getSortCriterion(0);
- criterion.setDirection(criterion.getDirection() * -1);
- getViewer().refresh(false);
- }
- });
columns[i].addControlListener(new ControlListener() {
public void controlResized(ControlEvent e) {
for (int j = 0; j < columnWidths.length; j++) {

Back to the top