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/internal/tasks/ui/search/messages.properties (+3 lines)
Lines 6-11 Link Here
6
RepositorySearchResultView_Create_Query_from_Search_=Create Query from Search...
6
RepositorySearchResultView_Create_Query_from_Search_=Create Query from Search...
7
RepositorySearchResultView_Filter_Completed_Tasks=Filter Completed Tasks
7
RepositorySearchResultView_Filter_Completed_Tasks=Filter Completed Tasks
8
RepositorySearchResultView_Group_By_Owner=Group By Owner
8
RepositorySearchResultView_Group_By_Owner=Group By Owner
9
RepositorySearchResultView_Group_By_Complete=Group By Complete
9
RepositorySearchResultView_Open_in_Editor=Open in Editor
10
RepositorySearchResultView_Open_in_Editor=Open in Editor
10
RepositorySearchResultView_Open_Search_with_Browser_Label=Open Search with Browser
11
RepositorySearchResultView_Open_Search_with_Browser_Label=Open Search with Browser
11
RepositorySearchResultView_Refine_Search_=Refine Search...
12
RepositorySearchResultView_Refine_Search_=Refine Search...
Lines 25-27 Link Here
25
SearchResultTreeContentProvider_Complete=Complete
26
SearchResultTreeContentProvider_Complete=Complete
26
SearchResultTreeContentProvider_Incomplete=Incomplete
27
SearchResultTreeContentProvider_Incomplete=Incomplete
27
SearchResultTreeContentProvider__unknown_=<unknown>
28
SearchResultTreeContentProvider__unknown_=<unknown>
29
30
SearchResultSortAction_Sort_Label=Sort...
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/Messages.java (+4 lines)
Lines 41-46 Link Here
41
41
42
	public static String RepositorySearchResultView_Group_By_Owner;
42
	public static String RepositorySearchResultView_Group_By_Owner;
43
43
44
	public static String RepositorySearchResultView_Group_By_Complete;
45
44
	public static String RepositorySearchResultView_Open_in_Editor;
46
	public static String RepositorySearchResultView_Open_in_Editor;
45
47
46
	public static String RepositorySearchResultView_Open_Search_with_Browser_Label;
48
	public static String RepositorySearchResultView_Open_Search_with_Browser_Label;
Lines 72-75 Link Here
72
	public static String SearchResultTreeContentProvider_Incomplete;
74
	public static String SearchResultTreeContentProvider_Incomplete;
73
75
74
	public static String SearchResultTreeContentProvider__unknown_;
76
	public static String SearchResultTreeContentProvider__unknown_;
77
78
	public static String SearchResultSortAction_Sort_Label;
75
}
79
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java (-16 / +13 lines)
Lines 12-17 Link Here
12
package org.eclipse.mylyn.internal.tasks.ui.search;
12
package org.eclipse.mylyn.internal.tasks.ui.search;
13
13
14
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.window.IShellProvider;
16
import org.eclipse.jface.window.Window;
17
import org.eclipse.mylyn.internal.tasks.ui.dialogs.TaskCompareDialog;
15
18
16
/**
19
/**
17
 * This class sorts search results by a supplied category.
20
 * This class sorts search results by a supplied category.
Lines 20-30 Link Here
20
 */
23
 */
21
public class SearchResultSortAction extends Action {
24
public class SearchResultSortAction extends Action {
22
25
23
	/** The category that this class sorts Bugzilla search results by. */
26
	private final TaskCompareDialog dialog;
24
	private final int bugSortOrder;
25
27
26
	/** The view where the Bugzilla search results are displayed. */
28
	SearchResultSorter searchResultSorter;
27
	private final RepositorySearchResultView bugPage;
28
29
29
	/**
30
	/**
30
	 * Constructor
31
	 * Constructor
Lines 36-45 Link Here
36
	 * @param sortOrder
37
	 * @param sortOrder
37
	 *            The category that this class sorts Bugzilla search results by
38
	 *            The category that this class sorts Bugzilla search results by
38
	 */
39
	 */
39
	public SearchResultSortAction(String label, RepositorySearchResultView page, int sortOrder) {
40
	public SearchResultSortAction(IShellProvider site, SearchResultSorter searchResultSorter) {
40
		super(label);
41
		super(Messages.SearchResultSortAction_Sort_Label);
41
		bugPage = page;
42
		setEnabled(true);
42
		bugSortOrder = sortOrder;
43
		dialog = new TaskCompareDialog(site, searchResultSorter.getTaskComparator());
44
		this.searchResultSorter = searchResultSorter;
43
	}
45
	}
44
46
45
	/**
47
	/**
Lines 47-59 Link Here
47
	 */
49
	 */
48
	@Override
50
	@Override
49
	public void run() {
51
	public void run() {
50
		bugPage.setSortOrder(bugSortOrder);
52
		if (dialog.open() == Window.OK) {
51
	}
53
			searchResultSorter.refreshView();
52
54
		}
53
	/**
54
	 * Returns the category that this class sorts Bugzilla search results by.
55
	 */
56
	public int getSortOrder() {
57
		return bugSortOrder;
58
	}
55
	}
59
}
56
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorter.java (-22 / +61 lines)
Lines 13-35 Link Here
13
13
14
import org.eclipse.jface.viewers.Viewer;
14
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.ViewerSorter;
15
import org.eclipse.jface.viewers.ViewerSorter;
16
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
17
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
16
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
18
import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
17
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator.SortByIndex;
19
import org.eclipse.mylyn.tasks.core.ITask;
18
import org.eclipse.mylyn.tasks.core.ITask;
20
19
21
/**
20
/**
22
 * Sorts search results by summary.
21
 * Sorts search results.
23
 * 
22
 * 
24
 * @author Rob Elves
23
 * @author Rob Elves
24
 * @author Frank Becker
25
 */
25
 */
26
public class SearchResultSorter extends ViewerSorter {
26
public class SearchResultSorter extends ViewerSorter {
27
27
28
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
28
	private final RepositorySearchResultView view;
29
30
	private final TaskComparator taskComparator = new TaskComparator();
31
32
	public SearchResultSorter(RepositorySearchResultView view) {
33
		super();
34
		this.view = view;
35
	}
29
36
30
	/**
37
	/**
31
	 * Returns a negative, zero, or positive number depending on whether the first bug's summary goes before, is the
38
	 * Returns a negative, zero, or positive number depending on whether the first bug's taskId is less than, equal to,
32
	 * same as, or goes after the second element's summary.
39
	 * or greater than the second bug's taskId.
33
	 * <p>
40
	 * <p>
34
	 * 
41
	 * 
35
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
42
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
Lines 37-58 Link Here
37
	 */
44
	 */
38
	@Override
45
	@Override
39
	public int compare(Viewer viewer, Object e1, Object e2) {
46
	public int compare(Viewer viewer, Object e1, Object e2) {
40
		try {
47
		if (e1 instanceof ITask && e2 instanceof ITask) {
41
48
			ITask entry1 = (ITask) e1;
42
			AbstractTask entry1 = (AbstractTask) e1;
49
			ITask entry2 = (ITask) e2;
43
			AbstractTask entry2 = (AbstractTask) e2;
50
			return taskComparator.compare(entry1, entry2);
44
			// NOTE we just comparing ids here, once summary and taskId separated
51
		} else {
45
			// they should have their own column/sorter.
52
			return super.compare(viewer, e1, e2);
46
			return taskKeyComparator.compare(TaskComparator.getSortableFromElement(entry1),
47
					TaskComparator.getSortableFromElement(entry2));
48
			// return taskKeyComparator.compare(entry1.getDescription(),
49
			// entry2.getDescription());
50
		} catch (Exception ignored) {
51
			// do nothing
52
		}
53
		}
53
54
		// if that didn't work, use the default compare method
55
		return super.compare(viewer, e1, e2);
56
	}
54
	}
57
55
58
	/**
56
	/**
Lines 69-77 Link Here
69
			ITask hit = (ITask) element;
67
			ITask hit = (ITask) element;
70
			return Integer.parseInt(hit.getTaskId());
68
			return Integer.parseInt(hit.getTaskId());
71
		} catch (Exception ignored) {
69
		} catch (Exception ignored) {
72
			// ignore if
70
			// ignore if there is a problem
73
		}
71
		}
74
		// if that didn't work, use the default category method
72
		// if that didn't work, use the default category method
75
		return super.category(element);
73
		return super.category(element);
76
	}
74
	}
75
76
	public int getSortDirection() {
77
		return taskComparator.getSortDirection();
78
	}
79
80
	public void setSortDirection(int sortDirection) {
81
		taskComparator.setSortDirection(sortDirection);
82
	}
83
84
	public SortByIndex getSortByIndex() {
85
		return taskComparator.getSortByIndex();
86
	}
87
88
	public void setSortByIndex(SortByIndex sortByIndex) {
89
		taskComparator.setSortByIndex(sortByIndex);
90
	}
91
92
	public int getSortDirection2() {
93
		return taskComparator.getSortDirection2();
94
	}
95
96
	public void setSortDirection2(int sortDirection) {
97
		taskComparator.setSortDirection2(sortDirection);
98
	}
99
100
	public SortByIndex getSortByIndex2() {
101
		return taskComparator.getSortByIndex2();
102
	}
103
104
	public void setSortByIndex2(SortByIndex sortByIndex) {
105
		taskComparator.setSortByIndex2(sortByIndex);
106
	}
107
108
	public TaskComparator getTaskComparator() {
109
		return taskComparator;
110
	}
111
112
	public void refreshView() {
113
		view.setCurrentSortOrder2Preference();
114
		view.getViewer().refresh();
115
	}
77
}
116
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterPriority.java (-65 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.search;
13
14
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.ViewerSorter;
16
import org.eclipse.mylyn.tasks.core.ITask;
17
18
/**
19
 * Sorts results of Bugzilla search by bug priority.
20
 * 
21
 * @author Rob Elves (modifications)
22
 */
23
public class SearchResultSorterPriority extends ViewerSorter {
24
25
	/**
26
	 * Returns a negative, zero, or positive number depending on whether the first bug's priority goes before, is the
27
	 * same as, or goes after the second element's priority.
28
	 * <p>
29
	 * 
30
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
31
	 *      java.lang.Object)
32
	 */
33
	@Override
34
	public int compare(Viewer viewer, Object e1, Object e2) {
35
		try {
36
			ITask hit1 = (ITask) e1;
37
			ITask hit2 = (ITask) e2;
38
			return hit1.getPriority().compareTo(hit2.getPriority());
39
		} catch (Exception ignored) {
40
			// do nothing
41
		}
42
		// if that didn't work, use the default compare method
43
		return super.compare(viewer, e1, e2);
44
	}
45
46
	/**
47
	 * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins
48
	 * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort
49
	 * criterion.
50
	 * <p>
51
	 * 
52
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(Object)
53
	 */
54
	@Override
55
	public int category(Object element) {
56
		try {
57
			ITask hit = (ITask) element;
58
			return Integer.parseInt(hit.getTaskId());
59
		} catch (Exception ignored) {
60
			// ignore if there is a problem
61
		}
62
		// if that didn't work, use the default category method
63
		return super.category(element);
64
	}
65
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResultView.java (-66 / +118 lines)
Lines 41-46 Link Here
41
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskSearchAction;
41
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskSearchAction;
42
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenWithBrowserAction;
42
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenWithBrowserAction;
43
import org.eclipse.mylyn.internal.tasks.ui.search.SearchResultTreeContentProvider.GroupBy;
43
import org.eclipse.mylyn.internal.tasks.ui.search.SearchResultTreeContentProvider.GroupBy;
44
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
44
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
45
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
45
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListToolTip;
46
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListToolTip;
46
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
47
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
Lines 129-155 Link Here
129
		}
130
		}
130
	}
131
	}
131
132
132
	public static final int ORDER_PRIORITY = 1;
133
134
	public static final int ORDER_DESCRIPTION = 2;
135
136
	public static final int ORDER_SEVERITY = 3;
137
138
	public static final int ORDER_STATUS = 4;
139
140
	public static final int ORDER_ID = 5;
141
142
	public static final int ORDER_DEFAULT = ORDER_PRIORITY;
143
144
	private static final String KEY_SORTING = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting"; //$NON-NLS-1$
133
	private static final String KEY_SORTING = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting"; //$NON-NLS-1$
145
134
146
	private SearchResultContentProvider searchResultProvider;
135
	private static final String KEY_SORTING2 = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting2"; //$NON-NLS-1$
147
136
148
	private int currentSortOrder;
137
	private static final String KEY_SORTINGDIRECTION = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sortingdirection"; //$NON-NLS-1$
149
138
150
	private final SearchResultSortAction sortByPriorityAction;
139
	private static final String KEY_SORTINGDIRECTION2 = TasksUiPlugin.ID_PLUGIN
140
			+ ".search.resultpage.sortingdirection2"; //$NON-NLS-1$
151
141
152
	private final SearchResultSortAction sortByDescriptionAction;
142
	private SearchResultContentProvider searchResultProvider;
153
143
154
	private final OpenSearchResultAction openInEditorAction;
144
	private final OpenSearchResultAction openInEditorAction;
155
145
Lines 167-172 Link Here
167
157
168
	private final OpenWithBrowserAction openSearchWithBrowserAction;
158
	private final OpenWithBrowserAction openSearchWithBrowserAction;
169
159
160
	private SearchResultSorter searchResultSorter;
161
162
	private SearchResultSortAction sortByDialogAction;
163
170
	private static final IShowInTargetList SHOW_IN_TARGET_LIST = new IShowInTargetList() {
164
	private static final IShowInTargetList SHOW_IN_TARGET_LIST = new IShowInTargetList() {
171
		public String[] getShowInTargetIds() {
165
		public String[] getShowInTargetIds() {
172
			return SHOW_IN_TARGETS;
166
			return SHOW_IN_TARGETS;
Lines 177-188 Link Here
177
		// Only use the table layout.
171
		// Only use the table layout.
178
		super(FLAG_LAYOUT_TREE);
172
		super(FLAG_LAYOUT_TREE);
179
173
180
		sortByPriorityAction = new SearchResultSortAction(Messages.RepositorySearchResultView_Task_Priority, this,
181
				ORDER_PRIORITY);
182
		sortByDescriptionAction = new SearchResultSortAction(Messages.RepositorySearchResultView_Task_Summary, this,
183
				ORDER_DESCRIPTION);
184
		currentSortOrder = ORDER_DEFAULT;
185
186
		openInEditorAction = new OpenSearchResultAction(Messages.RepositorySearchResultView_Open_in_Editor, this);
174
		openInEditorAction = new OpenSearchResultAction(Messages.RepositorySearchResultView_Open_in_Editor, this);
187
		createQueryAction = new CreateQueryFromSearchAction(
175
		createQueryAction = new CreateQueryFromSearchAction(
188
				Messages.RepositorySearchResultView_Create_Query_from_Search_, this);
176
				Messages.RepositorySearchResultView_Create_Query_from_Search_, this);
Lines 193-199 Link Here
193
181
194
		groupingActions = new ArrayList<GroupingAction>();
182
		groupingActions = new ArrayList<GroupingAction>();
195
		new GroupingAction(Messages.RepositorySearchResultView_Group_By_Owner, GroupBy.OWNER);
183
		new GroupingAction(Messages.RepositorySearchResultView_Group_By_Owner, GroupBy.OWNER);
196
		//new GroupingAction("Group By Complete", GroupBy.COMPLETION);
184
//		new GroupingAction(Messages.RepositorySearchResultView_Group_By_Complete, GroupBy.COMPLETION);
197
185
198
		filterActions = new ArrayList<FilteringAction>();
186
		filterActions = new ArrayList<FilteringAction>();
199
		new FilteringAction(Messages.RepositorySearchResultView_Filter_Completed_Tasks, new ViewerFilter() {
187
		new FilteringAction(Messages.RepositorySearchResultView_Filter_Completed_Tasks, new ViewerFilter() {
Lines 241-251 Link Here
241
		DecoratingLabelProvider labelProvider = new DecoratingLabelProvider(new SearchResultsLabelProvider(
229
		DecoratingLabelProvider labelProvider = new DecoratingLabelProvider(new SearchResultsLabelProvider(
242
				searchResultProvider, viewer), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
230
				searchResultProvider, viewer), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
243
		viewer.setLabelProvider(labelProvider);
231
		viewer.setLabelProvider(labelProvider);
232
		searchResultSorter = new SearchResultSorter(this);
233
		viewer.setSorter(searchResultSorter);
234
		sortByDialogAction = new SearchResultSortAction(getSite(), searchResultSorter);
244
235
245
		// Set the order when the search view is loading so that the items are
236
		// Set the order when the search view is loading so that the items are
246
		// sorted right away
237
		// sorted right away
247
		setSortOrder(currentSortOrder);
238
		restoreCurrentSortOrder2Preference();
248
249
		toolTip = new TaskListToolTip(viewer.getControl());
239
		toolTip = new TaskListToolTip(viewer.getControl());
250
	}
240
	}
251
241
Lines 318-353 Link Here
318
		super.dispose();
308
		super.dispose();
319
	}
309
	}
320
310
321
	/**
322
	 * Sets the new sorting category, and reorders all of the tasks.
323
	 * 
324
	 * @param sortOrder
325
	 *            The new category to sort by
326
	 */
327
	public void setSortOrder(int sortOrder) {
328
		StructuredViewer viewer = getViewer();
329
330
		switch (sortOrder) {
331
		case ORDER_ID:
332
			viewer.setSorter(new SearchResultSorterId());
333
			break;
334
		case ORDER_DESCRIPTION:
335
			viewer.setSorter(new SearchResultSorter());
336
			break;
337
		case ORDER_PRIORITY:
338
			viewer.setSorter(new SearchResultSorterPriority());
339
			break;
340
		default:
341
			// If the setting is not one of the four valid ones,
342
			// use the default order setting.
343
			sortOrder = ORDER_DEFAULT;
344
			viewer.setSorter(new SearchResultSorterPriority());
345
			break;
346
		}
347
		currentSortOrder = sortOrder;
348
		getSettings().put(KEY_SORTING, currentSortOrder);
349
	}
350
351
	@SuppressWarnings("unchecked")
311
	@SuppressWarnings("unchecked")
352
	public Object getAdapter(Class adapter) {
312
	public Object getAdapter(Class adapter) {
353
		return getAdapterDelegate(adapter);
313
		return getAdapterDelegate(adapter);
Lines 372-378 Link Here
372
		super.fillContextMenu(menuManager);
332
		super.fillContextMenu(menuManager);
373
333
374
		// open actions
334
		// open actions
375
376
		menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, openInEditorAction);
335
		menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, openInEditorAction);
377
336
378
		// Add to Task List menu
337
		// Add to Task List menu
Lines 404-419 Link Here
404
		menuManager.appendToGroup(IContextMenuConstants.GROUP_SEARCH, refineSearchAction);
363
		menuManager.appendToGroup(IContextMenuConstants.GROUP_SEARCH, refineSearchAction);
405
		menuManager.appendToGroup(IContextMenuConstants.GROUP_SEARCH, openSearchWithBrowserAction);
364
		menuManager.appendToGroup(IContextMenuConstants.GROUP_SEARCH, openSearchWithBrowserAction);
406
365
407
		// sort actions
366
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortByDialogAction);
408
409
		MenuManager sortMenuManager = new MenuManager(Messages.RepositorySearchResultView_Sort_by);
410
		sortMenuManager.add(sortByPriorityAction);
411
		sortMenuManager.add(sortByDescriptionAction);
412
413
		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
414
		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
415
416
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
417
		for (Action action : groupingActions) {
367
		for (Action action : groupingActions) {
418
			menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, action);
368
			menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, action);
419
		}
369
		}
Lines 468-471 Link Here
468
		}
418
		}
469
	}
419
	}
470
420
421
	public void restoreCurrentSortOrder2Preference() {
422
		int restoredSortIndex = 0;
423
		int restoredSortDirection = 1;
424
		int restoredSortIndex2 = 2;
425
		int restoredSortDirection2 = 1;
426
		String preferenceString = getSettings().get(KEY_SORTING);
427
428
		if (preferenceString != null) {
429
			try {
430
				restoredSortIndex = Integer.parseInt(preferenceString);
431
			} catch (NumberFormatException e) {
432
				restoredSortIndex = 0;
433
			}
434
		}
435
		preferenceString = getSettings().get(KEY_SORTINGDIRECTION);
436
		if (preferenceString != null) {
437
			try {
438
				restoredSortDirection = Integer.parseInt(preferenceString);
439
			} catch (NumberFormatException e) {
440
				restoredSortDirection = 1;
441
			}
442
		}
443
		preferenceString = getSettings().get(KEY_SORTING2);
444
		if (preferenceString != null) {
445
			try {
446
				restoredSortIndex2 = Integer.parseInt(preferenceString);
447
			} catch (NumberFormatException e) {
448
				restoredSortIndex2 = 2;
449
			}
450
		}
451
		preferenceString = getSettings().get(KEY_SORTINGDIRECTION2);
452
		if (preferenceString != null) {
453
			try {
454
				restoredSortDirection2 = Integer.parseInt(preferenceString);
455
			} catch (NumberFormatException e) {
456
				restoredSortDirection2 = 1;
457
			}
458
		}
459
460
		switch (restoredSortIndex) {
461
		case 1:
462
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
463
			break;
464
		case 2:
465
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED);
466
			break;
467
		case 3:
468
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.TASK_ID);
469
			break;
470
		default:
471
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
472
		}
473
474
		searchResultSorter.setSortDirection(restoredSortDirection2);
475
		switch (restoredSortIndex2) {
476
		case 1:
477
			searchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.SUMMARY);
478
			break;
479
		case 2:
480
			searchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.DATE_CREATED);
481
			break;
482
		case 3:
483
			searchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.TASK_ID);
484
			break;
485
		default:
486
			searchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY);
487
		}
488
		searchResultSorter.setSortDirection(restoredSortDirection);
489
		searchResultSorter.setSortDirection2(restoredSortDirection2);
490
	}
491
492
	public void setCurrentSortOrder2Preference() {
493
		getSettings().put(KEY_SORTINGDIRECTION, searchResultSorter.getSortDirection());
494
		switch (searchResultSorter.getSortByIndex()) {
495
		case SUMMARY:
496
			getSettings().put(KEY_SORTING, 1);
497
			break;
498
		case DATE_CREATED:
499
			getSettings().put(KEY_SORTING, 2);
500
			break;
501
		case TASK_ID:
502
			getSettings().put(KEY_SORTING, 3);
503
			break;
504
		default:
505
			getSettings().put(KEY_SORTING, 0);
506
		}
507
508
		getSettings().put(KEY_SORTINGDIRECTION2, searchResultSorter.getSortDirection2());
509
		switch (searchResultSorter.getSortByIndex2()) {
510
		case SUMMARY:
511
			getSettings().put(KEY_SORTING2, 1);
512
			break;
513
		case DATE_CREATED:
514
			getSettings().put(KEY_SORTING2, 2);
515
			break;
516
		case TASK_ID:
517
			getSettings().put(KEY_SORTING2, 3);
518
			break;
519
		default:
520
			getSettings().put(KEY_SORTING2, 0);
521
		}
522
	}
471
}
523
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterId.java (-73 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 Tasktop Technologies 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
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui.search;
13
14
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.ViewerSorter;
16
import org.eclipse.mylyn.tasks.core.ITask;
17
18
/**
19
 * Sorts search results (AbstractQueryHit) by taskId.
20
 */
21
public class SearchResultSorterId extends ViewerSorter {
22
23
	/**
24
	 * Returns a negative, zero, or positive number depending on whether the first bug's taskId is less than, equal to,
25
	 * or greater than the second bug's taskId.
26
	 * <p>
27
	 * 
28
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
29
	 *      java.lang.Object)
30
	 */
31
	@Override
32
	public int compare(Viewer viewer, Object e1, Object e2) {
33
		try {
34
			// cast the object and get its bug taskId
35
			ITask entry1 = (ITask) e1;
36
			Integer id1 = Integer.parseInt(entry1.getTaskId());
37
38
			// cast the other object and get its bug taskId
39
			ITask entry2 = (ITask) e2;
40
			Integer id2 = Integer.parseInt(entry2.getTaskId());
41
42
			// if neither is null, compare the bug taskId's
43
			if (id1 != null && id2 != null) {
44
				return id1.compareTo(id2);
45
			}
46
		} catch (Exception ignored) {
47
			// ignore if there is a problem
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
			ITask hit = (ITask) element;
66
			return Integer.parseInt(hit.getTaskId());
67
		} catch (Exception ignored) {
68
			// ignore
69
		}
70
		// if that didn't work, use the default category method
71
		return super.category(element);
72
	}
73
}
(-).refactorings/2009/3/13/refactorings.history (+4 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<session version="1.0">
3
<refactoring accessors="true" comment="Delete 2 element(s) from project &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original elements:&#x0A;     org.eclipse.mylyn.internal.tasks.ui.search.SearchResultSorterId.java&#x0A;     org.eclipse.mylyn.internal.tasks.ui.search.SearchResultSorterPriority.java" description="Delete elements" element1="/src&lt;org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterId.java" element2="/src&lt;org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterPriority.java" elements="2" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1238277505401" subPackages="false" version="1.0"/>
4
</session>
(-).refactorings/2009/3/13/refactorings.index (+1 lines)
Added Link Here
1
1238277505401	Delete elements

Return to bug 216150