Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 216150 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java (+1 lines)
Lines 63-68 Link Here
63
		suite.addTestSuite(OrphanedTasksTest.class);
63
		suite.addTestSuite(OrphanedTasksTest.class);
64
		suite.addTestSuite(TaskWorkingSetTest.class);
64
		suite.addTestSuite(TaskWorkingSetTest.class);
65
		suite.addTestSuite(TaskActivationHistoryTest.class);
65
		suite.addTestSuite(TaskActivationHistoryTest.class);
66
		suite.addTestSuite(TaskSearchResultSorterTest.class);
66
		// $JUnit-END$
67
		// $JUnit-END$
67
68
68
		// suite.addTestSuite(BackgroundSaveTest.class);
69
		// suite.addTestSuite(BackgroundSaveTest.class);
(-)src/org/eclipse/mylyn/tasks/tests/TaskSearchResultSorterTest.java (+101 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.tasks.tests;
10
11
import junit.framework.TestCase;
12
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.mylyn.internal.tasks.ui.TaskComparator;
16
import org.eclipse.mylyn.internal.tasks.ui.search.TaskSearchResultSorter;
17
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
18
import org.eclipse.swt.widgets.Control;
19
20
public class TaskSearchResultSorterTest extends TestCase {
21
22
	public class EmptyViewer extends Viewer {
23
		public EmptyViewer() {
24
		}
25
26
		@Override
27
		public Control getControl() {
28
			return null;
29
		}
30
31
		@Override
32
		public Object getInput() {
33
			return null;
34
		}
35
36
		@Override
37
		public ISelection getSelection() {
38
			return null;
39
		}
40
41
		@Override
42
		public void refresh() {
43
		}
44
45
		@Override
46
		public void setInput(Object input) {
47
		}
48
49
		@Override
50
		public void setSelection(ISelection selection, boolean reveal) {
51
		}
52
	}
53
54
	public void test2LevelSort() throws Exception {
55
		final TaskSearchResultSorter sorter = new TaskSearchResultSorter();
56
		final MockTask[] tasks = new MockTask[5];
57
		tasks[0] = new MockTask("local", "4", "c");
58
		tasks[1] = new MockTask("local", "1", "b");
59
		tasks[2] = new MockTask("local", "11", "a");
60
		tasks[2].setPriority("P1");
61
		tasks[3] = new MockTask("local", "3", "c");
62
		tasks[4] = new MockTask("local", "5", "a");
63
64
		// sort by PRIORITY then by SUMMARY
65
		sorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
66
		sorter.setSortByIndex2(TaskComparator.SortByIndex.SUMMARY);
67
		sorter.sort(new EmptyViewer(), tasks);
68
		assertTrue("11".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary()));
69
		assertTrue("1".equals(tasks[1].getTaskKey()) && "b".equals(tasks[1].getSummary()));
70
		assertTrue("3".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
71
		assertTrue("4".equals(tasks[3].getTaskKey()) && "c".equals(tasks[3].getSummary()));
72
		assertTrue("5".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary()));
73
74
		// sort by PRIORITY then by SUMMARY descending
75
		sorter.setSortDirection2(-1);
76
		sorter.sort(new EmptyViewer(), tasks);
77
		assertTrue("11".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary()));
78
		assertTrue("1".equals(tasks[4].getTaskKey()) && "b".equals(tasks[4].getSummary()));
79
		assertTrue("3".equals(tasks[3].getTaskKey()) && "c".equals(tasks[3].getSummary()));
80
		assertTrue("4".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
81
		assertTrue("5".equals(tasks[1].getTaskKey()) && "a".equals(tasks[1].getSummary()));
82
83
		// sort by PRIORITY descending then by SUMMARY descending
84
		sorter.setSortDirection(-1);
85
		sorter.sort(new EmptyViewer(), tasks);
86
		assertTrue("11".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary()));
87
		assertTrue("1".equals(tasks[3].getTaskKey()) && "b".equals(tasks[3].getSummary()));
88
		assertTrue("3".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
89
		assertTrue("4".equals(tasks[1].getTaskKey()) && "c".equals(tasks[1].getSummary()));
90
		assertTrue("5".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary()));
91
92
		// sort by PRIORITY descending then by SUMMARY
93
		sorter.setSortDirection2(1);
94
		sorter.sort(new EmptyViewer(), tasks);
95
		assertTrue("11".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary()));
96
		assertTrue("1".equals(tasks[0].getTaskKey()) && "b".equals(tasks[0].getSummary()));
97
		assertTrue("3".equals(tasks[1].getTaskKey()) && "c".equals(tasks[1].getSummary()));
98
		assertTrue("4".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
99
		assertTrue("5".equals(tasks[3].getTaskKey()) && "a".equals(tasks[3].getSummary()));
100
	}
101
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterDescription.java (-73 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.search;
10
11
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.ViewerSorter;
13
import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
14
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter;
15
import org.eclipse.mylyn.tasks.core.AbstractTask;
16
17
/**
18
 * Sorts search results by summary.
19
 * 
20
 * @author Rob Elves
21
 */
22
public class SearchResultSorterDescription extends ViewerSorter {
23
24
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
25
26
	/**
27
	 * Returns a negative, zero, or positive number depending on whether the first bug's summary goes before, is the
28
	 * same as, or goes after the second element's summary.
29
	 * <p>
30
	 * 
31
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
32
	 *      java.lang.Object)
33
	 */
34
	@Override
35
	public int compare(Viewer viewer, Object e1, Object e2) {
36
		try {
37
38
			AbstractTask entry1 = (AbstractTask) e1;
39
			AbstractTask entry2 = (AbstractTask) e2;
40
			// NOTE we just comparing ids here, once summary and taskId separated
41
			// they should have their own column/sorter.
42
			return taskKeyComparator.compare(TaskListTableSorter.getSortableFromElement(entry1),
43
					TaskListTableSorter.getSortableFromElement(entry2));
44
			// return taskKeyComparator.compare(entry1.getDescription(),
45
			// entry2.getDescription());
46
		} catch (Exception ignored) {
47
			// do nothing
48
		}
49
50
		// if that didn't work, use the default compare method
51
		return super.compare(viewer, e1, e2);
52
	}
53
54
	/**
55
	 * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins
56
	 * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort
57
	 * criterion.
58
	 * <p>
59
	 * 
60
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(Object)
61
	 */
62
	@Override
63
	public int category(Object element) {
64
		try {
65
			AbstractTask hit = (AbstractTask) element;
66
			return Integer.parseInt(hit.getTaskId());
67
		} catch (Exception ignored) {
68
			// ignore if
69
		}
70
		// if that didn't work, use the default category method
71
		return super.category(element);
72
	}
73
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java (-2 / +9 lines)
Lines 23-28 Link Here
23
	/** The view where the Bugzilla search results are displayed. */
23
	/** The view where the Bugzilla search results are displayed. */
24
	private final RepositorySearchResultView bugPage;
24
	private final RepositorySearchResultView bugPage;
25
25
26
	private final boolean secondLevel;
27
26
	/**
28
	/**
27
	 * Constructor
29
	 * Constructor
28
	 * 
30
	 * 
Lines 33-42 Link Here
33
	 * @param sortOrder
35
	 * @param sortOrder
34
	 *            The category that this class sorts Bugzilla search results by
36
	 *            The category that this class sorts Bugzilla search results by
35
	 */
37
	 */
36
	public SearchResultSortAction(String label, RepositorySearchResultView page, int sortOrder) {
38
	public SearchResultSortAction(String label, RepositorySearchResultView page, int sortOrder, boolean level2) {
37
		super(label);
39
		super(label);
38
		bugPage = page;
40
		bugPage = page;
39
		bugSortOrder = sortOrder;
41
		bugSortOrder = sortOrder;
42
		secondLevel = level2;
40
	}
43
	}
41
44
42
	/**
45
	/**
Lines 44-50 Link Here
44
	 */
47
	 */
45
	@Override
48
	@Override
46
	public void run() {
49
	public void run() {
47
		bugPage.setSortOrder(bugSortOrder);
50
		if (secondLevel) {
51
			bugPage.setSortOrder2(bugSortOrder);
52
		} else {
53
			bugPage.setSortOrder(bugSortOrder);
54
		}
48
	}
55
	}
49
56
50
	/**
57
	/**
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterPriority.java (-62 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.search;
10
11
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.ViewerSorter;
13
import org.eclipse.mylyn.tasks.core.AbstractTask;
14
15
/**
16
 * Sorts results of Bugzilla search by bug priority.
17
 * 
18
 * @author Rob Elves (modifications)
19
 */
20
public class SearchResultSorterPriority extends ViewerSorter {
21
22
	/**
23
	 * Returns a negative, zero, or positive number depending on whether the first bug's priority goes before, is the
24
	 * same as, or goes after the second element's priority.
25
	 * <p>
26
	 * 
27
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
28
	 *      java.lang.Object)
29
	 */
30
	@Override
31
	public int compare(Viewer viewer, Object e1, Object e2) {
32
		try {
33
			AbstractTask hit1 = (AbstractTask) e1;
34
			AbstractTask hit2 = (AbstractTask) e2;
35
			return hit1.getPriority().compareTo(hit2.getPriority());
36
		} catch (Exception ignored) {
37
			// do nothing
38
		}
39
		// if that didn't work, use the default compare method
40
		return super.compare(viewer, e1, e2);
41
	}
42
43
	/**
44
	 * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins
45
	 * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort
46
	 * criterion.
47
	 * <p>
48
	 * 
49
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(Object)
50
	 */
51
	@Override
52
	public int category(Object element) {
53
		try {
54
			AbstractTask hit = (AbstractTask) element;
55
			return Integer.parseInt(hit.getTaskId());
56
		} catch (Exception ignored) {
57
			// ignore if there is a problem
58
		}
59
		// if that didn't work, use the default category method
60
		return super.category(element);
61
	}
62
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResultView.java (-17 / +108 lines)
Lines 16-21 Link Here
16
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.IMenuManager;
18
import org.eclipse.jface.action.MenuManager;
18
import org.eclipse.jface.action.MenuManager;
19
import org.eclipse.jface.action.Separator;
19
import org.eclipse.jface.viewers.DecoratingLabelProvider;
20
import org.eclipse.jface.viewers.DecoratingLabelProvider;
20
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.jface.viewers.StructuredViewer;
22
import org.eclipse.jface.viewers.StructuredViewer;
Lines 23-28 Link Here
23
import org.eclipse.jface.viewers.TreeViewer;
24
import org.eclipse.jface.viewers.TreeViewer;
24
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
25
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
25
import org.eclipse.mylyn.internal.tasks.ui.AddExistingTaskJob;
26
import org.eclipse.mylyn.internal.tasks.ui.AddExistingTaskJob;
27
import org.eclipse.mylyn.internal.tasks.ui.TaskComparator;
26
import org.eclipse.mylyn.internal.tasks.ui.TaskListPatternFilter;
28
import org.eclipse.mylyn.internal.tasks.ui.TaskListPatternFilter;
27
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
29
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
28
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
30
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
Lines 31-37 Link Here
31
import org.eclipse.mylyn.tasks.core.TaskRepository;
33
import org.eclipse.mylyn.tasks.core.TaskRepository;
32
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
34
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
33
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
35
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
34
import org.eclipse.search.internal.ui.SearchMessages;
35
import org.eclipse.search.ui.IContextMenuConstants;
36
import org.eclipse.search.ui.IContextMenuConstants;
36
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
37
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
37
import org.eclipse.search.ui.text.Match;
38
import org.eclipse.search.ui.text.Match;
Lines 54-59 Link Here
54
 * @author Rob Elves
55
 * @author Rob Elves
55
 * @author Mik Kersten
56
 * @author Mik Kersten
56
 * @author Shawn Minto
57
 * @author Shawn Minto
58
 * @author Frank Becker (https://bugs.eclipse.org/bugs/show_bug.cgi?taskId=216150)
57
 */
59
 */
58
public class RepositorySearchResultView extends AbstractTextSearchViewPage implements IAdaptable {
60
public class RepositorySearchResultView extends AbstractTextSearchViewPage implements IAdaptable {
59
61
Lines 63-94 Link Here
63
65
64
	public static final int ORDER_DESCRIPTION = 2;
66
	public static final int ORDER_DESCRIPTION = 2;
65
67
66
	public static final int ORDER_SEVERITY = 3;
68
	public static final int ORDER_DATE_CREATED = 3;
67
68
	public static final int ORDER_STATUS = 4;
69
70
	public static final int ORDER_ID = 5;
71
69
72
	public static final int ORDER_DEFAULT = ORDER_PRIORITY;
70
	public static final int ORDER_DEFAULT = ORDER_PRIORITY;
73
71
72
	public static final int ORDER2_DEFAULT = ORDER_DESCRIPTION;
73
74
	private static final String KEY_SORTING = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting"; //$NON-NLS-1$
74
	private static final String KEY_SORTING = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting"; //$NON-NLS-1$
75
75
76
	private static final String KEY_SORTING2 = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting.then"; //$NON-NLS-1$
77
76
	private SearchResultContentProvider searchResultProvider;
78
	private SearchResultContentProvider searchResultProvider;
77
79
78
	private int currentSortOrder;
80
	private int currentSortOrder;
79
81
82
	private int currentSortOrder2;
83
80
	private final SearchResultSortAction sortByPriorityAction;
84
	private final SearchResultSortAction sortByPriorityAction;
81
85
82
	private final SearchResultSortAction sortByDescriptionAction;
86
	private final SearchResultSortAction sortByDescriptionAction;
83
87
88
	private final SearchResultSortAction sortByDateCreated;
89
90
	private final SearchResultSortAction sortByPriorityAction2;
91
92
	private final SearchResultSortAction sortByDescriptionAction2;
93
94
	private final SearchResultSortAction sortByDateCreated2;
95
84
	private final OpenSearchResultAction openInEditorAction;
96
	private final OpenSearchResultAction openInEditorAction;
85
97
86
	private final CreateQueryFromSearchAction addTaskListAction;
98
	private final CreateQueryFromSearchAction addTaskListAction;
87
99
100
	private final SearchResultSortDirection sortDirection;
101
102
	private final SearchResultSortDirection sortDirection2;
103
88
	private static final String[] SHOW_IN_TARGETS = new String[] { IPageLayout.ID_RES_NAV };
104
	private static final String[] SHOW_IN_TARGETS = new String[] { IPageLayout.ID_RES_NAV };
89
105
90
	private final Action groupByAction;
106
	private final Action groupByAction;
91
107
108
	private TaskSearchResultSorter taskSearchResultSorter;
109
92
	private static final IShowInTargetList SHOW_IN_TARGET_LIST = new IShowInTargetList() {
110
	private static final IShowInTargetList SHOW_IN_TARGET_LIST = new IShowInTargetList() {
93
		public String[] getShowInTargetIds() {
111
		public String[] getShowInTargetIds() {
94
			return SHOW_IN_TARGETS;
112
			return SHOW_IN_TARGETS;
Lines 99-107 Link Here
99
		// Only use the table layout.
117
		// Only use the table layout.
100
		super(FLAG_LAYOUT_TREE);
118
		super(FLAG_LAYOUT_TREE);
101
119
102
		sortByPriorityAction = new SearchResultSortAction("Task Priority", this, ORDER_PRIORITY);
120
		sortByPriorityAction = new SearchResultSortAction("Priority", this, ORDER_PRIORITY, false);
103
		sortByDescriptionAction = new SearchResultSortAction("Task Summary", this, ORDER_DESCRIPTION);
121
		sortByPriorityAction.setImageDescriptor(TasksUiImages.PRIORITY_1);
122
		sortByDescriptionAction = new SearchResultSortAction("Summary", this, ORDER_DESCRIPTION, false);
123
		sortByDateCreated = new SearchResultSortAction("Date Created", this, ORDER_DATE_CREATED, false);
124
		sortByDateCreated.setImageDescriptor(TasksUiImages.CALENDAR_SMALL);
104
		currentSortOrder = ORDER_DEFAULT;
125
		currentSortOrder = ORDER_DEFAULT;
126
		sortByPriorityAction2 = new SearchResultSortAction("Priority", this, ORDER_PRIORITY, true);
127
		sortByPriorityAction2.setImageDescriptor(TasksUiImages.PRIORITY_1);
128
		sortByDescriptionAction2 = new SearchResultSortAction("Summary", this, ORDER_DESCRIPTION, true);
129
		sortByDateCreated2 = new SearchResultSortAction("Date Created", this, ORDER_DATE_CREATED, true);
130
		sortByDateCreated2.setImageDescriptor(TasksUiImages.CALENDAR_SMALL);
131
		currentSortOrder2 = ORDER2_DEFAULT;
132
		sortDirection = new SearchResultSortDirection("Descending", this, false);
133
		sortDirection2 = new SearchResultSortDirection("Descending", this, true);
105
134
106
		openInEditorAction = new OpenSearchResultAction("Open in Editor", this);
135
		openInEditorAction = new OpenSearchResultAction("Open in Editor", this);
107
		addTaskListAction = new CreateQueryFromSearchAction("Create Query from Search...", this);
136
		addTaskListAction = new CreateQueryFromSearchAction("Create Query from Search...", this);
Lines 159-165 Link Here
159
188
160
		// Set the order when the search view is loading so that the items are
189
		// Set the order when the search view is loading so that the items are
161
		// sorted right away
190
		// sorted right away
191
		taskSearchResultSorter = new TaskSearchResultSorter();
192
		viewer.setSorter(taskSearchResultSorter);
162
		setSortOrder(currentSortOrder);
193
		setSortOrder(currentSortOrder);
194
		setSortOrder2(currentSortOrder2);
163
	}
195
	}
164
196
165
	@Override
197
	@Override
Lines 230-256 Link Here
230
	 *            The new category to sort by
262
	 *            The new category to sort by
231
	 */
263
	 */
232
	public void setSortOrder(int sortOrder) {
264
	public void setSortOrder(int sortOrder) {
233
		StructuredViewer viewer = getViewer();
234
235
		switch (sortOrder) {
265
		switch (sortOrder) {
236
		case ORDER_ID:
237
			viewer.setSorter(new SearchResultSorterId());
238
			break;
239
		case ORDER_DESCRIPTION:
266
		case ORDER_DESCRIPTION:
240
			viewer.setSorter(new SearchResultSorterDescription());
267
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
241
			break;
268
			break;
242
		case ORDER_PRIORITY:
269
		case ORDER_PRIORITY:
243
			viewer.setSorter(new SearchResultSorterPriority());
270
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
271
			break;
272
		case ORDER_DATE_CREATED:
273
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED);
244
			break;
274
			break;
245
		default:
275
		default:
246
			// If the setting is not one of the four valid ones,
276
			// If the setting is not one of the four valid ones,
247
			// use the default order setting.
277
			// use the default order setting.
248
			sortOrder = ORDER_DEFAULT;
278
			sortOrder = ORDER_DEFAULT;
249
			viewer.setSorter(new SearchResultSorterPriority());
279
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
250
			break;
280
			break;
251
		}
281
		}
252
		currentSortOrder = sortOrder;
282
		currentSortOrder = sortOrder;
253
		getSettings().put(KEY_SORTING, currentSortOrder);
283
		getSettings().put(KEY_SORTING, currentSortOrder);
284
285
		getViewer().refresh();
286
	}
287
288
	public void setSortOrder2(int sortOrder) {
289
		switch (sortOrder) {
290
		case ORDER_DESCRIPTION:
291
			taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.SUMMARY);
292
			break;
293
		case ORDER_PRIORITY:
294
			taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY);
295
			break;
296
		case ORDER_DATE_CREATED:
297
			taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.DATE_CREATED);
298
			break;
299
		default:
300
			// If the setting is not one of the four valid ones,
301
			// use the default order setting.
302
			sortOrder = ORDER_DEFAULT;
303
			taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY);
304
			break;
305
		}
306
		currentSortOrder2 = sortOrder;
307
		getSettings().put(KEY_SORTING2, currentSortOrder2);
308
		getViewer().refresh();
309
	}
310
311
	public void setSortDirection(int sortDirection) {
312
		taskSearchResultSorter.setSortDirection(sortDirection);
313
		getViewer().refresh();
314
	}
315
316
	public int getSortDirection() {
317
		return taskSearchResultSorter.getSortDirection();
318
	}
319
320
	public void setSortDirection2(int sortDirection) {
321
		taskSearchResultSorter.setSortDirection2(sortDirection);
322
		getViewer().refresh();
323
	}
324
325
	public int getSortDirection2() {
326
		return taskSearchResultSorter.getSortDirection2();
254
	}
327
	}
255
328
256
	@SuppressWarnings("unchecked")
329
	@SuppressWarnings("unchecked")
Lines 276-290 Link Here
276
	@Override
349
	@Override
277
	protected void fillContextMenu(IMenuManager menuManager) {
350
	protected void fillContextMenu(IMenuManager menuManager) {
278
		super.fillContextMenu(menuManager);
351
		super.fillContextMenu(menuManager);
279
		MenuManager sortMenuManager = new MenuManager(SearchMessages.SortDropDownAction_label);
352
		MenuManager sortMenuManager = new MenuManager("First Sort by");
280
		sortMenuManager.add(sortByPriorityAction);
353
		sortMenuManager.add(sortByPriorityAction);
281
		sortMenuManager.add(sortByDescriptionAction);
354
		sortMenuManager.add(sortByDescriptionAction);
355
		sortMenuManager.add(sortByDateCreated);
356
		sortMenuManager.add(new Separator());
357
		sortMenuManager.add(sortDirection);
282
358
283
		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
359
		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
284
		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
360
		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
361
		sortByDateCreated.setChecked(currentSortOrder == sortByDateCreated.getSortOrder());
362
		sortDirection.setChecked(getSortDirection() < 0);
363
364
		MenuManager sortMenuManager2 = new MenuManager("Then Sort by");
365
		sortMenuManager2.add(sortByPriorityAction2);
366
		sortMenuManager2.add(sortByDescriptionAction2);
367
		sortMenuManager2.add(sortByDateCreated2);
368
		sortMenuManager2.add(new Separator());
369
		sortMenuManager2.add(sortDirection2);
370
371
		sortByPriorityAction2.setChecked(currentSortOrder2 == sortByPriorityAction2.getSortOrder());
372
		sortByDescriptionAction2.setChecked(currentSortOrder2 == sortByDescriptionAction2.getSortOrder());
373
		sortByDateCreated2.setChecked(currentSortOrder2 == sortByDateCreated2.getSortOrder());
374
		sortDirection2.setChecked(getSortDirection2() < 0);
285
375
286
		// Add the new context menu items
376
		// Add the new context menu items
287
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
377
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
378
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager2);
288
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, groupByAction);
379
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, groupByAction);
289
380
290
		menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, openInEditorAction);
381
		menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, openInEditorAction);
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterId.java (-70 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.search;
10
11
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.ViewerSorter;
13
import org.eclipse.mylyn.tasks.core.AbstractTask;
14
15
/**
16
 * Sorts search results (AbstractQueryHit) by taskId.
17
 */
18
public class SearchResultSorterId extends ViewerSorter {
19
20
	/**
21
	 * Returns a negative, zero, or positive number depending on whether the first bug's taskId is less than, equal to,
22
	 * or greater than the second bug's taskId.
23
	 * <p>
24
	 * 
25
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
26
	 *      java.lang.Object)
27
	 */
28
	@Override
29
	public int compare(Viewer viewer, Object e1, Object e2) {
30
		try {
31
			// cast the object and get its bug taskId
32
			AbstractTask entry1 = (AbstractTask) e1;
33
			Integer id1 = Integer.parseInt(entry1.getTaskId());
34
35
			// cast the other object and get its bug taskId
36
			AbstractTask entry2 = (AbstractTask) e2;
37
			Integer id2 = Integer.parseInt(entry2.getTaskId());
38
39
			// if neither is null, compare the bug taskId's
40
			if (id1 != null && id2 != null) {
41
				return id1.compareTo(id2);
42
			}
43
		} catch (Exception ignored) {
44
			// ignore if there is a problem
45
		}
46
47
		// if that didn't work, use the default compare method
48
		return super.compare(viewer, e1, e2);
49
	}
50
51
	/**
52
	 * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins
53
	 * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort
54
	 * criterion.
55
	 * <p>
56
	 * 
57
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(Object)
58
	 */
59
	@Override
60
	public int category(Object element) {
61
		try {
62
			AbstractTask hit = (AbstractTask) element;
63
			return Integer.parseInt(hit.getTaskId());
64
		} catch (Exception ignored) {
65
			// ignore
66
		}
67
		// if that didn't work, use the default category method
68
		return super.category(element);
69
	}
70
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/TaskComparator.java (+184 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui;
10
11
import java.util.Comparator;
12
13
import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
14
import org.eclipse.mylyn.tasks.core.AbstractTask;
15
import org.eclipse.mylyn.tasks.core.AbstractTaskContainer;
16
17
/**
18
 * @author Frank Becker
19
 */
20
21
public class TaskComparator implements Comparator<AbstractTaskContainer> {
22
	public enum SortByIndex {
23
		PRIORITY, SUMMARY, DATE_CREATED;
24
	}
25
26
	private static final int DEFAULT_SORT_DIRECTION = 1;
27
28
	private int sortDirection = DEFAULT_SORT_DIRECTION;
29
30
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
31
32
	private static final int DEFAULT_SORT_DIRECTION2 = 1;
33
34
	private int sortDirection2 = DEFAULT_SORT_DIRECTION2;
35
36
	private SortByIndex sortByIndex2 = SortByIndex.SUMMARY;
37
38
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
39
40
	public int compare(AbstractTaskContainer element1, AbstractTaskContainer element2) {
41
		if (SortByIndex.PRIORITY.equals(sortByIndex)) {
42
			int result = sortByPriority(element1, element2, sortDirection);
43
			if (result != 0) {
44
				return result;
45
			}
46
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
47
				return sortByDate(element1, element2, sortDirection2);
48
			} else {
49
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
50
					return sortBySummary(element1, element2, sortDirection2);
51
				} else {
52
					return result;
53
				}
54
			}
55
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
56
			int result = sortByDate(element1, element2, sortDirection);
57
			if (result != 0) {
58
				return result;
59
			}
60
			if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
61
				return sortByPriority(element1, element2, sortDirection2);
62
			} else {
63
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
64
					return sortBySummary(element1, element2, sortDirection2);
65
				} else {
66
					return result;
67
				}
68
			}
69
		} else {
70
			int result = sortBySummary(element1, element2, sortDirection);
71
			if (result != 0) {
72
				return result;
73
			}
74
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
75
				return sortByDate(element1, element2, sortDirection2);
76
			} else {
77
				if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
78
					return sortByPriority(element1, element2, sortDirection2);
79
				} else {
80
					return result;
81
				}
82
			}
83
		}
84
	}
85
86
	/**
87
	 * Determine the sort order of two tasks by id/summary
88
	 * 
89
	 * @param element1
90
	 * @param element2
91
	 * @return sort order
92
	 */
93
	private int sortBySummary(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
94
		return sortDirection
95
				* taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
96
//		return sortDirection * (element1.getSummary().compareTo(element2.getSummary()));
97
	}
98
99
	/**
100
	 * Determine the sort order of two tasks by priority
101
	 * 
102
	 * @param element1
103
	 * @param element2
104
	 * @return sort order
105
	 */
106
	private int sortByPriority(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
107
		return sortDirection * element1.getPriority().compareTo(element2.getPriority());
108
	}
109
110
	/**
111
	 * Determine the sort order of two tasks by creation date
112
	 * 
113
	 * @param element1
114
	 * @param element2
115
	 * @return sort order
116
	 */
117
	private int sortByDate(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
118
		AbstractTask t1 = null;
119
		AbstractTask t2 = null;
120
		if (element1 instanceof AbstractTask) {
121
			t1 = (AbstractTask) element1;
122
		}
123
		if (element2 instanceof AbstractTask) {
124
			t2 = (AbstractTask) element2;
125
		}
126
		if (t1 != null && t2 != null) {
127
			if (t1.getCreationDate() != null) {
128
				return sortDirection * t1.getCreationDate().compareTo(t2.getCreationDate());
129
			}
130
		}
131
		return 0;
132
	}
133
134
	/**
135
	 * Return a array of values to pass to taskKeyComparator.compare() for sorting
136
	 * 
137
	 * @param element
138
	 * @return String array[component, taskId, summary]
139
	 */
140
	public static String[] getSortableFromElement(AbstractTaskContainer element) {
141
		final String a[] = new String[] { "", null, element.getSummary() };
142
143
		if (element instanceof AbstractTask) {
144
			AbstractTask task1 = (AbstractTask) element;
145
			if (task1.getTaskKey() != null) {
146
				a[1] = task1.getTaskKey();
147
			}
148
		}
149
		return a;
150
	}
151
152
	public int getSortDirection() {
153
		return sortDirection;
154
	}
155
156
	public void setSortDirection(int sortDirection) {
157
		this.sortDirection = sortDirection;
158
	}
159
160
	public SortByIndex getSortByIndex() {
161
		return sortByIndex;
162
	}
163
164
	public void setSortByIndex(SortByIndex sortByIndex) {
165
		this.sortByIndex = sortByIndex;
166
	}
167
168
	public int getSortDirection2() {
169
		return sortDirection2;
170
	}
171
172
	public void setSortDirection2(int sortDirection2) {
173
		this.sortDirection2 = sortDirection2;
174
	}
175
176
	public SortByIndex getSortByIndex2() {
177
		return sortByIndex2;
178
	}
179
180
	public void setSortByIndex2(SortByIndex sortByIndex2) {
181
		this.sortByIndex2 = sortByIndex2;
182
	}
183
184
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/TaskSearchResultSorter.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.search;
10
11
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.ViewerSorter;
13
import org.eclipse.mylyn.internal.tasks.ui.TaskComparator;
14
import org.eclipse.mylyn.internal.tasks.ui.TaskComparator.SortByIndex;
15
import org.eclipse.mylyn.tasks.core.AbstractTaskContainer;
16
17
/**
18
 * @author Frank Becker
19
 */
20
21
public class TaskSearchResultSorter extends ViewerSorter {
22
23
	private final TaskComparator taskComparator = new TaskComparator();
24
25
	@Override
26
	public int compare(Viewer viewer, Object e1, Object e2) {
27
		if (e1 instanceof AbstractTaskContainer && e2 instanceof AbstractTaskContainer) {
28
			AbstractTaskContainer entry1 = (AbstractTaskContainer) e1;
29
			AbstractTaskContainer entry2 = (AbstractTaskContainer) e2;
30
			return taskComparator.compare(entry1, entry2);
31
		} else {
32
			return super.compare(viewer, e1, e2);
33
		}
34
	}
35
36
	public int getSortDirection() {
37
		return taskComparator.getSortDirection();
38
	}
39
40
	public void setSortDirection(int sortDirection) {
41
		taskComparator.setSortDirection(sortDirection);
42
	}
43
44
	public SortByIndex getSortByIndex() {
45
		return taskComparator.getSortByIndex();
46
	}
47
48
	public void setSortByIndex(SortByIndex sortByIndex) {
49
		taskComparator.setSortByIndex(sortByIndex);
50
	}
51
52
	public int getSortDirection2() {
53
		return taskComparator.getSortDirection2();
54
	}
55
56
	public void setSortDirection2(int sortDirection) {
57
		taskComparator.setSortDirection2(sortDirection);
58
	}
59
60
	public SortByIndex getSortByIndex2() {
61
		return taskComparator.getSortByIndex2();
62
	}
63
64
	public void setSortByIndex2(SortByIndex sortByIndex) {
65
		taskComparator.setSortByIndex2(sortByIndex);
66
	}
67
68
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortDirection.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui.search;
10
11
import org.eclipse.jface.action.Action;
12
13
/**
14
 * This class set the sorts direction of the search results.
15
 * 
16
 * @author Frank Becker
17
 */
18
public class SearchResultSortDirection extends Action {
19
20
	/** The view where the Bugzilla search results are displayed. */
21
	private final RepositorySearchResultView bugPage;
22
23
	private final boolean secondLevel;
24
25
	/**
26
	 * Constructor
27
	 * 
28
	 * @param label
29
	 *            The string used as the text for the action, or null if there is no text
30
	 * @param page
31
	 *            The view where the Bugzilla search results are displayed.
32
	 * @param sortOrder
33
	 *            The category that this class sorts Bugzilla search results by
34
	 */
35
	public SearchResultSortDirection(String label, RepositorySearchResultView page, boolean level2) {
36
		super(label);
37
		bugPage = page;
38
		secondLevel = level2;
39
	}
40
41
	/**
42
	 * Reorder the Bugzilla search results.
43
	 */
44
	@Override
45
	public void run() {
46
		if (secondLevel) {
47
			bugPage.setSortDirection2(bugPage.getSortDirection2() * -1);
48
			setChecked(bugPage.getSortDirection2() < 0);
49
		} else {
50
			bugPage.setSortDirection(bugPage.getSortDirection() * -1);
51
			setChecked(bugPage.getSortDirection() < 0);
52
		}
53
	}
54
}

Return to bug 216150