### Eclipse Workspace Patch 1.0 #P org.eclipse.mylyn.tasks.tests Index: src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java,v retrieving revision 1.15 diff -u -r1.15 TableSorterTest.java --- src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java 26 Jun 2007 01:16:10 -0000 1.15 +++ src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java 16 Nov 2007 02:49:53 -0000 @@ -10,14 +10,20 @@ import junit.framework.TestCase; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.mylyn.internal.tasks.core.LocalTask; import org.eclipse.mylyn.internal.tasks.core.TaskCategory; +import org.eclipse.mylyn.internal.tasks.ui.views.ITaskListView; import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter; import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; import org.eclipse.mylyn.tasks.core.AbstractTask; +import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryTask; +import org.eclipse.swt.widgets.Control; /** * @author Mik Kersten + * @author George Lindholm */ public class TableSorterTest extends TestCase { @@ -31,4 +37,64 @@ assertEquals(-1, sorter.compare(null, task, category)); assertEquals(1, sorter.compare(null, category, task)); } + + public class EmptyViewer extends Viewer { + public EmptyViewer() { + } + + @Override + public Control getControl() { + return null; + } + + @Override + public Object getInput() { + return null; + } + + @Override + public ISelection getSelection() { + return null; + } + + @Override + public void refresh() { + } + + @Override + public void setInput(Object input) { + } + + @Override + public void setSelection(ISelection selection, boolean reveal) { + } + } + + public class EmptyTaskListView implements ITaskListView { + public boolean isFocusedMode() { + return false; + } + + public int getSortDirection() { + return 1; + } + } + + public void testSummaryOrderSorting() { + final ITaskListView etlv = new EmptyTaskListView(); + final TaskListTableSorter sorter = new TaskListTableSorter(etlv, TaskListTableSorter.SortByIndex.PRIORITY); + + final MockRepositoryTask[] tasks = new MockRepositoryTask[5]; + tasks[0] = new MockRepositoryTask("local", "4", "c"); + tasks[1] = new MockRepositoryTask("local", "1", "b"); + tasks[2] = new MockRepositoryTask("local", "1", "a"); + tasks[3] = new MockRepositoryTask("local", "3", "c"); + tasks[4] = new MockRepositoryTask("local", "5", "a"); + + sorter.sort(new EmptyViewer(), tasks); + + assertTrue("1".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary())); + assertTrue("5".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary())); + } + } #P org.eclipse.mylyn.context.ui Index: src/org/eclipse/mylyn/internal/context/ui/TaskListInterestSorter.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/TaskListInterestSorter.java,v retrieving revision 1.23 diff -u -r1.23 TaskListInterestSorter.java --- src/org/eclipse/mylyn/internal/context/ui/TaskListInterestSorter.java 28 Aug 2007 03:55:27 -0000 1.23 +++ src/org/eclipse/mylyn/internal/context/ui/TaskListInterestSorter.java 16 Nov 2007 02:49:54 -0000 @@ -186,9 +186,7 @@ } private int compareKeys(AbstractTaskContainer element1, AbstractTaskContainer element2) { - String summary1 = TaskListTableSorter.getSortableSummaryFromElement(element1); - String summary2 = TaskListTableSorter.getSortableSummaryFromElement(element2); - return taskKeyComparator.compare(summary1, summary2); + return taskKeyComparator.compare(TaskListTableSorter.getSortableFromElement(element1), TaskListTableSorter.getSortableFromElement(element2)); } private int comparePriorities(AbstractTaskContainer element1, AbstractTaskContainer element2) { #P org.eclipse.mylyn.tasks.ui Index: src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java,v retrieving revision 1.30 diff -u -r1.30 TaskListTableSorter.java --- src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java 27 Aug 2007 01:04:13 -0000 1.30 +++ src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java 16 Nov 2007 02:49:54 -0000 @@ -29,13 +29,13 @@ PRIORITY, SUMMARY, DATE_CREATED; } - private final TaskListView view; + private final ITaskListView view; private TaskKeyComparator taskKeyComparator = new TaskKeyComparator(); private SortByIndex sortByIndex; - public TaskListTableSorter(TaskListView view, SortByIndex sortByIndex) { + public TaskListTableSorter(ITaskListView view, SortByIndex sortByIndex) { super(); this.view = view; this.sortByIndex = sortByIndex; @@ -90,7 +90,7 @@ if (!(o1 instanceof AbstractTask)) { if (o2 instanceof AbstractTaskContainer || o2 instanceof AbstractRepositoryQuery) { - return this.view.sortDirection + return this.view.getSortDirection() * ((AbstractTaskContainer) o1).getSummary().compareToIgnoreCase( ((AbstractTaskContainer) o2).getSummary()); } else { @@ -113,10 +113,12 @@ private int compareElements(AbstractTaskContainer element1, AbstractTaskContainer element2) { if (SortByIndex.PRIORITY.equals(sortByIndex)) { - int result = this.view.sortDirection * element1.getPriority().compareTo(element2.getPriority()); + int result = this.view.getSortDirection() * element1.getPriority().compareTo(element2.getPriority()); if (result != 0) { return result; } + return sortBySummary(element1, element2); + } else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) { AbstractTask t1 = null; AbstractTask t2 = null; @@ -132,14 +134,28 @@ } } } else { - String summary1 = getSortableSummaryFromElement(element1); - String summary2 = getSortableSummaryFromElement(element2); - element2.getSummary(); - return this.view.sortDirection * taskKeyComparator.compare(summary1, summary2); + return sortBySummary(element1, element2); } return 0; } + /** + * Determine the sort order of two tasks by id/summary + * @param element1 + * @param element2 + * @return sort order + */ + private int sortBySummary(AbstractTaskContainer element1, AbstractTaskContainer element2) { + return this.view.getSortDirection() + * taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2)); + } + + /** + * Return a sortable string in the format "key: summary" + * @param element + * @return sortable string + * @deprecated Use getSortableFromElement() + */ public static String getSortableSummaryFromElement(AbstractTaskContainer element) { String summary = element.getSummary(); @@ -151,4 +167,22 @@ } return summary; } + + /** + * Return a array of values to pass to taskKeyComparator.compare() for sorting + * @param element + * @return String array[key, summary, ""] + */ + public static String[] getSortableFromElement(AbstractTaskContainer element) { + final String a[] = new String[] {"", element.getSummary(), ""}; + + if (element instanceof AbstractTask) { + AbstractTask task1 = (AbstractTask) element; + if (task1.getTaskKey() != null) { + a[0] = task1.getTaskKey(); + } + } + return a; + } + } Index: src/org/eclipse/mylyn/internal/tasks/ui/views/TaskKeyComparator.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskKeyComparator.java,v retrieving revision 1.7 diff -u -r1.7 TaskKeyComparator.java --- src/org/eclipse/mylyn/internal/tasks/ui/views/TaskKeyComparator.java 26 Jun 2007 01:16:39 -0000 1.7 +++ src/org/eclipse/mylyn/internal/tasks/ui/views/TaskKeyComparator.java 16 Nov 2007 02:49:54 -0000 @@ -21,31 +21,35 @@ public int compare(String o1, String o2) { String[] a1 = split(o1); String[] a2 = split(o2); + return compare(a1, a2); + } + + public int compare(final String a1[], final String a2[]) { + return compare(a1[0], a1[1], a1[2], a2[0], a2[1], a2[2]); + } - String s1 = a1[0]; - String s2 = a2[0]; - if (s1 == null && s2 != null) + public int compare(final String key1, final String value1, final String arb1, final String key2, + final String value2, final String arb2) { + if (key1 == null && key2 != null) return -1; - if (s1 != null && s2 == null) + if (key1 != null && key2 == null) return 1; - if (s1 != null && s2 != null) { - int n = s1.compareToIgnoreCase(s2); + if (key1 != null && key2 != null) { + int n = key1.compareToIgnoreCase(key2); if (n != 0) return n; - s1 = a1[1]; - s2 = a2[1]; - if (s1.length() == s2.length() || s1.length() == 0 || s2.length() == 0) { - n = s1.compareTo(s2); + if (value1.length() == value2.length() || value1.length() == 0 || value2.length() == 0) { + n = value1.compareTo(value2); } else { - n = Integer.valueOf(s1).compareTo(Integer.valueOf(s2)); + n = Integer.valueOf(value1).compareTo(Integer.valueOf(value2)); } if (n != 0) return n; } - return a1[2].compareToIgnoreCase(a2[2]); + return arb1.compareToIgnoreCase(arb2); } public String[] split(String s) { Index: src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java,v retrieving revision 1.205 diff -u -r1.205 TaskListView.java --- src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java 15 Nov 2007 02:26:06 -0000 1.205 +++ src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java 16 Nov 2007 02:49:55 -0000 @@ -157,7 +157,7 @@ * @author Ken Sueda * @author Eugene Kuleshov */ -public class TaskListView extends ViewPart implements IPropertyChangeListener { +public class TaskListView extends ViewPart implements IPropertyChangeListener, ITaskListView { public static final String ID = "org.eclipse.mylyn.tasks.ui.views.tasks"; @@ -1297,7 +1297,7 @@ /** * Recursive function that checks for the occurrence of a certain task taskId. All children of the supplied node * will be checked. - * + * * @param task * The ITask object that is to be searched. * @param taskId @@ -1578,6 +1578,10 @@ getViewer().setSorter(new TaskListTableSorter(this, sortByIndex)); } + public int getSortDirection() { + return sortDirection; + } + public void setSortDirection(int sortDirection) { this.sortDirection = sortDirection; getViewer().setSorter(new TaskListTableSorter(this, sortByIndex)); Index: src/org/eclipse/mylyn/internal/tasks/ui/views/ITaskListView.java =================================================================== RCS file: src/org/eclipse/mylyn/internal/tasks/ui/views/ITaskListView.java diff -N src/org/eclipse/mylyn/internal/tasks/ui/views/ITaskListView.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/mylyn/internal/tasks/ui/views/ITaskListView.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Mylyn project committers 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 + *******************************************************************************/ + +package org.eclipse.mylyn.internal.tasks.ui.views; +/** + * @author George Lindholm + */ +public interface ITaskListView { + public int getSortDirection(); + + public boolean isFocusedMode(); +}