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/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 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 RepositorySearchResultView bugPage;
24
	private RepositorySearchResultView bugPage;
25
25
26
	private 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 (-20 / +110 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.TasksUiImages;
28
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
27
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
29
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
28
import org.eclipse.mylyn.tasks.core.AbstractTask;
30
import org.eclipse.mylyn.tasks.core.AbstractTask;
Lines 30-36 Link Here
30
import org.eclipse.mylyn.tasks.core.TaskRepository;
32
import org.eclipse.mylyn.tasks.core.TaskRepository;
31
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
33
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
32
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
34
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
33
import org.eclipse.search.internal.ui.SearchMessages;
34
import org.eclipse.search.ui.IContextMenuConstants;
35
import org.eclipse.search.ui.IContextMenuConstants;
35
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
36
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
36
import org.eclipse.search.ui.text.Match;
37
import org.eclipse.search.ui.text.Match;
Lines 47-52 Link Here
47
 * 
48
 * 
48
 * @author Rob Elves
49
 * @author Rob Elves
49
 * @author Mik Kersten
50
 * @author Mik Kersten
51
 * @author Frank Becker (https://bugs.eclipse.org/bugs/show_bug.cgi?taskId=216150)
50
 */
52
 */
51
public class RepositorySearchResultView extends AbstractTextSearchViewPage implements IAdaptable {
53
public class RepositorySearchResultView extends AbstractTextSearchViewPage implements IAdaptable {
52
54
Lines 55-87 Link Here
55
	public static final int ORDER_PRIORITY = 1;
57
	public static final int ORDER_PRIORITY = 1;
56
58
57
	public static final int ORDER_DESCRIPTION = 2;
59
	public static final int ORDER_DESCRIPTION = 2;
58
60
	
59
	public static final int ORDER_SEVERITY = 3;
61
	public static final int ORDER_DATE_CREATED = 3;
60
61
	public static final int ORDER_STATUS = 4;
62
63
	public static final int ORDER_ID = 5;
64
62
65
	public static final int ORDER_DEFAULT = ORDER_PRIORITY;
63
	public static final int ORDER_DEFAULT = ORDER_PRIORITY;
66
64
65
	public static final int ORDER2_DEFAULT = ORDER_DESCRIPTION;
66
67
	private static final String KEY_SORTING = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting"; //$NON-NLS-1$
67
	private static final String KEY_SORTING = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting"; //$NON-NLS-1$
68
68
69
	private static final String KEY_SORTING2 = TasksUiPlugin.ID_PLUGIN + ".search.resultpage.sorting.then"; //$NON-NLS-1$
70
69
	private SearchResultContentProvider searchResultProvider;
71
	private SearchResultContentProvider searchResultProvider;
70
72
71
	private int currentSortOrder;
73
	private int currentSortOrder;
72
74
75
	private int currentSortOrder2;
76
73
	private SearchResultSortAction sortByPriorityAction;
77
	private SearchResultSortAction sortByPriorityAction;
74
78
75
	private SearchResultSortAction sortByDescriptionAction;
79
	private SearchResultSortAction sortByDescriptionAction;
76
80
81
	private SearchResultSortAction sortByDateCreated;
82
83
	private SearchResultSortAction sortByPriorityAction2;
84
85
	private SearchResultSortAction sortByDescriptionAction2;
86
87
	private SearchResultSortAction sortByDateCreated2;
88
77
	private OpenSearchResultAction openInEditorAction;
89
	private OpenSearchResultAction openInEditorAction;
78
90
79
	private CreateQueryFromSearchAction addTaskListAction;
91
	private CreateQueryFromSearchAction addTaskListAction;
92
	
93
	private SearchResultSortDirection sortDirection;
94
	
95
	private SearchResultSortDirection sortDirection2;
80
96
81
	private static final String[] SHOW_IN_TARGETS = new String[] { IPageLayout.ID_RES_NAV };
97
	private static final String[] SHOW_IN_TARGETS = new String[] { IPageLayout.ID_RES_NAV };
82
98
83
	private Action groupByAction;
99
	private Action groupByAction;
84
	
100
	
101
	private TaskSearchResultSorter taskSearchResultSorter;
102
	
85
	private static final IShowInTargetList SHOW_IN_TARGET_LIST = new IShowInTargetList() {
103
	private static final IShowInTargetList SHOW_IN_TARGET_LIST = new IShowInTargetList() {
86
		public String[] getShowInTargetIds() {
104
		public String[] getShowInTargetIds() {
87
			return SHOW_IN_TARGETS;
105
			return SHOW_IN_TARGETS;
Lines 92-104 Link Here
92
		// Only use the table layout.
110
		// Only use the table layout.
93
		super(FLAG_LAYOUT_TREE);
111
		super(FLAG_LAYOUT_TREE);
94
112
95
		sortByPriorityAction = new SearchResultSortAction("Task Priority", this, ORDER_PRIORITY);
113
		sortByPriorityAction = new SearchResultSortAction("Priority", this, ORDER_PRIORITY, false);
96
		sortByDescriptionAction = new SearchResultSortAction("Task Summary", this, ORDER_DESCRIPTION);
114
		sortByPriorityAction.setImageDescriptor(TasksUiImages.PRIORITY_1);
115
		sortByDescriptionAction = new SearchResultSortAction("Summary", this, ORDER_DESCRIPTION, false);
116
		sortByDateCreated = new SearchResultSortAction("Date Created", this, ORDER_DATE_CREATED, false);
117
		sortByDateCreated.setImageDescriptor(TasksUiImages.CALENDAR_SMALL);
97
		currentSortOrder = ORDER_DEFAULT;
118
		currentSortOrder = ORDER_DEFAULT;
119
		sortByPriorityAction2 = new SearchResultSortAction("Priority", this, ORDER_PRIORITY, true);
120
		sortByPriorityAction2.setImageDescriptor(TasksUiImages.PRIORITY_1);
121
		sortByDescriptionAction2 = new SearchResultSortAction("Summary", this, ORDER_DESCRIPTION, true);
122
		sortByDateCreated2 = new SearchResultSortAction("Date Created", this, ORDER_DATE_CREATED, true);
123
		sortByDateCreated2.setImageDescriptor(TasksUiImages.CALENDAR_SMALL);
124
		currentSortOrder2 = ORDER2_DEFAULT;
125
		sortDirection = new SearchResultSortDirection("Descending", this, false);
126
		sortDirection2 = new SearchResultSortDirection("Descending", this, true);
98
127
99
		openInEditorAction = new OpenSearchResultAction("Open in Editor", this);
128
		openInEditorAction = new OpenSearchResultAction("Open in Editor", this);
100
		addTaskListAction = new CreateQueryFromSearchAction("Create Query from Search...", this);
129
		addTaskListAction = new CreateQueryFromSearchAction("Create Query from Search...", this);
101
		
130
102
		groupByAction = new Action(){
131
		groupByAction = new Action(){
103
			
132
			
104
			@Override
133
			@Override
Lines 152-158 Link Here
152
181
153
		// Set the order when the search view is loading so that the items are
182
		// Set the order when the search view is loading so that the items are
154
		// sorted right away
183
		// sorted right away
184
		taskSearchResultSorter = new TaskSearchResultSorter();
185
		viewer.setSorter(taskSearchResultSorter);
155
		setSortOrder(currentSortOrder);
186
		setSortOrder(currentSortOrder);
187
		setSortOrder2(currentSortOrder2);
156
	}
188
	}
157
189
158
	@Override
190
	@Override
Lines 205-233 Link Here
205
	 *            The new category to sort by
237
	 *            The new category to sort by
206
	 */
238
	 */
207
	public void setSortOrder(int sortOrder) {
239
	public void setSortOrder(int sortOrder) {
208
		StructuredViewer viewer = getViewer();
209
210
		switch (sortOrder) {
240
		switch (sortOrder) {
211
		case ORDER_ID:
212
			viewer.setSorter(new SearchResultSorterId());
213
			break;
214
		case ORDER_DESCRIPTION:
241
		case ORDER_DESCRIPTION:
215
			viewer.setSorter(new SearchResultSorterDescription());
242
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);	
216
			break;
243
			break;
217
		case ORDER_PRIORITY:
244
		case ORDER_PRIORITY:
218
			viewer.setSorter(new SearchResultSorterPriority());
245
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);		
246
			break;
247
		case ORDER_DATE_CREATED:
248
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED);		
219
			break;
249
			break;
220
		default:
250
		default:
221
			// If the setting is not one of the four valid ones,
251
			// If the setting is not one of the four valid ones,
222
			// use the default order setting.
252
			// use the default order setting.
223
			sortOrder = ORDER_DEFAULT;
253
			sortOrder = ORDER_DEFAULT;
224
			viewer.setSorter(new SearchResultSorterPriority());
254
		taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);		
225
			break;
255
			break;
226
		}
256
		}
227
		currentSortOrder = sortOrder;
257
		currentSortOrder = sortOrder;
228
		getSettings().put(KEY_SORTING, currentSortOrder);
258
		getSettings().put(KEY_SORTING, currentSortOrder);
259
		getViewer().refresh();
260
	}
261
262
	public void setSortOrder2(int sortOrder) {
263
		switch (sortOrder) {
264
		case ORDER_DESCRIPTION:
265
			taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.SUMMARY);	
266
			break;
267
		case ORDER_PRIORITY:
268
			taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY);		
269
			break;
270
		case ORDER_DATE_CREATED:
271
			taskSearchResultSorter.setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED);		
272
			break;
273
		default:
274
			// If the setting is not one of the four valid ones,
275
			// use the default order setting.
276
			sortOrder = ORDER_DEFAULT;
277
		taskSearchResultSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY);		
278
			break;
279
		}
280
		currentSortOrder2 = sortOrder;
281
		getSettings().put(KEY_SORTING2, currentSortOrder2);
282
		getViewer().refresh();
283
	}
284
	
285
	public void setSortDirection(int sortDirection) {
286
		taskSearchResultSorter.setSortDirection(sortDirection);
287
		getViewer().refresh();
288
	}
289
290
	public int getSortDirection() {
291
		return taskSearchResultSorter.getSortDirection();
292
	}
293
	
294
	public void setSortDirection2(int sortDirection) {
295
		taskSearchResultSorter.setSortDirection2(sortDirection);
296
		getViewer().refresh();
229
	}
297
	}
230
298
299
	public int getSortDirection2() {
300
		return taskSearchResultSorter.getSortDirection2();
301
	}
302
	
231
	@SuppressWarnings("unchecked")
303
	@SuppressWarnings("unchecked")
232
	public Object getAdapter(Class adapter) {
304
	public Object getAdapter(Class adapter) {
233
		return getAdapterDelegate(adapter);
305
		return getAdapterDelegate(adapter);
Lines 252-266 Link Here
252
	@Override
324
	@Override
253
	protected void fillContextMenu(IMenuManager menuManager) {
325
	protected void fillContextMenu(IMenuManager menuManager) {
254
		super.fillContextMenu(menuManager);
326
		super.fillContextMenu(menuManager);
255
		MenuManager sortMenuManager = new MenuManager(SearchMessages.SortDropDownAction_label);
327
		MenuManager sortMenuManager = new MenuManager("First Sort by");
256
		sortMenuManager.add(sortByPriorityAction);
328
		sortMenuManager.add(sortByPriorityAction);
257
		sortMenuManager.add(sortByDescriptionAction);
329
		sortMenuManager.add(sortByDescriptionAction);
330
		sortMenuManager.add(sortByDateCreated);
331
		sortMenuManager.add(new Separator());
332
		sortMenuManager.add(sortDirection);
258
333
259
		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
334
		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
260
		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
335
		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
336
		sortByDateCreated.setChecked(currentSortOrder == sortByDateCreated.getSortOrder());
337
		sortDirection.setChecked(getSortDirection() < 0);
338
339
		MenuManager sortMenuManager2 = new MenuManager("Then Sort by");
340
		sortMenuManager2.add(sortByPriorityAction2);
341
		sortMenuManager2.add(sortByDescriptionAction2);
342
		sortMenuManager2.add(sortByDateCreated2);
343
		sortMenuManager2.add(new Separator());
344
		sortMenuManager2.add(sortDirection2);
345
346
		sortByPriorityAction2.setChecked(currentSortOrder2 == sortByPriorityAction2.getSortOrder());
347
		sortByDescriptionAction2.setChecked(currentSortOrder2 == sortByDescriptionAction2.getSortOrder());
348
		sortByDateCreated2.setChecked(currentSortOrder2 == sortByDateCreated2.getSortOrder());
349
		sortDirection2.setChecked(getSortDirection2() < 0);
261
350
262
		// Add the new context menu items
351
		// Add the new context menu items
263
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
352
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
353
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager2);
264
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, groupByAction);
354
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, groupByAction);
265
		
355
		
266
		menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, openInEditorAction);
356
		menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, openInEditorAction);
Lines 309-312 Link Here
309
		}
399
		}
310
	}
400
	}
311
401
312
}
402
}
(-)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 (+183 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 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 * taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
95
//		return sortDirection * (element1.getSummary().compareTo(element2.getSummary()));
96
	}
97
98
	/**
99
	 * Determine the sort order of two tasks by priority
100
	 * 
101
	 * @param element1
102
	 * @param element2
103
	 * @return sort order
104
	 */
105
	private int sortByPriority(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
106
		return sortDirection * element1.getPriority().compareTo(element2.getPriority());
107
	}
108
109
	/**
110
	 * Determine the sort order of two tasks by creation date
111
	 * 
112
	 * @param element1
113
	 * @param element2
114
	 * @return sort order
115
	 */
116
	private int sortByDate(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
117
		AbstractTask t1 = null;
118
		AbstractTask t2 = null;
119
		if (element1 instanceof AbstractTask) {
120
			t1 = (AbstractTask) element1;
121
		}
122
		if (element2 instanceof AbstractTask) {
123
			t2 = (AbstractTask) element2;
124
		}
125
		if (t1 != null && t2 != null) {
126
			if (t1.getCreationDate() != null) {
127
				return sortDirection * t1.getCreationDate().compareTo(t2.getCreationDate());
128
			}
129
		}
130
		return 0;
131
	}
132
133
	/**
134
	 * Return a array of values to pass to taskKeyComparator.compare() for sorting
135
	 * 
136
	 * @param element
137
	 * @return String array[component, taskId, summary]
138
	 */
139
	public static String[] getSortableFromElement(AbstractTaskContainer element) {
140
		final String a[] = new String[] { "", null, element.getSummary() };
141
142
		if (element instanceof AbstractTask) {
143
			AbstractTask task1 = (AbstractTask) element;
144
			if (task1.getTaskKey() != null) {
145
				a[1] = task1.getTaskKey();
146
			}
147
		}
148
		return a;
149
	}
150
151
	public int getSortDirection() {
152
		return sortDirection;
153
	}
154
155
	public void setSortDirection(int sortDirection) {
156
		this.sortDirection = sortDirection;
157
	}
158
159
	public SortByIndex getSortByIndex() {
160
		return sortByIndex;
161
	}
162
163
	public void setSortByIndex(SortByIndex sortByIndex) {
164
		this.sortByIndex = sortByIndex;
165
	}
166
167
	public int getSortDirection2() {
168
		return sortDirection2;
169
	}
170
171
	public void setSortDirection2(int sortDirection2) {
172
		this.sortDirection2 = sortDirection2;
173
	}
174
175
	public SortByIndex getSortByIndex2() {
176
		return sortByIndex2;
177
	}
178
179
	public void setSortByIndex2(SortByIndex sortByIndex2) {
180
		this.sortByIndex2 = sortByIndex2;
181
	}
182
183
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/TaskSearchResultSorter.java (+70 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 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
		 {
29
			AbstractTaskContainer entry1 = (AbstractTaskContainer) e1;
30
			AbstractTaskContainer entry2 = (AbstractTaskContainer) e2;
31
			return taskComparator.compare(entry1, entry2);
32
		} else {
33
		return super.compare(viewer, e1, e2);
34
		}
35
	}
36
37
	public int getSortDirection() {
38
		return taskComparator.getSortDirection();
39
	}
40
41
	public void setSortDirection(int sortDirection) {
42
		taskComparator.setSortDirection(sortDirection);
43
	}
44
45
	public SortByIndex getSortByIndex() {
46
		return taskComparator.getSortByIndex();
47
	}
48
49
	public void setSortByIndex(SortByIndex sortByIndex) {
50
		taskComparator.setSortByIndex(sortByIndex);
51
	}
52
53
	public int getSortDirection2() {
54
		return taskComparator.getSortDirection2();
55
	}
56
57
	public void setSortDirection2(int sortDirection) {
58
		taskComparator.setSortDirection2(sortDirection);
59
	}
60
61
	public SortByIndex getSortByIndex2() {
62
		return taskComparator.getSortByIndex2();
63
	}
64
65
	public void setSortByIndex2(SortByIndex sortByIndex) {
66
		taskComparator.setSortByIndex2(sortByIndex);
67
	}
68
69
70
}
(-)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 RepositorySearchResultView bugPage;
22
23
	private 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