Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 116103 Details for
Bug 216150
2nd level sorting in Search view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
poc with patch for 231336
patch216150.txt (text/plain), 76.37 KB, created by
Frank Becker
on 2008-10-24 15:42:43 EDT
(
hide
)
Description:
poc with patch for 231336
Filename:
MIME Type:
Creator:
Frank Becker
Created:
2008-10-24 15:42:43 EDT
Size:
76.37 KB
patch
obsolete
>### 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.21 >diff -u -r1.21 TableSorterTest.java >--- src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java 21 Sep 2008 03:36:28 -0000 1.21 >+++ src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java 24 Oct 2008 19:39:25 -0000 >@@ -24,10 +24,10 @@ > import org.eclipse.mylyn.internal.tasks.core.TaskCategory; > import org.eclipse.mylyn.internal.tasks.core.WeekDateRange; > import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; > import org.eclipse.mylyn.internal.tasks.ui.views.TaskListInterestSorter; > import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter; > import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex; > import org.eclipse.mylyn.tasks.core.ITask; > import org.eclipse.mylyn.tasks.tests.connector.MockTask; > import org.eclipse.swt.widgets.Control; >@@ -40,7 +40,7 @@ > > public void testRootTaskSorting() { > TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective(), >- TaskListTableSorter.SortByIndex.SUMMARY); >+ TaskComparator.SortByIndex.SUMMARY); > > ITask task = new LocalTask("1", ""); > TaskCategory category = new TaskCategory("cat"); >@@ -114,7 +114,7 @@ > tasks[5] = new MockTask("local", "5", "a"); > > TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective()); >- sorter.setSortByIndex(SortByIndex.SUMMARY); >+ sorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY); > sorter.sort(new EmptyViewer(), tasks); > > assertEquals("1", tasks[0].getTaskKey()); >@@ -136,7 +136,7 @@ > tasks[4] = new MockTask("local", "MYLN:5", "a"); > > TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective()); >- sorter.setSortByIndex(SortByIndex.SUMMARY); >+ sorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY); > sorter.sort(new EmptyViewer(), tasks); > > assertEquals("MYLN:1", tasks[0].getTaskKey()); >#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.49 >diff -u -r1.49 TaskListTableSorter.java >--- src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java 14 Oct 2008 21:24:22 -0000 1.49 >+++ src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java 24 Oct 2008 19:39:26 -0000 >@@ -11,54 +11,43 @@ > > package org.eclipse.mylyn.internal.tasks.ui.views; > >-import java.util.Date; >- > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.viewers.Viewer; > import org.eclipse.jface.viewers.ViewerSorter; > import org.eclipse.mylyn.internal.tasks.core.AbstractTask; >+import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory; > import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer; >+import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; > import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer; >+import org.eclipse.mylyn.internal.tasks.core.TaskGroup; > import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer; > import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; > import org.eclipse.mylyn.tasks.core.IRepositoryElement; >-import org.eclipse.mylyn.tasks.core.IRepositoryQuery; > import org.eclipse.mylyn.tasks.core.ITask; >-import org.eclipse.mylyn.tasks.core.ITaskContainer; > import org.eclipse.ui.PlatformUI; > > /** > * @author Mik Kersten > */ > public class TaskListTableSorter extends ViewerSorter { >+ public static final int DEFAULT_SORT_DIRECTION = 1; > >- public enum SortByIndex { >- PRIORITY, SUMMARY, DATE_CREATED; >- } >- >- private static final int DEFAULT_SORT_DIRECTION = 1; >- >- private int sortDirection = DEFAULT_SORT_DIRECTION; >- >- private SortByIndex sortByIndex = SortByIndex.PRIORITY; >- >- private int sortDirection2 = DEFAULT_SORT_DIRECTION; >- >- private SortByIndex sortByIndex2 = SortByIndex.DATE_CREATED; >+ private int sortDirectionRootElement = DEFAULT_SORT_DIRECTION; > > private final TaskListView view; > >- private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator(); >+ private final TaskComparator taskComparator = new TaskComparator(); > > public TaskListTableSorter(TaskListView view) { > super(); > this.view = view; > } > >- public TaskListTableSorter(TaskListView view, SortByIndex index) { >+ public TaskListTableSorter(TaskListView view, TaskComparator.SortByIndex index) { > super(); > this.view = view; >- this.sortByIndex = index; >+ taskComparator.setSortByIndex(index); > } > > public void setColumn(String column) { >@@ -74,169 +63,50 @@ > */ > @Override > public int compare(Viewer compareViewer, Object o1, Object o2) { >- >- if (o1 instanceof ScheduledTaskContainer && o2 instanceof ScheduledTaskContainer) { >+ if (o1 instanceof AbstractTask && o2 instanceof AbstractTask) { >+ // sort of the tasks within the container using ste setting from the Sortdialog >+ ITask element1 = (ITask) o1; >+ ITask element2 = (ITask) o2; >+ >+ return compareElements(element1, element2); >+ } else if (o1 instanceof ScheduledTaskContainer && o2 instanceof ScheduledTaskContainer) { >+ // scheduled Mode compare > ScheduledTaskContainer dateRangeTaskContainer1 = (ScheduledTaskContainer) o1; > ScheduledTaskContainer dateRangeTaskContainer2 = (ScheduledTaskContainer) o2; >- return dateRangeTaskContainer1.getDateRange().compareTo(dateRangeTaskContainer2.getDateRange()); >-// if (dateRangeTaskContainer1.isCaptureFloating() && !dateRangeTaskContainer2.isCaptureFloating()) { >-// return 1; >-// } else if (!dateRangeTaskContainer1.isCaptureFloating() && dateRangeTaskContainer2.isCaptureFloating()) { >-// return -1; >-// } >-// return -1 * dateRangeTaskContainer2.getStart().compareTo(dateRangeTaskContainer1.getStart()); >- } else if (o1 instanceof ITaskContainer && o2 instanceof ScheduledTaskContainer) { >- return -1; >- } else if (o1 instanceof ScheduledTaskContainer && o2 instanceof ITaskContainer) { >- return 1; >- } >- >- if (o1 instanceof ITaskContainer && o2 instanceof UncategorizedTaskContainer) { >- return 1; >- } else if (o2 instanceof ITaskContainer && o1 instanceof UncategorizedTaskContainer) { >- return -1; >- } >- >- if (o1 instanceof ITaskContainer && o2 instanceof UnmatchedTaskContainer) { >- return -1; >- } else if (o2 instanceof ITaskContainer && o1 instanceof UnmatchedTaskContainer) { >- return 1; >- } >- >- if (!(o1 instanceof ITask) && o2 instanceof ITask) { >- return 1; >- } >+ return this.sortDirectionRootElement >+ * dateRangeTaskContainer1.getDateRange().compareTo(dateRangeTaskContainer2.getDateRange()); >+ } else if (o1 instanceof UnmatchedTaskContainer) { >+ // UnmatchedTaskContainer is always the last entry >+ return this.sortDirectionRootElement * -1; >+ } else if (o2 instanceof UnmatchedTaskContainer) { >+ // UnmatchedTaskContainer is always the last entry >+ return this.sortDirectionRootElement * 1; >+ } else if (o1 instanceof UncategorizedTaskContainer) { >+ // UncategorizedTaskContainer is always the first entry >+ return this.sortDirectionRootElement * 1; >+ } else if (o2 instanceof UncategorizedTaskContainer) { >+ // UncategorizedTaskContainer is always the first entry >+ return this.sortDirectionRootElement * -1; >+ } else if (o1 instanceof TaskGroup && o2 instanceof TaskGroup) { >+ // support for the experimental grouping of tasks >+ TaskGroup taskGroupTaskContainer1 = (TaskGroup) o1; >+ TaskGroup taskGroupTaskContainer2 = (TaskGroup) o2; >+ >+ return this.sortDirectionRootElement >+ * taskGroupTaskContainer1.getSummary().compareToIgnoreCase(taskGroupTaskContainer2.getSummary()); >+ } else if ((o1 instanceof AbstractTaskCategory || o1 instanceof RepositoryQuery) >+ && (o2 instanceof AbstractTaskCategory || o2 instanceof RepositoryQuery)) { >+ AbstractTaskContainer taskContainer1 = (AbstractTaskContainer) o1; >+ AbstractTaskContainer taskContainer2 = (AbstractTaskContainer) o2; > >- if (o1 instanceof ITask && !(o2 instanceof ITaskContainer)) { >- return -1; >- } >- >- // if (o1 instanceof AbstractTaskContainer || o1 instanceof >- // AbstractRepositoryQuery) { >- if (!(o1 instanceof ITask)) { >- if (o2 instanceof ITaskContainer || o2 instanceof IRepositoryQuery) { >- >- return this.sortDirection >- * ((IRepositoryElement) o1).getSummary().compareToIgnoreCase( >- ((IRepositoryElement) o2).getSummary()); >- } else { >- return -1; >- } >- } else if (o1 instanceof ITaskContainer) { >- if (!(o2 instanceof ITask)) { >- return -1; >- } else if (o2 instanceof ITaskContainer) { >- IRepositoryElement element1 = (IRepositoryElement) o1; >- IRepositoryElement element2 = (IRepositoryElement) o2; >- >- return compareElements(element1, element2); >- } >- } else { >- return 0; >+ return this.sortDirectionRootElement >+ * taskContainer1.getSummary().compareToIgnoreCase(taskContainer2.getSummary()); > } > return 0; > } > >- private int compareElements(IRepositoryElement element1, IRepositoryElement element2) { >- if (SortByIndex.PRIORITY.equals(sortByIndex)) { >- int result = sortByPriority(element1, element2, sortDirection); >- if (result != 0) { >- return result; >- } >- >- if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) { >- return sortByDate(element1, element2, sortDirection2); >- } else { >- if (SortByIndex.SUMMARY.equals(sortByIndex2)) { >- return sortBySummary(element1, element2, sortDirection2); >- } else { >- return result; >- } >- } >- } else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) { >- int result = sortByDate(element1, element2, sortDirection); >- if (result != 0) { >- return result; >- } >- if (SortByIndex.PRIORITY.equals(sortByIndex2)) { >- return sortByPriority(element1, element2, sortDirection2); >- } else { >- if (SortByIndex.SUMMARY.equals(sortByIndex2)) { >- return sortBySummary(element1, element2, sortDirection2); >- } else { >- return result; >- } >- } >- } else { >- int result = sortBySummary(element1, element2, sortDirection); >- if (result != 0) { >- return result; >- } >- if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) { >- return sortByDate(element1, element2, sortDirection2); >- } else { >- if (SortByIndex.PRIORITY.equals(sortByIndex2)) { >- return sortByPriority(element1, element2, sortDirection2); >- } else { >- return result; >- } >- } >- } >- } >- >- /** >- * Determine the sort order of two tasks by id/summary >- * >- * @param element1 >- * @param element2 >- * @return sort order >- */ >- private int sortBySummary(IRepositoryElement element1, IRepositoryElement element2, int sortDirection) { >- return sortDirection >- * taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2)); >- } >- >- /** >- * Determine the sort order of two tasks by priority >- * >- * @param element1 >- * @param element2 >- * @return sort order >- */ >- private int sortByPriority(IRepositoryElement element1, IRepositoryElement element2, int sortDirection) { >- return sortDirection >- * ((AbstractTaskContainer) element1).getPriority().compareTo( >- ((AbstractTaskContainer) element2).getPriority()); >- } >- >- /** >- * Determine the sort order of two tasks by creation date >- * >- * @param element1 >- * @param element2 >- * @return sort order >- */ >- private int sortByDate(IRepositoryElement element1, IRepositoryElement element2, int sortDirection) { >- AbstractTask t1 = null; >- AbstractTask t2 = null; >- if (element1 instanceof AbstractTask) { >- t1 = (AbstractTask) element1; >- } >- if (element2 instanceof AbstractTask) { >- t2 = (AbstractTask) element2; >- } >- if (t1 != null && t2 != null) { >- Date creationDate1 = t1.getCreationDate(); >- if (creationDate1 != null) { >- Date creationDate2 = t2.getCreationDate(); >- if (creationDate2 != null) { >- return sortDirection * creationDate1.compareTo(creationDate2); >- } else { >- return 1; >- } >- } >- } >- return 0; >+ private int compareElements(ITask element1, ITask element2) { >+ return taskComparator.compare(element1, element2); > } > > /** >@@ -257,54 +127,69 @@ > return a; > } > >- public SortByIndex getSortByIndex() { >- return sortByIndex; >+ public TaskComparator.SortByIndex getSortByIndex() { >+ return taskComparator.getSortByIndex(); > } > >- public void setSortByIndex(SortByIndex sortByIndex) { >- SortByIndex oldValue = this.sortByIndex; >- this.sortByIndex = sortByIndex; >+ public void setSortByIndex(TaskComparator.SortByIndex sortByIndex) { >+ TaskComparator.SortByIndex oldValue = taskComparator.getSortByIndex(); > if (!oldValue.equals(sortByIndex)) { >- view.getViewer().refresh(); >+ taskComparator.setSortByIndex(sortByIndex); > } > > } > > public int getSortDirection() { >- return sortDirection; >+ return taskComparator.getSortDirection(); > } > > public void setSortDirection(int sortDirection) { >- int oldValue = this.sortDirection; >- this.sortDirection = sortDirection; >- if (oldValue != this.sortDirection) { >- view.getViewer().refresh(); >+ int oldValue = taskComparator.getSortDirection(); >+ if (oldValue != sortDirection) { >+ taskComparator.setSortDirection(sortDirection); > } > } > >- public SortByIndex getSortByIndex2() { >- return sortByIndex2; >+ public TaskComparator.SortByIndex getSortByIndex2() { >+ return taskComparator.getSortByIndex2(); > } > >- public void setSortByIndex2(SortByIndex sortByIndex) { >- SortByIndex oldValue = this.sortByIndex2; >- this.sortByIndex2 = sortByIndex; >+ public void setSortByIndex2(TaskComparator.SortByIndex sortByIndex) { >+ TaskComparator.SortByIndex oldValue = taskComparator.getSortByIndex2(); > if (!oldValue.equals(sortByIndex)) { >- view.getViewer().refresh(); >+ taskComparator.setSortByIndex2(sortByIndex); > } > > } > > public int getSortDirection2() { >- return sortDirection2; >+ return taskComparator.getSortDirection2(); > } > > public void setSortDirection2(int sortDirection) { >- int oldValue = this.sortDirection2; >- this.sortDirection2 = sortDirection; >- if (oldValue != this.sortDirection2) { >- view.getViewer().refresh(); >+ int oldValue = taskComparator.getSortDirection2(); >+ if (oldValue != sortDirection) { >+ taskComparator.setSortDirection2(sortDirection); >+ } >+ } >+ >+ public int getSortDirectionRootElement() { >+ return sortDirectionRootElement; >+ } >+ >+ public void setSortDirectionRootElement(int sortDirection) { >+ int oldValue = this.sortDirectionRootElement; >+ this.sortDirectionRootElement = sortDirection; >+ if (oldValue != this.sortDirectionRootElement) { > } > } > >+ public TaskComparator getTaskComparator() { >+ return taskComparator; >+ } >+ >+ public void refreshView() { >+ view.getViewer().refresh(); >+ } >+ > } >Index: src/org/eclipse/mylyn/internal/tasks/ui/views/SortyByDropDownAction.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/SortyByDropDownAction.java,v >retrieving revision 1.10 >diff -u -r1.10 SortyByDropDownAction.java >--- src/org/eclipse/mylyn/internal/tasks/ui/views/SortyByDropDownAction.java 12 Sep 2008 04:19:26 -0000 1.10 >+++ src/org/eclipse/mylyn/internal/tasks/ui/views/SortyByDropDownAction.java 24 Oct 2008 19:39:26 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >-* Copyright (c) 2004, 2008 Tasktop Technologies and others. >+ * Copyright (c) 2004, 2008 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 >@@ -16,7 +16,7 @@ > import org.eclipse.jface.action.IMenuCreator; > import org.eclipse.jface.action.Separator; > import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Menu; > >@@ -74,7 +74,7 @@ > byPriority = new Action("", AS_CHECK_BOX) { > @Override > public void run() { >- taskListView.getSorter().setSortByIndex(SortByIndex.PRIORITY); >+ taskListView.getSorter().setSortByIndex(TaskComparator.SortByIndex.PRIORITY); > byPriority.setChecked(true); > bySummary.setChecked(false); > byDateCreated.setChecked(false); >@@ -88,7 +88,7 @@ > bySummary = new Action("", AS_CHECK_BOX) { > @Override > public void run() { >- taskListView.getSorter().setSortByIndex(SortByIndex.SUMMARY); >+ taskListView.getSorter().setSortByIndex(TaskComparator.SortByIndex.SUMMARY); > byPriority.setChecked(false); > bySummary.setChecked(true); > byDateCreated.setChecked(false); >@@ -101,7 +101,7 @@ > byDateCreated = new Action("", AS_CHECK_BOX) { > @Override > public void run() { >- taskListView.getSorter().setSortByIndex(SortByIndex.DATE_CREATED); >+ taskListView.getSorter().setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED); > byPriority.setChecked(false); > bySummary.setChecked(false); > byDateCreated.setChecked(true); >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.295 >diff -u -r1.295 TaskListView.java >--- src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java 3 Oct 2008 02:39:18 -0000 1.295 >+++ src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java 24 Oct 2008 19:39:27 -0000 >@@ -104,11 +104,11 @@ > import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListSortAction; > import org.eclipse.mylyn.internal.tasks.ui.commands.CollapseAllHandler; > import org.eclipse.mylyn.internal.tasks.ui.editors.TaskListChangeAdapter; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; > import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener; > import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; > import org.eclipse.mylyn.internal.tasks.ui.util.TreeWalker; > import org.eclipse.mylyn.internal.tasks.ui.util.TreeWalker.TreeVisitor; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex; > import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater; > import org.eclipse.mylyn.tasks.core.IRepositoryElement; > import org.eclipse.mylyn.tasks.core.IRepositoryQuery; >@@ -298,6 +298,8 @@ > > private static final String MEMENTO_KEY_SORT_DIRECTION = "sortDirection"; > >+ private static final String MEMENTO_KEY_ROOT_SORT_DIRECTION = "rootSortDirection"; >+ > private static final String MEMENTO_KEY_SORTER = "sorter"; > > private static final String MEMENTO_KEY_SORTER2 = "sorter2"; >@@ -761,6 +763,9 @@ > case DATE_CREATED: > m.putInteger(MEMENTO_KEY_SORT_INDEX, 2); > break; >+ case TASK_ID: >+ m.putInteger(MEMENTO_KEY_SORT_INDEX, 3); >+ break; > default: > m.putInteger(MEMENTO_KEY_SORT_INDEX, 0); > } >@@ -774,6 +779,9 @@ > case DATE_CREATED: > m2.putInteger(MEMENTO_KEY_SORT_INDEX, 2); > break; >+ case TASK_ID: >+ m.putInteger(MEMENTO_KEY_SORT_INDEX, 3); >+ break; > default: > m2.putInteger(MEMENTO_KEY_SORT_INDEX, 0); > } >@@ -781,6 +789,7 @@ > m2.putInteger(MEMENTO_KEY_SORT_DIRECTION, tableSorter.getSortDirection2()); > memento.putString(MEMENTO_LINK_WITH_EDITOR, Boolean.toString(linkWithEditor)); > memento.putString(MEMENTO_PRESENTATION, currentPresentation.getId()); >+ memento.putInteger(MEMENTO_KEY_ROOT_SORT_DIRECTION, tableSorter.getSortDirectionRootElement()); > } > > private void restoreState() { >@@ -803,13 +812,16 @@ > tableSorter.setSortDirection(sortDirection); > switch (restoredSortIndex) { > case 1: >- tableSorter.setSortByIndex(SortByIndex.SUMMARY); >+ tableSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY); > break; > case 2: >- tableSorter.setSortByIndex(SortByIndex.DATE_CREATED); >+ tableSorter.setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED); >+ break; >+ case 3: >+ tableSorter.setSortByIndex(TaskComparator.SortByIndex.TASK_ID); > break; > default: >- tableSorter.setSortByIndex(SortByIndex.PRIORITY); >+ tableSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY); > } > } > } >@@ -826,18 +838,27 @@ > tableSorter.setSortDirection2(sortDirection); > switch (restoredSortIndex) { > case 1: >- tableSorter.setSortByIndex2(SortByIndex.SUMMARY); >+ tableSorter.setSortByIndex2(TaskComparator.SortByIndex.SUMMARY); > break; > case 2: >- tableSorter.setSortByIndex2(SortByIndex.DATE_CREATED); >+ tableSorter.setSortByIndex2(TaskComparator.SortByIndex.DATE_CREATED); >+ break; >+ case 3: >+ tableSorter.setSortByIndex2(TaskComparator.SortByIndex.TASK_ID); > break; > default: >- tableSorter.setSortByIndex2(SortByIndex.PRIORITY); >+ tableSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY); > } > } > } > } > applyPresentation(taskListMemento.getString(MEMENTO_PRESENTATION)); >+ Integer sortOrder = taskListMemento.getInteger(MEMENTO_KEY_ROOT_SORT_DIRECTION); >+ if (sortOrder != null) { >+ tableSorter.setSortDirectionRootElement(sortOrder); >+ } else { >+ tableSorter.setSortDirectionRootElement(TaskListTableSorter.DEFAULT_SORT_DIRECTION); >+ } > } > > if (tableSorter == null) { >@@ -1477,7 +1498,7 @@ > synchronizeAutomatically = new SynchronizeAutomaticallyAction(); > openPreferencesAction = new OpenTasksUiPreferencesAction(); > //filterArchiveCategory = new FilterArchiveContainerAction(this); >- sortDialogAction = new TaskListSortAction(getSite(), this); >+ sortDialogAction = new TaskListSortAction(getSite(), tableSorter); > filterOnPriorityAction = new PriorityDropDownAction(this); > linkWithEditorAction = new LinkWithEditorAction(this); > presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this); >Index: .refactorings/2008/10/43/refactorings.index >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/.refactorings/2008/10/43/refactorings.index,v >retrieving revision 1.2 >diff -u -r1.2 refactorings.index >--- .refactorings/2008/10/43/refactorings.index 23 Oct 2008 04:58:28 -0000 1.2 >+++ .refactorings/2008/10/43/refactorings.index 24 Oct 2008 19:39:26 -0000 >@@ -1,2 +1,4 @@ > 1224453298513 Delete element > 1224737272005 Extract local variable 'repositoryPerson' >+1224872029957 Delete elements >+1224875091596 Delete element >Index: .refactorings/2008/10/43/refactorings.history >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/.refactorings/2008/10/43/refactorings.history,v >retrieving revision 1.2 >diff -u -r1.2 refactorings.history >--- .refactorings/2008/10/43/refactorings.history 23 Oct 2008 04:58:28 -0000 1.2 >+++ .refactorings/2008/10/43/refactorings.history 24 Oct 2008 19:39:26 -0000 >@@ -1,3 +1,3 @@ > <?xml version="1.0" encoding="UTF-8"?> >-<session version="1.0">
<refactoring accessors="true" comment="Delete 1 element(s) from project 'org.eclipse.mylyn.tasks.ui'
- Original project: 'org.eclipse.mylyn.tasks.ui'
- Original element: 'org.eclipse.mylyn.internal.tasks.ui.search.AbstractRepositorySearchQuery.java'" description="Delete element" element1="/src<org.eclipse.mylyn.internal.tasks.ui.search{AbstractRepositorySearchQuery.java" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224453298513" subPackages="false" version="1.0"/>
<refactoring comment="Extract local variable 'repositoryPerson' from expression 'getAttributeMapper().getRepositoryPerson(getTaskAttribute())'
- Original project: 'org.eclipse.mylyn.tasks.ui'
- Variable name: 'repositoryPerson'
- Destination method: 'org.eclipse.mylyn.internal.tasks.ui.editors.PersonAttributeEditor.getValue()'
- Variable expression: 'getAttributeMapper().getRepositoryPerson(getTaskAttribute())'
- Replace occurrences of expression with variable" description="Extract local variable 'repositoryPerson'" final="false" id="org.eclipse.jdt.ui.extract.temp" input="/src<org.eclipse.mylyn.internal.tasks.ui.editors{PersonAttributeEditor.java" name="repositoryPerson" replace="true" selection="987 60" stamp="1224737272005" version="1.0"/> >+<session version="1.0">
<refactoring accessors="true" comment="Delete 1 element(s) from project 'org.eclipse.mylyn.tasks.ui'
- Original project: 'org.eclipse.mylyn.tasks.ui'
- Original element: 'org.eclipse.mylyn.internal.tasks.ui.search.AbstractRepositorySearchQuery.java'" description="Delete element" element1="/src<org.eclipse.mylyn.internal.tasks.ui.search{AbstractRepositorySearchQuery.java" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224453298513" subPackages="false" version="1.0"/>
<refactoring comment="Extract local variable 'repositoryPerson' from expression 'getAttributeMapper().getRepositoryPerson(getTaskAttribute())'
- Original project: 'org.eclipse.mylyn.tasks.ui'
- Variable name: 'repositoryPerson'
- Destination method: 'org.eclipse.mylyn.internal.tasks.ui.editors.PersonAttributeEditor.getValue()'
- Variable expression: 'getAttributeMapper().getRepositoryPerson(getTaskAttribute())'
- Replace occurrences of expression with variable" description="Extract local variable 'repositoryPerson'" final="false" id="org.eclipse.jdt.ui.extract.temp" input="/src<org.eclipse.mylyn.internal.tasks.ui.editors{PersonAttributeEditor.java" name="repositoryPerson" replace="true" selection="987 60" stamp="1224737272005" version="1.0"/>
<refactoring accessors="true" comment="Delete 3 element(s) from project 'org.eclipse.mylyn.tasks.ui'
- Original project: 'org.eclipse.mylyn.tasks.ui'
- Original elements:
 org.eclipse.mylyn.internal.tasks.ui.search.SearchResultSorterDescription.java
 org.eclipse.mylyn.internal.tasks.ui.search.SearchResultSorterId.java
 org.eclipse.mylyn.internal.tasks.ui.search.SearchResultSorterPriority.java" description="Delete elements" element1="/src<org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterDescription.java" element2="/src<org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterId.java" element3="/src<org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterPriority.java" elements="3" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224872029957" subPackages="false" version="1.0"/>
<refactoring accessors="true" comment="Delete 1 element(s) from project 'org.eclipse.mylyn.tasks.ui'
- Original project: 'org.eclipse.mylyn.tasks.ui'
- Original element: 'org.eclipse.mylyn.internal.tasks.ui.dialogs.SortResultSortDialog.java'" description="Delete element" element1="/src<org.eclipse.mylyn.internal.tasks.ui.dialogs{SortResultSortDialog.java" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224875091596" subPackages="false" version="1.0"/> > </session> >\ No newline at end of file >Index: src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskListSortAction.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskListSortAction.java,v >retrieving revision 1.2 >diff -u -r1.2 TaskListSortAction.java >--- src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskListSortAction.java 12 Sep 2008 04:19:23 -0000 1.2 >+++ src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskListSortAction.java 24 Oct 2008 19:39:26 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >-* Copyright (c) 2004, 2008 Tasktop Technologies and others. >+ * Copyright (c) 2004, 2008 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 >@@ -12,8 +12,9 @@ > package org.eclipse.mylyn.internal.tasks.ui.actions; > > import org.eclipse.jface.action.Action; >+import org.eclipse.jface.window.Window; > import org.eclipse.mylyn.internal.tasks.ui.dialogs.TaskListSortDialog; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; >+import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter; > import org.eclipse.ui.IWorkbenchPartSite; > > /** >@@ -23,15 +24,19 @@ > > private final TaskListSortDialog dialog; > >- public TaskListSortAction(IWorkbenchPartSite site, TaskListView taskListView) { >+ TaskListTableSorter taskListTableSorter; >+ >+ public TaskListSortAction(IWorkbenchPartSite site, TaskListTableSorter taskListTableSorter) { > super("Sort..."); > setEnabled(true); >- dialog = new TaskListSortDialog(site, taskListView); >+ dialog = new TaskListSortDialog(site, taskListTableSorter); > } > > @Override > public void run() { >- dialog.open(); >+ if (dialog.open() == Window.OK) { >+ taskListTableSorter.refreshView(); >+ } > } > > } >Index: src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java,v >retrieving revision 1.3 >diff -u -r1.3 TaskListSortDialog.java >--- src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java 12 Sep 2008 04:19:27 -0000 1.3 >+++ src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java 24 Oct 2008 19:39:26 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >-* Copyright (c) 2004, 2008 Tasktop Technologies and others. >+ * Copyright (c) 2004, 2008 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 >@@ -11,257 +11,81 @@ > > package org.eclipse.mylyn.internal.tasks.ui.dialogs; > >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.Comparator; >- > import org.eclipse.jface.window.IShellProvider; >+import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter; > import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Combo; > import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Label; >-import org.eclipse.ui.dialogs.SelectionDialog; >- >-public class TaskListSortDialog extends SelectionDialog { >- private Combo[] priorityCombos; > >- private Button[] ascendingButtons; >+public class TaskListSortDialog extends TaskCompareDialog { > >- private Button[] descendingButtons; >+// private final TaskListView taskListView; > >- private final String[] propertyText; >+ private Button ascendingRootButton; > >- private boolean dirty = false; >+ private Button descendingRootButton; > >- private final TaskListView taskListView; >+ private final TaskListTableSorter taskListTableSorter; > >- public TaskListSortDialog(IShellProvider parentShell, TaskListView taskListView) { >- super(parentShell.getShell()); >- propertyText = new String[3]; >- propertyText[0] = "Priority"; >- propertyText[1] = "Summary"; >- propertyText[2] = "Date Created"; >- this.taskListView = taskListView; >+ public TaskListSortDialog(IShellProvider parentShell, TaskListTableSorter taskListTableSorter) { >+ super(parentShell, taskListTableSorter.getTaskComparator()); >+ this.taskListTableSorter = taskListTableSorter; > setTitle(TaskListView.LABEL_VIEW + " Sorting"); > } > > @Override >- protected Control createDialogArea(Composite parent) { >- Composite composite = (Composite) super.createDialogArea(parent); >- >- initializeDialogUnits(composite); >+ protected void createDialogStartArea(Composite parent) { >+ Label sortByHeader = new Label(parent, SWT.NULL); >+ sortByHeader.setText("Sort order Container:"); >+ >+ ascendingRootButton = new Button(parent, SWT.RADIO); >+ ascendingRootButton.setText("Ascending"); >+ ascendingRootButton.addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ markDirty(); >+ } >+ }); > >- Composite prioritiesArea = new Composite(composite, SWT.NULL); >- prioritiesArea.setLayout(new GridLayout(3, false)); >+ descendingRootButton = new Button(parent, SWT.RADIO); >+ descendingRootButton.setText("Descending"); >+ descendingRootButton.addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ markDirty(); >+ } >+ }); > >- Label sortByLabel = new Label(prioritiesArea, SWT.NULL); >- sortByLabel.setText("Sort order:"); >+ Label sortByLabel = new Label(parent, SWT.NULL); >+ sortByLabel.setText("Sort order within a Container:"); > GridData data = new GridData(); > data.horizontalSpan = 3; > sortByLabel.setLayoutData(data); >- >- ascendingButtons = new Button[2]; >- descendingButtons = new Button[2]; >- priorityCombos = new Combo[2]; >- >- for (int i = 0; i < 2; i++) { >- final int index = i; >- Label numberLabel = new Label(prioritiesArea, SWT.NULL); >- numberLabel.setText("" + (i + 1) + "."); >- priorityCombos[i] = new Combo(prioritiesArea, SWT.READ_ONLY); >- priorityCombos[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- >- Composite directionGroup = new Composite(prioritiesArea, SWT.NONE); >- directionGroup.setLayout(new GridLayout(2, false)); >- ascendingButtons[i] = new Button(directionGroup, SWT.RADIO); >- ascendingButtons[i].setText("Ascending"); >- ascendingButtons[i].addSelectionListener(new SelectionAdapter() { >- @Override >- public void widgetSelected(SelectionEvent e) { >- markDirty(); >- } >- }); >- descendingButtons[i] = new Button(directionGroup, SWT.RADIO); >- descendingButtons[i].setText("Descending"); >- descendingButtons[i].addSelectionListener(new SelectionAdapter() { >- @Override >- public void widgetSelected(SelectionEvent e) { >- markDirty(); >- } >- }); >- if (i < priorityCombos.length - 1) { >- priorityCombos[i].addSelectionListener(new SelectionAdapter() { >- @Override >- public void widgetSelected(SelectionEvent e) { >- int oldSelectionDirection = 1; >- if (descendingButtons[index].getSelection()) { >- oldSelectionDirection = -1; >- } >- ArrayList<String> oldSelectionList = new ArrayList<String>( >- Arrays.asList(priorityCombos[index].getItems())); >- oldSelectionList.removeAll(Arrays.asList(priorityCombos[index + 1].getItems())); >- if (oldSelectionList.size() != 1) { >- return; >- } >- String oldSelection = oldSelectionList.get(0); >- String newSelection = priorityCombos[index].getItem(priorityCombos[index].getSelectionIndex()); >- if (oldSelection.equals(newSelection)) { >- return; >- } >- for (int j = index + 1; j < priorityCombos.length; j++) { >- int newSelectionIndex = priorityCombos[j].indexOf(newSelection); >- //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); >- if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) { >- priorityCombos[j].add(oldSelection, insertionPoint); >- } else { >- priorityCombos[j].add(oldSelection); >- } >- priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection)); >- ascendingButtons[index].setSelection(ascendingButtons[j].getSelection()); >- descendingButtons[index].setSelection(descendingButtons[j].getSelection()); >- ascendingButtons[j].setSelection(oldSelectionDirection == 1); >- descendingButtons[j].setSelection(oldSelectionDirection == -1); >- } >- //this combo contains newSelection >- else if (newSelectionIndex >= 0) { >- String currentText = priorityCombos[j].getText(); >- priorityCombos[j].remove(newSelection); >- 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)); >- } else { >- priorityCombos[j].add(oldSelection); >- } >- } >- } >- markDirty(); >- } >- }); >- } else { >- priorityCombos[i].addSelectionListener(new SelectionAdapter() { >- @Override >- public void widgetSelected(SelectionEvent e) { >- markDirty(); >- } >- }); >- } >- >- } >- int a[] = new int[2]; >- int b[] = new int[2]; >- switch (taskListView.getSorter().getSortByIndex()) { >- case PRIORITY: >- a[0] = 0; >- break; >- case SUMMARY: >- a[0] = 1; >- break; >- case DATE_CREATED: >- a[0] = 2; >- break; >- } >- >- switch (taskListView.getSorter().getSortByIndex2()) { >- case PRIORITY: >- a[1] = 0; >- break; >- case SUMMARY: >- a[1] = 1; >- break; >- case DATE_CREATED: >- a[1] = 2; >- break; >- } >- b[0] = taskListView.getSorter().getSortDirection(); >- b[1] = taskListView.getSorter().getSortDirection2(); >- updateUI(a, b); >- return composite; > } > > @Override > protected void okPressed() { > if (isDirty()) { >- taskListView.getSorter().setSortByIndex( >- SortByIndex.valueOf(priorityCombos[0].getItem(priorityCombos[0].getSelectionIndex()).replace(' ', >- '_').toUpperCase())); >- taskListView.getSorter().setSortByIndex2( >- SortByIndex.valueOf(priorityCombos[1].getItem(priorityCombos[1].getSelectionIndex()).replace(' ', >- '_').toUpperCase())); >- if (descendingButtons[0].getSelection()) { >- taskListView.getSorter().setSortDirection(-1); >- } else { >- taskListView.getSorter().setSortDirection(1); >- } >- if (descendingButtons[1].getSelection()) { >- taskListView.getSorter().setSortDirection2(-1); >+ if (descendingRootButton.getSelection()) { >+ taskListTableSorter.setSortDirectionRootElement(-1); > } else { >- taskListView.getSorter().setSortDirection2(1); >+ taskListTableSorter.setSortDirectionRootElement(1); > } >- > } > super.okPressed(); > } > >- /** >- * @return boolean >- */ >- public boolean isDirty() { >- return dirty; >- } >- >- /** >- * Sets the dirty flag to true. >- */ >- public void markDirty() { >- dirty = true; >- } >- >- private final Comparator<String> columnComparator = new Comparator<String>() { >- public int compare(String arg0, String arg1) { >- int index0 = -1; >- int index1 = -1; >- for (int i = 0; i < propertyText.length; i++) { >- if (propertyText[i].equals(arg0)) { >- index0 = i; >- } >- if (propertyText[i].equals(arg1)) { >- index1 = i; >- } >- } >- return index0 - index1; >- } >- }; >- >- private void updateUI(int[] priorities, int[] directions) { >- ArrayList<String> availablePriorities = new ArrayList<String>(Arrays.asList(propertyText)); >- >- for (int i = 0; i < priorityCombos.length; i++) { >- priorityCombos[i].removeAll(); >- for (int j = 0; j < availablePriorities.size(); j++) { >- priorityCombos[i].add(availablePriorities.get(j)); >- } >- priorityCombos[i].select(priorityCombos[i].indexOf(propertyText[priorities[i]])); >- availablePriorities.remove(propertyText[priorities[i]]); >- >- ascendingButtons[i].setSelection(directions[i] == 1); >- descendingButtons[i].setSelection(directions[i] == -1); >- } >+ @Override >+ protected void updateUI(int[] priorities, int[] directions) { >+ int headElementDirection = taskListTableSorter.getSortDirectionRootElement(); >+ super.updateUI(priorities, directions); >+ ascendingRootButton.setSelection(headElementDirection == 1); >+ descendingRootButton.setSelection(headElementDirection == -1); > } > > } >Index: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterDescription.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterDescription.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterDescription.java >--- src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterDescription.java 12 Sep 2008 04:19:27 -0000 1.13 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,77 +0,0 @@ >-/******************************************************************************* >-* Copyright (c) 2004, 2008 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.internal.tasks.ui.search; >- >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerSorter; >-import org.eclipse.mylyn.internal.tasks.core.AbstractTask; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator; >-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter; >-import org.eclipse.mylyn.tasks.core.ITask; >- >-/** >- * Sorts search results by summary. >- * >- * @author Rob Elves >- */ >-public class SearchResultSorterDescription extends ViewerSorter { >- >- private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator(); >- >- /** >- * Returns a negative, zero, or positive number depending on whether the first bug's summary goes before, is the >- * same as, or goes after the second element's summary. >- * <p> >- * >- * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, >- * java.lang.Object) >- */ >- @Override >- public int compare(Viewer viewer, Object e1, Object e2) { >- try { >- >- AbstractTask entry1 = (AbstractTask) e1; >- AbstractTask entry2 = (AbstractTask) e2; >- // NOTE we just comparing ids here, once summary and taskId separated >- // they should have their own column/sorter. >- return taskKeyComparator.compare(TaskListTableSorter.getSortableFromElement(entry1), >- TaskListTableSorter.getSortableFromElement(entry2)); >- // return taskKeyComparator.compare(entry1.getDescription(), >- // entry2.getDescription()); >- } catch (Exception ignored) { >- // do nothing >- } >- >- // if that didn't work, use the default compare method >- return super.compare(viewer, e1, e2); >- } >- >- /** >- * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins >- * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort >- * criterion. >- * <p> >- * >- * @see org.eclipse.jface.viewers.ViewerSorter#category(Object) >- */ >- @Override >- public int category(Object element) { >- try { >- ITask hit = (ITask) element; >- return Integer.parseInt(hit.getTaskId()); >- } catch (Exception ignored) { >- // ignore if >- } >- // if that didn't work, use the default category method >- return super.category(element); >- } >-} >Index: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java,v >retrieving revision 1.6 >diff -u -r1.6 SearchResultSortAction.java >--- src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java 12 Sep 2008 04:19:27 -0000 1.6 >+++ src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java 24 Oct 2008 19:39:26 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >-* Copyright (c) 2004, 2008 Tasktop Technologies and others. >+ * Copyright (c) 2004, 2008 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 >@@ -12,6 +12,9 @@ > package org.eclipse.mylyn.internal.tasks.ui.search; > > import org.eclipse.jface.action.Action; >+import org.eclipse.jface.window.IShellProvider; >+import org.eclipse.jface.window.Window; >+import org.eclipse.mylyn.internal.tasks.ui.dialogs.TaskCompareDialog; > > /** > * This class sorts search results by a supplied category. >@@ -20,11 +23,9 @@ > */ > public class SearchResultSortAction extends Action { > >- /** The category that this class sorts Bugzilla search results by. */ >- private final int bugSortOrder; >+ private final TaskCompareDialog dialog; > >- /** The view where the Bugzilla search results are displayed. */ >- private final RepositorySearchResultView bugPage; >+ SearchResultSorter searchResultSorter; > > /** > * Constructor >@@ -36,10 +37,11 @@ > * @param sortOrder > * The category that this class sorts Bugzilla search results by > */ >- public SearchResultSortAction(String label, RepositorySearchResultView page, int sortOrder) { >- super(label); >- bugPage = page; >- bugSortOrder = sortOrder; >+ public SearchResultSortAction(IShellProvider site, SearchResultSorter searchResultSorter) { >+ super("Sort..."); >+ setEnabled(true); >+ dialog = new TaskCompareDialog(site, searchResultSorter.getTaskComparator()); >+ this.searchResultSorter = searchResultSorter; > } > > /** >@@ -47,13 +49,8 @@ > */ > @Override > public void run() { >- bugPage.setSortOrder(bugSortOrder); >- } >- >- /** >- * Returns the category that this class sorts Bugzilla search results by. >- */ >- public int getSortOrder() { >- return bugSortOrder; >+ if (dialog.open() == Window.OK) { >+ searchResultSorter.refreshView(); >+ } > } > } >Index: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterPriority.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterPriority.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterPriority.java >--- src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterPriority.java 12 Sep 2008 04:19:27 -0000 1.10 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,65 +0,0 @@ >-/******************************************************************************* >-* Copyright (c) 2004, 2008 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.internal.tasks.ui.search; >- >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerSorter; >-import org.eclipse.mylyn.tasks.core.ITask; >- >-/** >- * Sorts results of Bugzilla search by bug priority. >- * >- * @author Rob Elves (modifications) >- */ >-public class SearchResultSorterPriority extends ViewerSorter { >- >- /** >- * Returns a negative, zero, or positive number depending on whether the first bug's priority goes before, is the >- * same as, or goes after the second element's priority. >- * <p> >- * >- * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, >- * java.lang.Object) >- */ >- @Override >- public int compare(Viewer viewer, Object e1, Object e2) { >- try { >- ITask hit1 = (ITask) e1; >- ITask hit2 = (ITask) e2; >- return hit1.getPriority().compareTo(hit2.getPriority()); >- } catch (Exception ignored) { >- // do nothing >- } >- // if that didn't work, use the default compare method >- return super.compare(viewer, e1, e2); >- } >- >- /** >- * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins >- * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort >- * criterion. >- * <p> >- * >- * @see org.eclipse.jface.viewers.ViewerSorter#category(Object) >- */ >- @Override >- public int category(Object element) { >- try { >- ITask hit = (ITask) element; >- return Integer.parseInt(hit.getTaskId()); >- } catch (Exception ignored) { >- // ignore if there is a problem >- } >- // if that didn't work, use the default category method >- return super.category(element); >- } >-} >Index: src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResultView.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResultView.java,v >retrieving revision 1.57 >diff -u -r1.57 RepositorySearchResultView.java >--- src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResultView.java 12 Sep 2008 04:19:27 -0000 1.57 >+++ src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResultView.java 24 Oct 2008 19:39:26 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >-* Copyright (c) 2004, 2008 Tasktop Technologies and others. >+ * Copyright (c) 2004, 2008 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 >@@ -39,6 +39,7 @@ > import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; > import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskSearchAction; > import org.eclipse.mylyn.internal.tasks.ui.search.SearchResultTreeContentProvider.GroupBy; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; > import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; > import org.eclipse.mylyn.internal.tasks.ui.views.TaskListToolTip; > import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; >@@ -46,7 +47,6 @@ > import org.eclipse.mylyn.tasks.core.TaskRepository; > import org.eclipse.mylyn.tasks.ui.TasksUi; > import org.eclipse.mylyn.tasks.ui.TasksUiImages; >-import org.eclipse.search.internal.ui.SearchMessages; > import org.eclipse.search.ui.IContextMenuConstants; > import org.eclipse.search.ui.ISearchResult; > import org.eclipse.search.ui.text.AbstractTextSearchViewPage; >@@ -145,9 +145,11 @@ > > private int currentSortOrder; > >- private final SearchResultSortAction sortByPriorityAction; >+// private final SearchResultSortAction sortByPriorityAction; >+// >+// private final SearchResultSortAction sortByDescriptionAction; > >- private final SearchResultSortAction sortByDescriptionAction; >+ private SearchResultSortAction sortByDialogAction; > > private final OpenSearchResultAction openInEditorAction; > >@@ -169,12 +171,15 @@ > } > }; > >+ private SearchResultSorter searchResultSorter; >+ > public RepositorySearchResultView() { > // Only use the table layout. > super(FLAG_LAYOUT_TREE); > >- sortByPriorityAction = new SearchResultSortAction("Task Priority", this, ORDER_PRIORITY); >- sortByDescriptionAction = new SearchResultSortAction("Task Summary", this, ORDER_DESCRIPTION); >+// sortByPriorityAction = new SearchResultSortAction("Task Priority", this, ORDER_PRIORITY); >+// sortByDescriptionAction = new SearchResultSortAction("Task Summary", this, ORDER_DESCRIPTION); >+ > currentSortOrder = ORDER_DEFAULT; > > openInEditorAction = new OpenSearchResultAction("Open in Editor", this); >@@ -233,6 +238,9 @@ > searchResultProvider, viewer), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); > viewer.setLabelProvider(labelProvider); > >+ searchResultSorter = new SearchResultSorter(this); >+ viewer.setSorter(searchResultSorter); >+ sortByDialogAction = new SearchResultSortAction(getSite(), searchResultSorter); > // Set the order when the search view is loading so that the items are > // sorted right away > setSortOrder(currentSortOrder); >@@ -314,27 +322,27 @@ > * The new category to sort by > */ > public void setSortOrder(int sortOrder) { >- StructuredViewer viewer = getViewer(); >- > switch (sortOrder) { > case ORDER_ID: >- viewer.setSorter(new SearchResultSorterId()); >+ searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.TASK_ID); > break; > case ORDER_DESCRIPTION: >- viewer.setSorter(new SearchResultSorterDescription()); >+ searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY); > break; > case ORDER_PRIORITY: >- viewer.setSorter(new SearchResultSorterPriority()); >+ searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY); > break; > default: > // If the setting is not one of the four valid ones, > // use the default order setting. > sortOrder = ORDER_DEFAULT; >- viewer.setSorter(new SearchResultSorterPriority()); >+ searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY); > break; > } > currentSortOrder = sortOrder; > getSettings().put(KEY_SORTING, currentSortOrder); >+// searchResultSorter.refresh(searchResultSorter.getRoot(), updateLabels); >+ this.getViewer().refresh(); > } > > @SuppressWarnings("unchecked") >@@ -359,15 +367,16 @@ > @Override > protected void fillContextMenu(IMenuManager menuManager) { > super.fillContextMenu(menuManager); >- MenuManager sortMenuManager = new MenuManager(SearchMessages.SortDropDownAction_label); >- sortMenuManager.add(sortByPriorityAction); >- sortMenuManager.add(sortByDescriptionAction); >- >- sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder()); >- sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder()); >+// MenuManager sortMenuManager = new MenuManager(SearchMessages.SortDropDownAction_label); >+// sortMenuManager.add(sortByPriorityAction); >+// sortMenuManager.add(sortByDescriptionAction); >+// >+// sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder()); >+// sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder()); > >+ menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortByDialogAction); > // Add the new context menu items >- menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager); >+// menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager); > for (Action action : groupingActions) { > menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, action); > } >Index: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterId.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterId.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterId.java >--- src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterId.java 12 Sep 2008 04:19:27 -0000 1.9 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,73 +0,0 @@ >-/******************************************************************************* >-* Copyright (c) 2004, 2008 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.internal.tasks.ui.search; >- >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerSorter; >-import org.eclipse.mylyn.tasks.core.ITask; >- >-/** >- * Sorts search results (AbstractQueryHit) by taskId. >- */ >-public class SearchResultSorterId extends ViewerSorter { >- >- /** >- * Returns a negative, zero, or positive number depending on whether the first bug's taskId is less than, equal to, >- * or greater than the second bug's taskId. >- * <p> >- * >- * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, >- * java.lang.Object) >- */ >- @Override >- public int compare(Viewer viewer, Object e1, Object e2) { >- try { >- // cast the object and get its bug taskId >- ITask entry1 = (ITask) e1; >- Integer id1 = Integer.parseInt(entry1.getTaskId()); >- >- // cast the other object and get its bug taskId >- ITask entry2 = (ITask) e2; >- Integer id2 = Integer.parseInt(entry2.getTaskId()); >- >- // if neither is null, compare the bug taskId's >- if (id1 != null && id2 != null) { >- return id1.compareTo(id2); >- } >- } catch (Exception ignored) { >- // ignore if there is a problem >- } >- >- // if that didn't work, use the default compare method >- return super.compare(viewer, e1, e2); >- } >- >- /** >- * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins >- * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort >- * criterion. >- * <p> >- * >- * @see org.eclipse.jface.viewers.ViewerSorter#category(Object) >- */ >- @Override >- public int category(Object element) { >- try { >- ITask hit = (ITask) element; >- return Integer.parseInt(hit.getTaskId()); >- } catch (Exception ignored) { >- // ignore >- } >- // if that didn't work, use the default category method >- return super.category(element); >- } >-} >Index: src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,151 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 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.internal.tasks.ui.util; >+ >+import java.util.Comparator; >+ >+import org.eclipse.mylyn.tasks.core.ITask; >+ >+public class TaskComparator implements Comparator<ITask> { >+ >+ public enum SortByIndex { >+ PRIORITY, SUMMARY, DATE_CREATED, TASK_ID; >+ } >+ >+ public static final int DEFAULT_SORT_DIRECTION = 1; >+ >+ private int sortDirection = DEFAULT_SORT_DIRECTION; >+ >+ private SortByIndex sortByIndex = SortByIndex.PRIORITY; >+ >+ private int sortDirection2 = DEFAULT_SORT_DIRECTION; >+ >+ private SortByIndex sortByIndex2 = SortByIndex.DATE_CREATED; >+ >+ public int compare(ITask element1, ITask element2) { >+ if (SortByIndex.PRIORITY.equals(sortByIndex)) { >+ int result = sortByPriority(element1, element2, sortDirection); >+ if (result != 0) { >+ return result; >+ } >+ >+ if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) { >+ return sortByDate(element1, element2, sortDirection2); >+ } else { >+ if (SortByIndex.SUMMARY.equals(sortByIndex2)) { >+ return sortBySummary(element1, element2, sortDirection2); >+ } else if (SortByIndex.TASK_ID.equals(sortByIndex2)) { >+ return sortByID(element1, element2, sortDirection2); >+ } else { >+ return result; >+ } >+ } >+ } else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) { >+ int result = sortByDate(element1, element2, sortDirection); >+ if (result != 0) { >+ return result; >+ } >+ if (SortByIndex.PRIORITY.equals(sortByIndex2)) { >+ return sortByPriority(element1, element2, sortDirection2); >+ } else { >+ if (SortByIndex.SUMMARY.equals(sortByIndex2)) { >+ return sortBySummary(element1, element2, sortDirection2); >+ } else if (SortByIndex.TASK_ID.equals(sortByIndex2)) { >+ return sortByID(element1, element2, sortDirection2); >+ } else { >+ return result; >+ } >+ } >+ } else if (SortByIndex.SUMMARY.equals(sortByIndex)) { >+ int result = sortBySummary(element1, element2, sortDirection); >+ if (result != 0) { >+ return result; >+ } >+ if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) { >+ return sortByDate(element1, element2, sortDirection2); >+ } else { >+ if (SortByIndex.PRIORITY.equals(sortByIndex2)) { >+ return sortByPriority(element1, element2, sortDirection2); >+ } else if (SortByIndex.TASK_ID.equals(sortByIndex2)) { >+ return sortByID(element1, element2, sortDirection2); >+ } else { >+ return result; >+ } >+ } >+ } else { >+ int result = sortByID(element1, element2, sortDirection); >+ if (result != 0) { >+ return result; >+ } >+ if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) { >+ return sortByDate(element1, element2, sortDirection2); >+ } else { >+ if (SortByIndex.PRIORITY.equals(sortByIndex2)) { >+ return sortByPriority(element1, element2, sortDirection2); >+ } else if (SortByIndex.SUMMARY.equals(sortByIndex2)) { >+ return sortBySummary(element1, element2, sortDirection2); >+ } else { >+ return result; >+ } >+ } >+ } >+ } >+ >+ private int sortBySummary(ITask element1, ITask element2, int sortDirection) { >+ return sortDirection * (element1.getSummary().compareTo(element2.getSummary())); >+ } >+ >+ private int sortByID(ITask element1, ITask element2, int sortDirection) { >+ return sortDirection * (element1.getTaskId().compareTo(element2.getTaskId())); >+ } >+ >+ private int sortByPriority(ITask element1, ITask element2, int sortDirection) { >+ return sortDirection * (element1.getPriority().compareTo(element2.getPriority())); >+ } >+ >+ private int sortByDate(ITask element1, ITask element2, int sortDirection) { >+ return sortDirection * (element1.getCreationDate().compareTo(element2.getCreationDate())); >+ } >+ >+ public SortByIndex getSortByIndex() { >+ return sortByIndex; >+ } >+ >+ public void setSortByIndex(SortByIndex sortByIndex) { >+ this.sortByIndex = sortByIndex; >+ } >+ >+ public int getSortDirection() { >+ return sortDirection; >+ } >+ >+ public void setSortDirection(int sortDirection) { >+ this.sortDirection = sortDirection; >+ } >+ >+ public SortByIndex getSortByIndex2() { >+ return sortByIndex2; >+ } >+ >+ public void setSortByIndex2(SortByIndex sortByIndex) { >+ this.sortByIndex2 = sortByIndex; >+ } >+ >+ public int getSortDirection2() { >+ return sortDirection2; >+ } >+ >+ public void setSortDirection2(int sortDirection) { >+ this.sortDirection2 = sortDirection; >+ } >+ >+} >Index: src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,275 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 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.internal.tasks.ui.dialogs; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Comparator; >+ >+import org.eclipse.jface.window.IShellProvider; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; >+import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.ui.dialogs.SelectionDialog; >+ >+public class TaskCompareDialog extends SelectionDialog { >+ private Combo[] priorityCombos; >+ >+ private Button[] ascendingButtons; >+ >+ private Button[] descendingButtons; >+ >+ private final String[] propertyText; >+ >+ private boolean dirty = false; >+ >+ private final TaskComparator taskComparator; >+ >+ public TaskCompareDialog(IShellProvider parentShell, TaskComparator taskComparator) { >+ super(parentShell.getShell()); >+ propertyText = new String[4]; >+ propertyText[0] = "Priority"; >+ propertyText[1] = "Summary"; >+ propertyText[2] = "Date Created"; >+ propertyText[3] = "Task ID"; >+ this.taskComparator = taskComparator; >+ setTitle(TaskListView.LABEL_VIEW + " Sorting"); >+ } >+ >+ protected void createDialogStartArea(Composite parent) { >+ Label sortByLabel = new Label(parent, SWT.NULL); >+ sortByLabel.setText("Sort order:"); >+ GridData data = new GridData(); >+ data.horizontalSpan = 3; >+ sortByLabel.setLayoutData(data); >+ } >+ >+ @Override >+ protected Control createDialogArea(Composite parent) { >+ Composite composite = (Composite) super.createDialogArea(parent); >+ >+ initializeDialogUnits(composite); >+ >+ Composite prioritiesArea = new Composite(composite, SWT.NULL); >+ prioritiesArea.setLayout(new GridLayout(3, false)); >+ >+ createDialogStartArea(prioritiesArea); >+ >+ ascendingButtons = new Button[2]; >+ descendingButtons = new Button[2]; >+ priorityCombos = new Combo[2]; >+ >+ for (int i = 0; i < 2; i++) { >+ final int index = i; >+ Label numberLabel = new Label(prioritiesArea, SWT.NULL); >+ numberLabel.setText("" + (i + 1) + "."); >+ priorityCombos[i] = new Combo(prioritiesArea, SWT.READ_ONLY); >+ priorityCombos[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ Composite directionGroup = new Composite(prioritiesArea, SWT.NONE); >+ directionGroup.setLayout(new GridLayout(2, false)); >+ ascendingButtons[i] = new Button(directionGroup, SWT.RADIO); >+ ascendingButtons[i].setText("Ascending"); >+ ascendingButtons[i].addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ markDirty(); >+ } >+ }); >+ descendingButtons[i] = new Button(directionGroup, SWT.RADIO); >+ descendingButtons[i].setText("Descending"); >+ descendingButtons[i].addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ markDirty(); >+ } >+ }); >+ if (i < priorityCombos.length - 1) { >+ priorityCombos[i].addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ int oldSelectionDirection = 1; >+ if (descendingButtons[index].getSelection()) { >+ oldSelectionDirection = -1; >+ } >+ ArrayList<String> oldSelectionList = new ArrayList<String>( >+ Arrays.asList(priorityCombos[index].getItems())); >+ oldSelectionList.removeAll(Arrays.asList(priorityCombos[index + 1].getItems())); >+ if (oldSelectionList.size() != 1) { >+ return; >+ } >+ String oldSelection = oldSelectionList.get(0); >+ String newSelection = priorityCombos[index].getItem(priorityCombos[index].getSelectionIndex()); >+ if (oldSelection.equals(newSelection)) { >+ return; >+ } >+ for (int j = index + 1; j < priorityCombos.length; j++) { >+ int newSelectionIndex = priorityCombos[j].indexOf(newSelection); >+ //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); >+ if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) { >+ priorityCombos[j].add(oldSelection, insertionPoint); >+ } else { >+ priorityCombos[j].add(oldSelection); >+ } >+ priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection)); >+ ascendingButtons[index].setSelection(ascendingButtons[j].getSelection()); >+ descendingButtons[index].setSelection(descendingButtons[j].getSelection()); >+ ascendingButtons[j].setSelection(oldSelectionDirection == 1); >+ descendingButtons[j].setSelection(oldSelectionDirection == -1); >+ } >+ //this combo contains newSelection >+ else if (newSelectionIndex >= 0) { >+ String currentText = priorityCombos[j].getText(); >+ priorityCombos[j].remove(newSelection); >+ 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)); >+ } else { >+ priorityCombos[j].add(oldSelection); >+ } >+ } >+ } >+ markDirty(); >+ } >+ }); >+ } else { >+ priorityCombos[i].addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ markDirty(); >+ } >+ }); >+ } >+ >+ } >+ int a[] = new int[2]; >+ int b[] = new int[2]; >+ switch (taskComparator.getSortByIndex()) { >+ case PRIORITY: >+ a[0] = 0; >+ break; >+ case SUMMARY: >+ a[0] = 1; >+ break; >+ case DATE_CREATED: >+ a[0] = 2; >+ break; >+ case TASK_ID: >+ a[0] = 3; >+ break; >+ } >+ >+ switch (taskComparator.getSortByIndex2()) { >+ case PRIORITY: >+ a[1] = 0; >+ break; >+ case SUMMARY: >+ a[1] = 1; >+ break; >+ case DATE_CREATED: >+ a[1] = 2; >+ break; >+ case TASK_ID: >+ a[1] = 3; >+ break; >+ } >+ b[0] = taskComparator.getSortDirection(); >+ b[1] = taskComparator.getSortDirection2(); >+ updateUI(a, b); >+ return composite; >+ } >+ >+ @Override >+ protected void okPressed() { >+ if (isDirty()) { >+ taskComparator.setSortByIndex(TaskComparator.SortByIndex.valueOf(priorityCombos[0].getItem( >+ priorityCombos[0].getSelectionIndex()).replace(' ', '_').toUpperCase())); >+ taskComparator.setSortByIndex2(TaskComparator.SortByIndex.valueOf(priorityCombos[1].getItem( >+ priorityCombos[1].getSelectionIndex()).replace(' ', '_').toUpperCase())); >+ if (descendingButtons[0].getSelection()) { >+ taskComparator.setSortDirection(-1); >+ } else { >+ taskComparator.setSortDirection(1); >+ } >+ if (descendingButtons[1].getSelection()) { >+ taskComparator.setSortDirection2(-1); >+ } else { >+ taskComparator.setSortDirection2(1); >+ } >+ >+ } >+ super.okPressed(); >+ } >+ >+ /** >+ * @return boolean >+ */ >+ public boolean isDirty() { >+ return dirty; >+ } >+ >+ /** >+ * Sets the dirty flag to true. >+ */ >+ public void markDirty() { >+ dirty = true; >+ } >+ >+ private final Comparator<String> columnComparator = new Comparator<String>() { >+ public int compare(String arg0, String arg1) { >+ int index0 = -1; >+ int index1 = -1; >+ for (int i = 0; i < propertyText.length; i++) { >+ if (propertyText[i].equals(arg0)) { >+ index0 = i; >+ } >+ if (propertyText[i].equals(arg1)) { >+ index1 = i; >+ } >+ } >+ return index0 - index1; >+ } >+ }; >+ >+ protected void updateUI(int[] priorities, int[] directions) { >+ ArrayList<String> availablePriorities = new ArrayList<String>(Arrays.asList(propertyText)); >+ >+ for (int i = 0; i < priorityCombos.length; i++) { >+ priorityCombos[i].removeAll(); >+ for (int j = 0; j < availablePriorities.size(); j++) { >+ priorityCombos[i].add(availablePriorities.get(j)); >+ } >+ priorityCombos[i].select(priorityCombos[i].indexOf(propertyText[priorities[i]])); >+ availablePriorities.remove(propertyText[priorities[i]]); >+ ascendingButtons[i].setSelection(directions[i] == 1); >+ descendingButtons[i].setSelection(directions[i] == -1); >+ } >+ } >+ >+} >Index: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorter.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorter.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 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.internal.tasks.ui.search; >+ >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerSorter; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator; >+import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator.SortByIndex; >+import org.eclipse.mylyn.tasks.core.ITask; >+ >+public class SearchResultSorter extends ViewerSorter { >+ >+ private final RepositorySearchResultView view; >+ >+ private final TaskComparator taskComparator = new TaskComparator(); >+ >+ public SearchResultSorter(RepositorySearchResultView view) { >+ super(); >+ this.view = view; >+ } >+ >+ /** >+ * Returns a negative, zero, or positive number depending on whether the first bug's taskId is less than, equal to, >+ * or greater than the second bug's taskId. >+ * <p> >+ * >+ * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, >+ * java.lang.Object) >+ */ >+ @Override >+ public int compare(Viewer viewer, Object e1, Object e2) { >+ if (e1 instanceof ITask && e2 instanceof ITask) { >+ ITask entry1 = (ITask) e1; >+ ITask entry2 = (ITask) e2; >+ return taskComparator.compare(entry1, entry2); >+ } else { >+ return super.compare(viewer, e1, e2); >+ } >+ } >+ >+ /** >+ * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins >+ * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort >+ * criterion. >+ * <p> >+ * >+ * @see org.eclipse.jface.viewers.ViewerSorter#category(Object) >+ */ >+ @Override >+ public int category(Object element) { >+ try { >+ ITask hit = (ITask) element; >+ return Integer.parseInt(hit.getTaskId()); >+ } catch (Exception ignored) { >+ // ignore if there is a problem >+ } >+ // if that didn't work, use the default category method >+ return super.category(element); >+ } >+ >+ public int getSortDirection() { >+ return taskComparator.getSortDirection(); >+ } >+ >+ public void setSortDirection(int sortDirection) { >+ taskComparator.setSortDirection(sortDirection); >+ } >+ >+ public SortByIndex getSortByIndex() { >+ return taskComparator.getSortByIndex(); >+ } >+ >+ public void setSortByIndex(SortByIndex sortByIndex) { >+ taskComparator.setSortByIndex(sortByIndex); >+ } >+ >+ public int getSortDirection2() { >+ return taskComparator.getSortDirection2(); >+ } >+ >+ public void setSortDirection2(int sortDirection) { >+ taskComparator.setSortDirection2(sortDirection); >+ } >+ >+ public SortByIndex getSortByIndex2() { >+ return taskComparator.getSortByIndex2(); >+ } >+ >+ public void setSortByIndex2(SortByIndex sortByIndex) { >+ taskComparator.setSortByIndex2(sortByIndex); >+ } >+ >+ public TaskComparator getTaskComparator() { >+ return taskComparator; >+ } >+ >+ public void refreshView() { >+ view.getViewer().refresh(); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 216150
:
89347
|
89348
|
89358
|
89359
|
90557
|
90558
|
90583
|
90584
|
95415
|
95416
| 116103 |
116104
|
130300
|
130301
|
134922