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/TableSorterTest.java (-4 / +4 lines)
Lines 24-33 Link Here
24
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
24
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
25
import org.eclipse.mylyn.internal.tasks.core.WeekDateRange;
25
import org.eclipse.mylyn.internal.tasks.core.WeekDateRange;
26
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
26
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
27
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
27
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListInterestSorter;
28
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListInterestSorter;
28
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter;
29
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter;
29
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
30
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
30
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
31
import org.eclipse.mylyn.tasks.core.ITask;
31
import org.eclipse.mylyn.tasks.core.ITask;
32
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
32
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
33
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Control;
Lines 40-46 Link Here
40
40
41
	public void testRootTaskSorting() {
41
	public void testRootTaskSorting() {
42
		TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective(),
42
		TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective(),
43
				TaskListTableSorter.SortByIndex.SUMMARY);
43
				TaskComparator.SortByIndex.SUMMARY);
44
44
45
		ITask task = new LocalTask("1", "");
45
		ITask task = new LocalTask("1", "");
46
		TaskCategory category = new TaskCategory("cat");
46
		TaskCategory category = new TaskCategory("cat");
Lines 114-120 Link Here
114
		tasks[5] = new MockTask("local", "5", "a");
114
		tasks[5] = new MockTask("local", "5", "a");
115
115
116
		TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective());
116
		TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective());
117
		sorter.setSortByIndex(SortByIndex.SUMMARY);
117
		sorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
118
		sorter.sort(new EmptyViewer(), tasks);
118
		sorter.sort(new EmptyViewer(), tasks);
119
119
120
		assertEquals("1", tasks[0].getTaskKey());
120
		assertEquals("1", tasks[0].getTaskKey());
Lines 136-142 Link Here
136
		tasks[4] = new MockTask("local", "MYLN:5", "a");
136
		tasks[4] = new MockTask("local", "MYLN:5", "a");
137
137
138
		TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective());
138
		TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective());
139
		sorter.setSortByIndex(SortByIndex.SUMMARY);
139
		sorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
140
		sorter.sort(new EmptyViewer(), tasks);
140
		sorter.sort(new EmptyViewer(), tasks);
141
141
142
		assertEquals("MYLN:1", tasks[0].getTaskKey());
142
		assertEquals("MYLN:1", tasks[0].getTaskKey());
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java (-198 / +83 lines)
Lines 11-64 Link Here
11
11
12
package org.eclipse.mylyn.internal.tasks.ui.views;
12
package org.eclipse.mylyn.internal.tasks.ui.views;
13
13
14
import java.util.Date;
15
16
import org.eclipse.jface.dialogs.MessageDialog;
14
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.ViewerSorter;
16
import org.eclipse.jface.viewers.ViewerSorter;
19
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
17
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
18
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
20
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
19
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
20
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
21
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
21
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
22
import org.eclipse.mylyn.internal.tasks.core.TaskGroup;
22
import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer;
23
import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer;
23
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
24
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
25
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
24
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
26
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
25
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
26
import org.eclipse.mylyn.tasks.core.ITask;
27
import org.eclipse.mylyn.tasks.core.ITask;
27
import org.eclipse.mylyn.tasks.core.ITaskContainer;
28
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
29
29
30
/**
30
/**
31
 * @author Mik Kersten
31
 * @author Mik Kersten
32
 */
32
 */
33
public class TaskListTableSorter extends ViewerSorter {
33
public class TaskListTableSorter extends ViewerSorter {
34
	public static final int DEFAULT_SORT_DIRECTION = 1;
34
35
35
	public enum SortByIndex {
36
	private int sortDirectionRootElement = DEFAULT_SORT_DIRECTION;
36
		PRIORITY, SUMMARY, DATE_CREATED;
37
	}
38
39
	private static final int DEFAULT_SORT_DIRECTION = 1;
40
41
	private int sortDirection = DEFAULT_SORT_DIRECTION;
42
43
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
44
45
	private int sortDirection2 = DEFAULT_SORT_DIRECTION;
46
47
	private SortByIndex sortByIndex2 = SortByIndex.DATE_CREATED;
48
37
49
	private final TaskListView view;
38
	private final TaskListView view;
50
39
51
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
40
	private final TaskComparator taskComparator = new TaskComparator();
52
41
53
	public TaskListTableSorter(TaskListView view) {
42
	public TaskListTableSorter(TaskListView view) {
54
		super();
43
		super();
55
		this.view = view;
44
		this.view = view;
56
	}
45
	}
57
46
58
	public TaskListTableSorter(TaskListView view, SortByIndex index) {
47
	public TaskListTableSorter(TaskListView view, TaskComparator.SortByIndex index) {
59
		super();
48
		super();
60
		this.view = view;
49
		this.view = view;
61
		this.sortByIndex = index;
50
		taskComparator.setSortByIndex(index);
62
	}
51
	}
63
52
64
	public void setColumn(String column) {
53
	public void setColumn(String column) {
Lines 74-242 Link Here
74
	 */
63
	 */
75
	@Override
64
	@Override
76
	public int compare(Viewer compareViewer, Object o1, Object o2) {
65
	public int compare(Viewer compareViewer, Object o1, Object o2) {
77
66
		if (o1 instanceof AbstractTask && o2 instanceof AbstractTask) {
78
		if (o1 instanceof ScheduledTaskContainer && o2 instanceof ScheduledTaskContainer) {
67
			// sort of the tasks within the container using ste setting from the Sortdialog
68
			ITask element1 = (ITask) o1;
69
			ITask element2 = (ITask) o2;
70
71
			return compareElements(element1, element2);
72
		} else if (o1 instanceof ScheduledTaskContainer && o2 instanceof ScheduledTaskContainer) {
73
			// scheduled Mode compare
79
			ScheduledTaskContainer dateRangeTaskContainer1 = (ScheduledTaskContainer) o1;
74
			ScheduledTaskContainer dateRangeTaskContainer1 = (ScheduledTaskContainer) o1;
80
			ScheduledTaskContainer dateRangeTaskContainer2 = (ScheduledTaskContainer) o2;
75
			ScheduledTaskContainer dateRangeTaskContainer2 = (ScheduledTaskContainer) o2;
81
			return dateRangeTaskContainer1.getDateRange().compareTo(dateRangeTaskContainer2.getDateRange());
76
			return this.sortDirectionRootElement
82
//			if (dateRangeTaskContainer1.isCaptureFloating() && !dateRangeTaskContainer2.isCaptureFloating()) {
77
					* dateRangeTaskContainer1.getDateRange().compareTo(dateRangeTaskContainer2.getDateRange());
83
//				return 1;
78
		} else if (o1 instanceof UnmatchedTaskContainer) {
84
//			} else if (!dateRangeTaskContainer1.isCaptureFloating() && dateRangeTaskContainer2.isCaptureFloating()) {
79
			// UnmatchedTaskContainer is always the last entry
85
//				return -1;
80
			return this.sortDirectionRootElement * -1;
86
//			}
81
		} else if (o2 instanceof UnmatchedTaskContainer) {
87
//			return -1 * dateRangeTaskContainer2.getStart().compareTo(dateRangeTaskContainer1.getStart());
82
			// UnmatchedTaskContainer is always the last entry
88
		} else if (o1 instanceof ITaskContainer && o2 instanceof ScheduledTaskContainer) {
83
			return this.sortDirectionRootElement * 1;
89
			return -1;
84
		} else if (o1 instanceof UncategorizedTaskContainer) {
90
		} else if (o1 instanceof ScheduledTaskContainer && o2 instanceof ITaskContainer) {
85
			// UncategorizedTaskContainer is always the first entry
91
			return 1;
86
			return this.sortDirectionRootElement * 1;
92
		}
87
		} else if (o2 instanceof UncategorizedTaskContainer) {
93
88
			// UncategorizedTaskContainer is always the first entry
94
		if (o1 instanceof ITaskContainer && o2 instanceof UncategorizedTaskContainer) {
89
			return this.sortDirectionRootElement * -1;
95
			return 1;
90
		} else if (o1 instanceof TaskGroup && o2 instanceof TaskGroup) {
96
		} else if (o2 instanceof ITaskContainer && o1 instanceof UncategorizedTaskContainer) {
91
			// support for the experimental grouping of tasks
97
			return -1;
92
			TaskGroup taskGroupTaskContainer1 = (TaskGroup) o1;
98
		}
93
			TaskGroup taskGroupTaskContainer2 = (TaskGroup) o2;
99
94
100
		if (o1 instanceof ITaskContainer && o2 instanceof UnmatchedTaskContainer) {
95
			return this.sortDirectionRootElement
101
			return -1;
96
					* taskGroupTaskContainer1.getSummary().compareToIgnoreCase(taskGroupTaskContainer2.getSummary());
102
		} else if (o2 instanceof ITaskContainer && o1 instanceof UnmatchedTaskContainer) {
97
		} else if ((o1 instanceof AbstractTaskCategory || o1 instanceof RepositoryQuery)
103
			return 1;
98
				&& (o2 instanceof AbstractTaskCategory || o2 instanceof RepositoryQuery)) {
104
		}
99
			AbstractTaskContainer taskContainer1 = (AbstractTaskContainer) o1;
105
100
			AbstractTaskContainer taskContainer2 = (AbstractTaskContainer) o2;
106
		if (!(o1 instanceof ITask) && o2 instanceof ITask) {
107
			return 1;
108
		}
109
101
110
		if (o1 instanceof ITask && !(o2 instanceof ITaskContainer)) {
102
			return this.sortDirectionRootElement
111
			return -1;
103
					* taskContainer1.getSummary().compareToIgnoreCase(taskContainer2.getSummary());
112
		}
113
114
		// if (o1 instanceof AbstractTaskContainer || o1 instanceof
115
		// AbstractRepositoryQuery) {
116
		if (!(o1 instanceof ITask)) {
117
			if (o2 instanceof ITaskContainer || o2 instanceof IRepositoryQuery) {
118
119
				return this.sortDirection
120
						* ((IRepositoryElement) o1).getSummary().compareToIgnoreCase(
121
								((IRepositoryElement) o2).getSummary());
122
			} else {
123
				return -1;
124
			}
125
		} else if (o1 instanceof ITaskContainer) {
126
			if (!(o2 instanceof ITask)) {
127
				return -1;
128
			} else if (o2 instanceof ITaskContainer) {
129
				IRepositoryElement element1 = (IRepositoryElement) o1;
130
				IRepositoryElement element2 = (IRepositoryElement) o2;
131
132
				return compareElements(element1, element2);
133
			}
134
		} else {
135
			return 0;
136
		}
104
		}
137
		return 0;
105
		return 0;
138
	}
106
	}
139
107
140
	private int compareElements(IRepositoryElement element1, IRepositoryElement element2) {
108
	private int compareElements(ITask element1, ITask element2) {
141
		if (SortByIndex.PRIORITY.equals(sortByIndex)) {
109
		return taskComparator.compare(element1, element2);
142
			int result = sortByPriority(element1, element2, sortDirection);
143
			if (result != 0) {
144
				return result;
145
			}
146
147
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
148
				return sortByDate(element1, element2, sortDirection2);
149
			} else {
150
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
151
					return sortBySummary(element1, element2, sortDirection2);
152
				} else {
153
					return result;
154
				}
155
			}
156
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
157
			int result = sortByDate(element1, element2, sortDirection);
158
			if (result != 0) {
159
				return result;
160
			}
161
			if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
162
				return sortByPriority(element1, element2, sortDirection2);
163
			} else {
164
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
165
					return sortBySummary(element1, element2, sortDirection2);
166
				} else {
167
					return result;
168
				}
169
			}
170
		} else {
171
			int result = sortBySummary(element1, element2, sortDirection);
172
			if (result != 0) {
173
				return result;
174
			}
175
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
176
				return sortByDate(element1, element2, sortDirection2);
177
			} else {
178
				if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
179
					return sortByPriority(element1, element2, sortDirection2);
180
				} else {
181
					return result;
182
				}
183
			}
184
		}
185
	}
186
187
	/**
188
	 * Determine the sort order of two tasks by id/summary
189
	 * 
190
	 * @param element1
191
	 * @param element2
192
	 * @return sort order
193
	 */
194
	private int sortBySummary(IRepositoryElement element1, IRepositoryElement element2, int sortDirection) {
195
		return sortDirection
196
				* taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
197
	}
198
199
	/**
200
	 * Determine the sort order of two tasks by priority
201
	 * 
202
	 * @param element1
203
	 * @param element2
204
	 * @return sort order
205
	 */
206
	private int sortByPriority(IRepositoryElement element1, IRepositoryElement element2, int sortDirection) {
207
		return sortDirection
208
				* ((AbstractTaskContainer) element1).getPriority().compareTo(
209
						((AbstractTaskContainer) element2).getPriority());
210
	}
211
212
	/**
213
	 * Determine the sort order of two tasks by creation date
214
	 * 
215
	 * @param element1
216
	 * @param element2
217
	 * @return sort order
218
	 */
219
	private int sortByDate(IRepositoryElement element1, IRepositoryElement element2, int sortDirection) {
220
		AbstractTask t1 = null;
221
		AbstractTask t2 = null;
222
		if (element1 instanceof AbstractTask) {
223
			t1 = (AbstractTask) element1;
224
		}
225
		if (element2 instanceof AbstractTask) {
226
			t2 = (AbstractTask) element2;
227
		}
228
		if (t1 != null && t2 != null) {
229
			Date creationDate1 = t1.getCreationDate();
230
			if (creationDate1 != null) {
231
				Date creationDate2 = t2.getCreationDate();
232
				if (creationDate2 != null) {
233
					return sortDirection * creationDate1.compareTo(creationDate2);
234
				} else {
235
					return 1;
236
				}
237
			}
238
		}
239
		return 0;
240
	}
110
	}
241
111
242
	/**
112
	/**
Lines 257-310 Link Here
257
		return a;
127
		return a;
258
	}
128
	}
259
129
260
	public SortByIndex getSortByIndex() {
130
	public TaskComparator.SortByIndex getSortByIndex() {
261
		return sortByIndex;
131
		return taskComparator.getSortByIndex();
262
	}
132
	}
263
133
264
	public void setSortByIndex(SortByIndex sortByIndex) {
134
	public void setSortByIndex(TaskComparator.SortByIndex sortByIndex) {
265
		SortByIndex oldValue = this.sortByIndex;
135
		TaskComparator.SortByIndex oldValue = taskComparator.getSortByIndex();
266
		this.sortByIndex = sortByIndex;
267
		if (!oldValue.equals(sortByIndex)) {
136
		if (!oldValue.equals(sortByIndex)) {
268
			view.getViewer().refresh();
137
			taskComparator.setSortByIndex(sortByIndex);
269
		}
138
		}
270
139
271
	}
140
	}
272
141
273
	public int getSortDirection() {
142
	public int getSortDirection() {
274
		return sortDirection;
143
		return taskComparator.getSortDirection();
275
	}
144
	}
276
145
277
	public void setSortDirection(int sortDirection) {
146
	public void setSortDirection(int sortDirection) {
278
		int oldValue = this.sortDirection;
147
		int oldValue = taskComparator.getSortDirection();
279
		this.sortDirection = sortDirection;
148
		if (oldValue != sortDirection) {
280
		if (oldValue != this.sortDirection) {
149
			taskComparator.setSortDirection(sortDirection);
281
			view.getViewer().refresh();
282
		}
150
		}
283
	}
151
	}
284
152
285
	public SortByIndex getSortByIndex2() {
153
	public TaskComparator.SortByIndex getSortByIndex2() {
286
		return sortByIndex2;
154
		return taskComparator.getSortByIndex2();
287
	}
155
	}
288
156
289
	public void setSortByIndex2(SortByIndex sortByIndex) {
157
	public void setSortByIndex2(TaskComparator.SortByIndex sortByIndex) {
290
		SortByIndex oldValue = this.sortByIndex2;
158
		TaskComparator.SortByIndex oldValue = taskComparator.getSortByIndex2();
291
		this.sortByIndex2 = sortByIndex;
292
		if (!oldValue.equals(sortByIndex)) {
159
		if (!oldValue.equals(sortByIndex)) {
293
			view.getViewer().refresh();
160
			taskComparator.setSortByIndex2(sortByIndex);
294
		}
161
		}
295
162
296
	}
163
	}
297
164
298
	public int getSortDirection2() {
165
	public int getSortDirection2() {
299
		return sortDirection2;
166
		return taskComparator.getSortDirection2();
300
	}
167
	}
301
168
302
	public void setSortDirection2(int sortDirection) {
169
	public void setSortDirection2(int sortDirection) {
303
		int oldValue = this.sortDirection2;
170
		int oldValue = taskComparator.getSortDirection2();
304
		this.sortDirection2 = sortDirection;
171
		if (oldValue != sortDirection) {
305
		if (oldValue != this.sortDirection2) {
172
			taskComparator.setSortDirection2(sortDirection);
306
			view.getViewer().refresh();
173
		}
174
	}
175
176
	public int getSortDirectionRootElement() {
177
		return sortDirectionRootElement;
178
	}
179
180
	public void setSortDirectionRootElement(int sortDirection) {
181
		int oldValue = this.sortDirectionRootElement;
182
		this.sortDirectionRootElement = sortDirection;
183
		if (oldValue != this.sortDirectionRootElement) {
307
		}
184
		}
308
	}
185
	}
309
186
187
	public TaskComparator getTaskComparator() {
188
		return taskComparator;
189
	}
190
191
	public void refreshView() {
192
		view.getViewer().refresh();
193
	}
194
310
}
195
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/SortyByDropDownAction.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-22 Link Here
16
import org.eclipse.jface.action.IMenuCreator;
16
import org.eclipse.jface.action.IMenuCreator;
17
import org.eclipse.jface.action.Separator;
17
import org.eclipse.jface.action.Separator;
18
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
18
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
19
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
19
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
20
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Menu;
21
import org.eclipse.swt.widgets.Menu;
22
22
Lines 74-80 Link Here
74
		byPriority = new Action("", AS_CHECK_BOX) {
74
		byPriority = new Action("", AS_CHECK_BOX) {
75
			@Override
75
			@Override
76
			public void run() {
76
			public void run() {
77
				taskListView.getSorter().setSortByIndex(SortByIndex.PRIORITY);
77
				taskListView.getSorter().setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
78
				byPriority.setChecked(true);
78
				byPriority.setChecked(true);
79
				bySummary.setChecked(false);
79
				bySummary.setChecked(false);
80
				byDateCreated.setChecked(false);
80
				byDateCreated.setChecked(false);
Lines 88-94 Link Here
88
		bySummary = new Action("", AS_CHECK_BOX) {
88
		bySummary = new Action("", AS_CHECK_BOX) {
89
			@Override
89
			@Override
90
			public void run() {
90
			public void run() {
91
				taskListView.getSorter().setSortByIndex(SortByIndex.SUMMARY);
91
				taskListView.getSorter().setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
92
				byPriority.setChecked(false);
92
				byPriority.setChecked(false);
93
				bySummary.setChecked(true);
93
				bySummary.setChecked(true);
94
				byDateCreated.setChecked(false);
94
				byDateCreated.setChecked(false);
Lines 101-107 Link Here
101
		byDateCreated = new Action("", AS_CHECK_BOX) {
101
		byDateCreated = new Action("", AS_CHECK_BOX) {
102
			@Override
102
			@Override
103
			public void run() {
103
			public void run() {
104
				taskListView.getSorter().setSortByIndex(SortByIndex.DATE_CREATED);
104
				taskListView.getSorter().setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED);
105
				byPriority.setChecked(false);
105
				byPriority.setChecked(false);
106
				bySummary.setChecked(false);
106
				bySummary.setChecked(false);
107
				byDateCreated.setChecked(true);
107
				byDateCreated.setChecked(true);
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java (-8 / +29 lines)
Lines 104-114 Link Here
104
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListSortAction;
104
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListSortAction;
105
import org.eclipse.mylyn.internal.tasks.ui.commands.CollapseAllHandler;
105
import org.eclipse.mylyn.internal.tasks.ui.commands.CollapseAllHandler;
106
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskListChangeAdapter;
106
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskListChangeAdapter;
107
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
107
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
108
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
108
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
109
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
109
import org.eclipse.mylyn.internal.tasks.ui.util.TreeWalker;
110
import org.eclipse.mylyn.internal.tasks.ui.util.TreeWalker;
110
import org.eclipse.mylyn.internal.tasks.ui.util.TreeWalker.TreeVisitor;
111
import org.eclipse.mylyn.internal.tasks.ui.util.TreeWalker.TreeVisitor;
111
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
112
import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
112
import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
113
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
113
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
114
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
114
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
Lines 298-303 Link Here
298
298
299
	private static final String MEMENTO_KEY_SORT_DIRECTION = "sortDirection";
299
	private static final String MEMENTO_KEY_SORT_DIRECTION = "sortDirection";
300
300
301
	private static final String MEMENTO_KEY_ROOT_SORT_DIRECTION = "rootSortDirection";
302
301
	private static final String MEMENTO_KEY_SORTER = "sorter";
303
	private static final String MEMENTO_KEY_SORTER = "sorter";
302
304
303
	private static final String MEMENTO_KEY_SORTER2 = "sorter2";
305
	private static final String MEMENTO_KEY_SORTER2 = "sorter2";
Lines 761-766 Link Here
761
		case DATE_CREATED:
763
		case DATE_CREATED:
762
			m.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
764
			m.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
763
			break;
765
			break;
766
		case TASK_ID:
767
			m.putInteger(MEMENTO_KEY_SORT_INDEX, 3);
768
			break;
764
		default:
769
		default:
765
			m.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
770
			m.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
766
		}
771
		}
Lines 774-779 Link Here
774
		case DATE_CREATED:
779
		case DATE_CREATED:
775
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
780
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
776
			break;
781
			break;
782
		case TASK_ID:
783
			m.putInteger(MEMENTO_KEY_SORT_INDEX, 3);
784
			break;
777
		default:
785
		default:
778
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
786
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
779
		}
787
		}
Lines 781-786 Link Here
781
		m2.putInteger(MEMENTO_KEY_SORT_DIRECTION, tableSorter.getSortDirection2());
789
		m2.putInteger(MEMENTO_KEY_SORT_DIRECTION, tableSorter.getSortDirection2());
782
		memento.putString(MEMENTO_LINK_WITH_EDITOR, Boolean.toString(linkWithEditor));
790
		memento.putString(MEMENTO_LINK_WITH_EDITOR, Boolean.toString(linkWithEditor));
783
		memento.putString(MEMENTO_PRESENTATION, currentPresentation.getId());
791
		memento.putString(MEMENTO_PRESENTATION, currentPresentation.getId());
792
		memento.putInteger(MEMENTO_KEY_ROOT_SORT_DIRECTION, tableSorter.getSortDirectionRootElement());
784
	}
793
	}
785
794
786
	private void restoreState() {
795
	private void restoreState() {
Lines 803-815 Link Here
803
						tableSorter.setSortDirection(sortDirection);
812
						tableSorter.setSortDirection(sortDirection);
804
						switch (restoredSortIndex) {
813
						switch (restoredSortIndex) {
805
						case 1:
814
						case 1:
806
							tableSorter.setSortByIndex(SortByIndex.SUMMARY);
815
							tableSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
807
							break;
816
							break;
808
						case 2:
817
						case 2:
809
							tableSorter.setSortByIndex(SortByIndex.DATE_CREATED);
818
							tableSorter.setSortByIndex(TaskComparator.SortByIndex.DATE_CREATED);
819
							break;
820
						case 3:
821
							tableSorter.setSortByIndex(TaskComparator.SortByIndex.TASK_ID);
810
							break;
822
							break;
811
						default:
823
						default:
812
							tableSorter.setSortByIndex(SortByIndex.PRIORITY);
824
							tableSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
813
						}
825
						}
814
					}
826
					}
815
				}
827
				}
Lines 826-843 Link Here
826
						tableSorter.setSortDirection2(sortDirection);
838
						tableSorter.setSortDirection2(sortDirection);
827
						switch (restoredSortIndex) {
839
						switch (restoredSortIndex) {
828
						case 1:
840
						case 1:
829
							tableSorter.setSortByIndex2(SortByIndex.SUMMARY);
841
							tableSorter.setSortByIndex2(TaskComparator.SortByIndex.SUMMARY);
830
							break;
842
							break;
831
						case 2:
843
						case 2:
832
							tableSorter.setSortByIndex2(SortByIndex.DATE_CREATED);
844
							tableSorter.setSortByIndex2(TaskComparator.SortByIndex.DATE_CREATED);
845
							break;
846
						case 3:
847
							tableSorter.setSortByIndex2(TaskComparator.SortByIndex.TASK_ID);
833
							break;
848
							break;
834
						default:
849
						default:
835
							tableSorter.setSortByIndex2(SortByIndex.PRIORITY);
850
							tableSorter.setSortByIndex2(TaskComparator.SortByIndex.PRIORITY);
836
						}
851
						}
837
					}
852
					}
838
				}
853
				}
839
			}
854
			}
840
			applyPresentation(taskListMemento.getString(MEMENTO_PRESENTATION));
855
			applyPresentation(taskListMemento.getString(MEMENTO_PRESENTATION));
856
			Integer sortOrder = taskListMemento.getInteger(MEMENTO_KEY_ROOT_SORT_DIRECTION);
857
			if (sortOrder != null) {
858
				tableSorter.setSortDirectionRootElement(sortOrder);
859
			} else {
860
				tableSorter.setSortDirectionRootElement(TaskListTableSorter.DEFAULT_SORT_DIRECTION);
861
			}
841
		}
862
		}
842
863
843
		if (tableSorter == null) {
864
		if (tableSorter == null) {
Lines 1477-1483 Link Here
1477
		synchronizeAutomatically = new SynchronizeAutomaticallyAction();
1498
		synchronizeAutomatically = new SynchronizeAutomaticallyAction();
1478
		openPreferencesAction = new OpenTasksUiPreferencesAction();
1499
		openPreferencesAction = new OpenTasksUiPreferencesAction();
1479
		//filterArchiveCategory = new FilterArchiveContainerAction(this);
1500
		//filterArchiveCategory = new FilterArchiveContainerAction(this);
1480
		sortDialogAction = new TaskListSortAction(getSite(), this);
1501
		sortDialogAction = new TaskListSortAction(getSite(), tableSorter);
1481
		filterOnPriorityAction = new PriorityDropDownAction(this);
1502
		filterOnPriorityAction = new PriorityDropDownAction(this);
1482
		linkWithEditorAction = new LinkWithEditorAction(this);
1503
		linkWithEditorAction = new LinkWithEditorAction(this);
1483
		presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this);
1504
		presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this);
(-).refactorings/2008/10/43/refactorings.index (+2 lines)
Lines 1-2 Link Here
1
1224453298513	Delete element
1
1224453298513	Delete element
2
1224737272005	Extract local variable 'repositoryPerson'
2
1224737272005	Extract local variable 'repositoryPerson'
3
1224872029957	Delete elements
4
1224875091596	Delete element
(-).refactorings/2008/10/43/refactorings.history (-1 / +1 lines)
Lines 1-3 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<session version="1.0">&#x0A;<refactoring accessors="true" comment="Delete 1 element(s) from project &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original element: &apos;org.eclipse.mylyn.internal.tasks.ui.search.AbstractRepositorySearchQuery.java&apos;" description="Delete element" element1="/src&lt;org.eclipse.mylyn.internal.tasks.ui.search{AbstractRepositorySearchQuery.java" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224453298513" subPackages="false" version="1.0"/>&#x0A;<refactoring comment="Extract local variable &apos;repositoryPerson&apos; from expression &apos;getAttributeMapper().getRepositoryPerson(getTaskAttribute())&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Variable name: &apos;repositoryPerson&apos;&#x0A;- Destination method: &apos;org.eclipse.mylyn.internal.tasks.ui.editors.PersonAttributeEditor.getValue()&apos;&#x0A;- Variable expression: &apos;getAttributeMapper().getRepositoryPerson(getTaskAttribute())&apos;&#x0A;- Replace occurrences of expression with variable" description="Extract local variable &apos;repositoryPerson&apos;" final="false" id="org.eclipse.jdt.ui.extract.temp" input="/src&lt;org.eclipse.mylyn.internal.tasks.ui.editors{PersonAttributeEditor.java" name="repositoryPerson" replace="true" selection="987 60" stamp="1224737272005" version="1.0"/>
2
<session version="1.0">&#x0A;<refactoring accessors="true" comment="Delete 1 element(s) from project &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original element: &apos;org.eclipse.mylyn.internal.tasks.ui.search.AbstractRepositorySearchQuery.java&apos;" description="Delete element" element1="/src&lt;org.eclipse.mylyn.internal.tasks.ui.search{AbstractRepositorySearchQuery.java" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224453298513" subPackages="false" version="1.0"/>&#x0A;<refactoring comment="Extract local variable &apos;repositoryPerson&apos; from expression &apos;getAttributeMapper().getRepositoryPerson(getTaskAttribute())&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Variable name: &apos;repositoryPerson&apos;&#x0A;- Destination method: &apos;org.eclipse.mylyn.internal.tasks.ui.editors.PersonAttributeEditor.getValue()&apos;&#x0A;- Variable expression: &apos;getAttributeMapper().getRepositoryPerson(getTaskAttribute())&apos;&#x0A;- Replace occurrences of expression with variable" description="Extract local variable &apos;repositoryPerson&apos;" final="false" id="org.eclipse.jdt.ui.extract.temp" input="/src&lt;org.eclipse.mylyn.internal.tasks.ui.editors{PersonAttributeEditor.java" name="repositoryPerson" replace="true" selection="987 60" stamp="1224737272005" version="1.0"/>&#x0A;<refactoring accessors="true" comment="Delete 3 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.SearchResultSorterDescription.java&#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{SearchResultSorterDescription.java" element2="/src&lt;org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterId.java" element3="/src&lt;org.eclipse.mylyn.internal.tasks.ui.search{SearchResultSorterPriority.java" elements="3" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224872029957" subPackages="false" version="1.0"/>&#x0A;<refactoring accessors="true" comment="Delete 1 element(s) from project &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.tasks.ui&apos;&#x0A;- Original element: &apos;org.eclipse.mylyn.internal.tasks.ui.dialogs.SortResultSortDialog.java&apos;" description="Delete element" element1="/src&lt;org.eclipse.mylyn.internal.tasks.ui.dialogs{SortResultSortDialog.java" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1224875091596" subPackages="false" version="1.0"/>
3
</session>
3
</session>
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskListSortAction.java (-5 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-19 Link Here
12
package org.eclipse.mylyn.internal.tasks.ui.actions;
12
package org.eclipse.mylyn.internal.tasks.ui.actions;
13
13
14
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.window.Window;
15
import org.eclipse.mylyn.internal.tasks.ui.dialogs.TaskListSortDialog;
16
import org.eclipse.mylyn.internal.tasks.ui.dialogs.TaskListSortDialog;
16
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
17
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter;
17
import org.eclipse.ui.IWorkbenchPartSite;
18
import org.eclipse.ui.IWorkbenchPartSite;
18
19
19
/**
20
/**
Lines 23-37 Link Here
23
24
24
	private final TaskListSortDialog dialog;
25
	private final TaskListSortDialog dialog;
25
26
26
	public TaskListSortAction(IWorkbenchPartSite site, TaskListView taskListView) {
27
	TaskListTableSorter taskListTableSorter;
28
29
	public TaskListSortAction(IWorkbenchPartSite site, TaskListTableSorter taskListTableSorter) {
27
		super("Sort...");
30
		super("Sort...");
28
		setEnabled(true);
31
		setEnabled(true);
29
		dialog = new TaskListSortDialog(site, taskListView);
32
		dialog = new TaskListSortDialog(site, taskListTableSorter);
30
	}
33
	}
31
34
32
	@Override
35
	@Override
33
	public void run() {
36
	public void run() {
34
		dialog.open();
37
		if (dialog.open() == Window.OK) {
38
			taskListTableSorter.refreshView();
39
		}
35
	}
40
	}
36
41
37
}
42
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java (-217 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-267 Link Here
11
11
12
package org.eclipse.mylyn.internal.tasks.ui.dialogs;
12
package org.eclipse.mylyn.internal.tasks.ui.dialogs;
13
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Comparator;
17
18
import org.eclipse.jface.window.IShellProvider;
14
import org.eclipse.jface.window.IShellProvider;
15
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter;
19
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
16
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
20
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
21
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Combo;
28
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.ui.dialogs.SelectionDialog;
32
33
public class TaskListSortDialog extends SelectionDialog {
34
	private Combo[] priorityCombos;
35
24
36
	private Button[] ascendingButtons;
25
public class TaskListSortDialog extends TaskCompareDialog {
37
26
38
	private Button[] descendingButtons;
27
//	private final TaskListView taskListView;
39
28
40
	private final String[] propertyText;
29
	private Button ascendingRootButton;
41
30
42
	private boolean dirty = false;
31
	private Button descendingRootButton;
43
32
44
	private final TaskListView taskListView;
33
	private final TaskListTableSorter taskListTableSorter;
45
34
46
	public TaskListSortDialog(IShellProvider parentShell, TaskListView taskListView) {
35
	public TaskListSortDialog(IShellProvider parentShell, TaskListTableSorter taskListTableSorter) {
47
		super(parentShell.getShell());
36
		super(parentShell, taskListTableSorter.getTaskComparator());
48
		propertyText = new String[3];
37
		this.taskListTableSorter = taskListTableSorter;
49
		propertyText[0] = "Priority";
50
		propertyText[1] = "Summary";
51
		propertyText[2] = "Date Created";
52
		this.taskListView = taskListView;
53
		setTitle(TaskListView.LABEL_VIEW + " Sorting");
38
		setTitle(TaskListView.LABEL_VIEW + " Sorting");
54
	}
39
	}
55
40
56
	@Override
41
	@Override
57
	protected Control createDialogArea(Composite parent) {
42
	protected void createDialogStartArea(Composite parent) {
58
		Composite composite = (Composite) super.createDialogArea(parent);
43
		Label sortByHeader = new Label(parent, SWT.NULL);
59
44
		sortByHeader.setText("Sort order Container:");
60
		initializeDialogUnits(composite);
45
46
		ascendingRootButton = new Button(parent, SWT.RADIO);
47
		ascendingRootButton.setText("Ascending");
48
		ascendingRootButton.addSelectionListener(new SelectionAdapter() {
49
			@Override
50
			public void widgetSelected(SelectionEvent e) {
51
				markDirty();
52
			}
53
		});
61
54
62
		Composite prioritiesArea = new Composite(composite, SWT.NULL);
55
		descendingRootButton = new Button(parent, SWT.RADIO);
63
		prioritiesArea.setLayout(new GridLayout(3, false));
56
		descendingRootButton.setText("Descending");
57
		descendingRootButton.addSelectionListener(new SelectionAdapter() {
58
			@Override
59
			public void widgetSelected(SelectionEvent e) {
60
				markDirty();
61
			}
62
		});
64
63
65
		Label sortByLabel = new Label(prioritiesArea, SWT.NULL);
64
		Label sortByLabel = new Label(parent, SWT.NULL);
66
		sortByLabel.setText("Sort order:");
65
		sortByLabel.setText("Sort order within a Container:");
67
		GridData data = new GridData();
66
		GridData data = new GridData();
68
		data.horizontalSpan = 3;
67
		data.horizontalSpan = 3;
69
		sortByLabel.setLayoutData(data);
68
		sortByLabel.setLayoutData(data);
70
71
		ascendingButtons = new Button[2];
72
		descendingButtons = new Button[2];
73
		priorityCombos = new Combo[2];
74
75
		for (int i = 0; i < 2; i++) {
76
			final int index = i;
77
			Label numberLabel = new Label(prioritiesArea, SWT.NULL);
78
			numberLabel.setText("" + (i + 1) + ".");
79
			priorityCombos[i] = new Combo(prioritiesArea, SWT.READ_ONLY);
80
			priorityCombos[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
81
82
			Composite directionGroup = new Composite(prioritiesArea, SWT.NONE);
83
			directionGroup.setLayout(new GridLayout(2, false));
84
			ascendingButtons[i] = new Button(directionGroup, SWT.RADIO);
85
			ascendingButtons[i].setText("Ascending");
86
			ascendingButtons[i].addSelectionListener(new SelectionAdapter() {
87
				@Override
88
				public void widgetSelected(SelectionEvent e) {
89
					markDirty();
90
				}
91
			});
92
			descendingButtons[i] = new Button(directionGroup, SWT.RADIO);
93
			descendingButtons[i].setText("Descending");
94
			descendingButtons[i].addSelectionListener(new SelectionAdapter() {
95
				@Override
96
				public void widgetSelected(SelectionEvent e) {
97
					markDirty();
98
				}
99
			});
100
			if (i < priorityCombos.length - 1) {
101
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
102
					@Override
103
					public void widgetSelected(SelectionEvent e) {
104
						int oldSelectionDirection = 1;
105
						if (descendingButtons[index].getSelection()) {
106
							oldSelectionDirection = -1;
107
						}
108
						ArrayList<String> oldSelectionList = new ArrayList<String>(
109
								Arrays.asList(priorityCombos[index].getItems()));
110
						oldSelectionList.removeAll(Arrays.asList(priorityCombos[index + 1].getItems()));
111
						if (oldSelectionList.size() != 1) {
112
							return;
113
						}
114
						String oldSelection = oldSelectionList.get(0);
115
						String newSelection = priorityCombos[index].getItem(priorityCombos[index].getSelectionIndex());
116
						if (oldSelection.equals(newSelection)) {
117
							return;
118
						}
119
						for (int j = index + 1; j < priorityCombos.length; j++) {
120
							int newSelectionIndex = priorityCombos[j].indexOf(newSelection);
121
							//this combo's current selection is equal to newSelection
122
							if (priorityCombos[j].getSelectionIndex() == newSelectionIndex) {
123
								priorityCombos[j].remove(newSelection);
124
								int insertionPoint = -1
125
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
126
												columnComparator);
127
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
128
									priorityCombos[j].add(oldSelection, insertionPoint);
129
								} else {
130
									priorityCombos[j].add(oldSelection);
131
								}
132
								priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection));
133
								ascendingButtons[index].setSelection(ascendingButtons[j].getSelection());
134
								descendingButtons[index].setSelection(descendingButtons[j].getSelection());
135
								ascendingButtons[j].setSelection(oldSelectionDirection == 1);
136
								descendingButtons[j].setSelection(oldSelectionDirection == -1);
137
							}
138
							//this combo contains newSelection
139
							else if (newSelectionIndex >= 0) {
140
								String currentText = priorityCombos[j].getText();
141
								priorityCombos[j].remove(newSelection);
142
								int insertionPoint = -1
143
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
144
												columnComparator);
145
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
146
									priorityCombos[j].add(oldSelection, insertionPoint);
147
									priorityCombos[j].select(priorityCombos[j].indexOf(currentText));
148
								} else {
149
									priorityCombos[j].add(oldSelection);
150
								}
151
							}
152
						}
153
						markDirty();
154
					}
155
				});
156
			} else {
157
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
158
					@Override
159
					public void widgetSelected(SelectionEvent e) {
160
						markDirty();
161
					}
162
				});
163
			}
164
165
		}
166
		int a[] = new int[2];
167
		int b[] = new int[2];
168
		switch (taskListView.getSorter().getSortByIndex()) {
169
		case PRIORITY:
170
			a[0] = 0;
171
			break;
172
		case SUMMARY:
173
			a[0] = 1;
174
			break;
175
		case DATE_CREATED:
176
			a[0] = 2;
177
			break;
178
		}
179
180
		switch (taskListView.getSorter().getSortByIndex2()) {
181
		case PRIORITY:
182
			a[1] = 0;
183
			break;
184
		case SUMMARY:
185
			a[1] = 1;
186
			break;
187
		case DATE_CREATED:
188
			a[1] = 2;
189
			break;
190
		}
191
		b[0] = taskListView.getSorter().getSortDirection();
192
		b[1] = taskListView.getSorter().getSortDirection2();
193
		updateUI(a, b);
194
		return composite;
195
	}
69
	}
196
70
197
	@Override
71
	@Override
198
	protected void okPressed() {
72
	protected void okPressed() {
199
		if (isDirty()) {
73
		if (isDirty()) {
200
			taskListView.getSorter().setSortByIndex(
74
			if (descendingRootButton.getSelection()) {
201
					SortByIndex.valueOf(priorityCombos[0].getItem(priorityCombos[0].getSelectionIndex()).replace(' ',
75
				taskListTableSorter.setSortDirectionRootElement(-1);
202
							'_').toUpperCase()));
203
			taskListView.getSorter().setSortByIndex2(
204
					SortByIndex.valueOf(priorityCombos[1].getItem(priorityCombos[1].getSelectionIndex()).replace(' ',
205
							'_').toUpperCase()));
206
			if (descendingButtons[0].getSelection()) {
207
				taskListView.getSorter().setSortDirection(-1);
208
			} else {
209
				taskListView.getSorter().setSortDirection(1);
210
			}
211
			if (descendingButtons[1].getSelection()) {
212
				taskListView.getSorter().setSortDirection2(-1);
213
			} else {
76
			} else {
214
				taskListView.getSorter().setSortDirection2(1);
77
				taskListTableSorter.setSortDirectionRootElement(1);
215
			}
78
			}
216
217
		}
79
		}
218
		super.okPressed();
80
		super.okPressed();
219
	}
81
	}
220
82
221
	/**
83
	@Override
222
	 * @return boolean
84
	protected void updateUI(int[] priorities, int[] directions) {
223
	 */
85
		int headElementDirection = taskListTableSorter.getSortDirectionRootElement();
224
	public boolean isDirty() {
86
		super.updateUI(priorities, directions);
225
		return dirty;
87
		ascendingRootButton.setSelection(headElementDirection == 1);
226
	}
88
		descendingRootButton.setSelection(headElementDirection == -1);
227
228
	/**
229
	 * Sets the dirty flag to true.
230
	 */
231
	public void markDirty() {
232
		dirty = true;
233
	}
234
235
	private final Comparator<String> columnComparator = new Comparator<String>() {
236
		public int compare(String arg0, String arg1) {
237
			int index0 = -1;
238
			int index1 = -1;
239
			for (int i = 0; i < propertyText.length; i++) {
240
				if (propertyText[i].equals(arg0)) {
241
					index0 = i;
242
				}
243
				if (propertyText[i].equals(arg1)) {
244
					index1 = i;
245
				}
246
			}
247
			return index0 - index1;
248
		}
249
	};
250
251
	private void updateUI(int[] priorities, int[] directions) {
252
		ArrayList<String> availablePriorities = new ArrayList<String>(Arrays.asList(propertyText));
253
254
		for (int i = 0; i < priorityCombos.length; i++) {
255
			priorityCombos[i].removeAll();
256
			for (int j = 0; j < availablePriorities.size(); j++) {
257
				priorityCombos[i].add(availablePriorities.get(j));
258
			}
259
			priorityCombos[i].select(priorityCombos[i].indexOf(propertyText[priorities[i]]));
260
			availablePriorities.remove(propertyText[priorities[i]]);
261
262
			ascendingButtons[i].setSelection(directions[i] == 1);
263
			descendingButtons[i].setSelection(directions[i] == -1);
264
		}
265
	}
89
	}
266
90
267
}
91
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorterDescription.java (-77 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.internal.tasks.core.AbstractTask;
17
import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
18
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter;
19
import org.eclipse.mylyn.tasks.core.ITask;
20
21
/**
22
 * Sorts search results by summary.
23
 * 
24
 * @author Rob Elves
25
 */
26
public class SearchResultSorterDescription extends ViewerSorter {
27
28
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
29
30
	/**
31
	 * Returns a negative, zero, or positive number depending on whether the first bug's summary goes before, is the
32
	 * same as, or goes after the second element's summary.
33
	 * <p>
34
	 * 
35
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
36
	 *      java.lang.Object)
37
	 */
38
	@Override
39
	public int compare(Viewer viewer, Object e1, Object e2) {
40
		try {
41
42
			AbstractTask entry1 = (AbstractTask) e1;
43
			AbstractTask entry2 = (AbstractTask) e2;
44
			// NOTE we just comparing ids here, once summary and taskId separated
45
			// they should have their own column/sorter.
46
			return taskKeyComparator.compare(TaskListTableSorter.getSortableFromElement(entry1),
47
					TaskListTableSorter.getSortableFromElement(entry2));
48
			// return taskKeyComparator.compare(entry1.getDescription(),
49
			// entry2.getDescription());
50
		} catch (Exception ignored) {
51
			// do nothing
52
		}
53
54
		// if that didn't work, use the default compare method
55
		return super.compare(viewer, e1, e2);
56
	}
57
58
	/**
59
	 * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins
60
	 * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort
61
	 * criterion.
62
	 * <p>
63
	 * 
64
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(Object)
65
	 */
66
	@Override
67
	public int category(Object element) {
68
		try {
69
			ITask hit = (ITask) element;
70
			return Integer.parseInt(hit.getTaskId());
71
		} catch (Exception ignored) {
72
			// ignore if
73
		}
74
		// if that didn't work, use the default category method
75
		return super.category(element);
76
	}
77
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSortAction.java (-17 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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("Sort...");
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/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 (-19 / +28 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 39-44 Link Here
39
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
39
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
40
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskSearchAction;
40
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskSearchAction;
41
import org.eclipse.mylyn.internal.tasks.ui.search.SearchResultTreeContentProvider.GroupBy;
41
import org.eclipse.mylyn.internal.tasks.ui.search.SearchResultTreeContentProvider.GroupBy;
42
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
42
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
43
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
43
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListToolTip;
44
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListToolTip;
44
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
45
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
Lines 46-52 Link Here
46
import org.eclipse.mylyn.tasks.core.TaskRepository;
47
import org.eclipse.mylyn.tasks.core.TaskRepository;
47
import org.eclipse.mylyn.tasks.ui.TasksUi;
48
import org.eclipse.mylyn.tasks.ui.TasksUi;
48
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
49
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
49
import org.eclipse.search.internal.ui.SearchMessages;
50
import org.eclipse.search.ui.IContextMenuConstants;
50
import org.eclipse.search.ui.IContextMenuConstants;
51
import org.eclipse.search.ui.ISearchResult;
51
import org.eclipse.search.ui.ISearchResult;
52
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
52
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
Lines 145-153 Link Here
145
145
146
	private int currentSortOrder;
146
	private int currentSortOrder;
147
147
148
	private final SearchResultSortAction sortByPriorityAction;
148
//	private final SearchResultSortAction sortByPriorityAction;
149
//
150
//	private final SearchResultSortAction sortByDescriptionAction;
149
151
150
	private final SearchResultSortAction sortByDescriptionAction;
152
	private SearchResultSortAction sortByDialogAction;
151
153
152
	private final OpenSearchResultAction openInEditorAction;
154
	private final OpenSearchResultAction openInEditorAction;
153
155
Lines 169-180 Link Here
169
		}
171
		}
170
	};
172
	};
171
173
174
	private SearchResultSorter searchResultSorter;
175
172
	public RepositorySearchResultView() {
176
	public RepositorySearchResultView() {
173
		// Only use the table layout.
177
		// Only use the table layout.
174
		super(FLAG_LAYOUT_TREE);
178
		super(FLAG_LAYOUT_TREE);
175
179
176
		sortByPriorityAction = new SearchResultSortAction("Task Priority", this, ORDER_PRIORITY);
180
//		sortByPriorityAction = new SearchResultSortAction("Task Priority", this, ORDER_PRIORITY);
177
		sortByDescriptionAction = new SearchResultSortAction("Task Summary", this, ORDER_DESCRIPTION);
181
//		sortByDescriptionAction = new SearchResultSortAction("Task Summary", this, ORDER_DESCRIPTION);
182
178
		currentSortOrder = ORDER_DEFAULT;
183
		currentSortOrder = ORDER_DEFAULT;
179
184
180
		openInEditorAction = new OpenSearchResultAction("Open in Editor", this);
185
		openInEditorAction = new OpenSearchResultAction("Open in Editor", this);
Lines 233-238 Link Here
233
				searchResultProvider, viewer), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
238
				searchResultProvider, viewer), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
234
		viewer.setLabelProvider(labelProvider);
239
		viewer.setLabelProvider(labelProvider);
235
240
241
		searchResultSorter = new SearchResultSorter(this);
242
		viewer.setSorter(searchResultSorter);
243
		sortByDialogAction = new SearchResultSortAction(getSite(), searchResultSorter);
236
		// Set the order when the search view is loading so that the items are
244
		// Set the order when the search view is loading so that the items are
237
		// sorted right away
245
		// sorted right away
238
		setSortOrder(currentSortOrder);
246
		setSortOrder(currentSortOrder);
Lines 314-340 Link Here
314
	 *            The new category to sort by
322
	 *            The new category to sort by
315
	 */
323
	 */
316
	public void setSortOrder(int sortOrder) {
324
	public void setSortOrder(int sortOrder) {
317
		StructuredViewer viewer = getViewer();
318
319
		switch (sortOrder) {
325
		switch (sortOrder) {
320
		case ORDER_ID:
326
		case ORDER_ID:
321
			viewer.setSorter(new SearchResultSorterId());
327
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.TASK_ID);
322
			break;
328
			break;
323
		case ORDER_DESCRIPTION:
329
		case ORDER_DESCRIPTION:
324
			viewer.setSorter(new SearchResultSorterDescription());
330
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.SUMMARY);
325
			break;
331
			break;
326
		case ORDER_PRIORITY:
332
		case ORDER_PRIORITY:
327
			viewer.setSorter(new SearchResultSorterPriority());
333
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
328
			break;
334
			break;
329
		default:
335
		default:
330
			// If the setting is not one of the four valid ones,
336
			// If the setting is not one of the four valid ones,
331
			// use the default order setting.
337
			// use the default order setting.
332
			sortOrder = ORDER_DEFAULT;
338
			sortOrder = ORDER_DEFAULT;
333
			viewer.setSorter(new SearchResultSorterPriority());
339
			searchResultSorter.setSortByIndex(TaskComparator.SortByIndex.PRIORITY);
334
			break;
340
			break;
335
		}
341
		}
336
		currentSortOrder = sortOrder;
342
		currentSortOrder = sortOrder;
337
		getSettings().put(KEY_SORTING, currentSortOrder);
343
		getSettings().put(KEY_SORTING, currentSortOrder);
344
//		searchResultSorter.refresh(searchResultSorter.getRoot(), updateLabels);
345
		this.getViewer().refresh();
338
	}
346
	}
339
347
340
	@SuppressWarnings("unchecked")
348
	@SuppressWarnings("unchecked")
Lines 359-373 Link Here
359
	@Override
367
	@Override
360
	protected void fillContextMenu(IMenuManager menuManager) {
368
	protected void fillContextMenu(IMenuManager menuManager) {
361
		super.fillContextMenu(menuManager);
369
		super.fillContextMenu(menuManager);
362
		MenuManager sortMenuManager = new MenuManager(SearchMessages.SortDropDownAction_label);
370
//		MenuManager sortMenuManager = new MenuManager(SearchMessages.SortDropDownAction_label);
363
		sortMenuManager.add(sortByPriorityAction);
371
//		sortMenuManager.add(sortByPriorityAction);
364
		sortMenuManager.add(sortByDescriptionAction);
372
//		sortMenuManager.add(sortByDescriptionAction);
365
373
//
366
		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
374
//		sortByPriorityAction.setChecked(currentSortOrder == sortByPriorityAction.getSortOrder());
367
		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
375
//		sortByDescriptionAction.setChecked(currentSortOrder == sortByDescriptionAction.getSortOrder());
368
376
377
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortByDialogAction);
369
		// Add the new context menu items
378
		// Add the new context menu items
370
		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
379
//		menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenuManager);
371
		for (Action action : groupingActions) {
380
		for (Action action : groupingActions) {
372
			menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, action);
381
			menuManager.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, action);
373
		}
382
		}
(-)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
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparator.java (+151 lines)
Added 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.util;
13
14
import java.util.Comparator;
15
16
import org.eclipse.mylyn.tasks.core.ITask;
17
18
public class TaskComparator implements Comparator<ITask> {
19
20
	public enum SortByIndex {
21
		PRIORITY, SUMMARY, DATE_CREATED, TASK_ID;
22
	}
23
24
	public static final int DEFAULT_SORT_DIRECTION = 1;
25
26
	private int sortDirection = DEFAULT_SORT_DIRECTION;
27
28
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
29
30
	private int sortDirection2 = DEFAULT_SORT_DIRECTION;
31
32
	private SortByIndex sortByIndex2 = SortByIndex.DATE_CREATED;
33
34
	public int compare(ITask element1, ITask element2) {
35
		if (SortByIndex.PRIORITY.equals(sortByIndex)) {
36
			int result = sortByPriority(element1, element2, sortDirection);
37
			if (result != 0) {
38
				return result;
39
			}
40
41
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
42
				return sortByDate(element1, element2, sortDirection2);
43
			} else {
44
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
45
					return sortBySummary(element1, element2, sortDirection2);
46
				} else if (SortByIndex.TASK_ID.equals(sortByIndex2)) {
47
					return sortByID(element1, element2, sortDirection2);
48
				} else {
49
					return result;
50
				}
51
			}
52
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
53
			int result = sortByDate(element1, element2, sortDirection);
54
			if (result != 0) {
55
				return result;
56
			}
57
			if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
58
				return sortByPriority(element1, element2, sortDirection2);
59
			} else {
60
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
61
					return sortBySummary(element1, element2, sortDirection2);
62
				} else if (SortByIndex.TASK_ID.equals(sortByIndex2)) {
63
					return sortByID(element1, element2, sortDirection2);
64
				} else {
65
					return result;
66
				}
67
			}
68
		} else if (SortByIndex.SUMMARY.equals(sortByIndex)) {
69
			int result = sortBySummary(element1, element2, sortDirection);
70
			if (result != 0) {
71
				return result;
72
			}
73
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
74
				return sortByDate(element1, element2, sortDirection2);
75
			} else {
76
				if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
77
					return sortByPriority(element1, element2, sortDirection2);
78
				} else if (SortByIndex.TASK_ID.equals(sortByIndex2)) {
79
					return sortByID(element1, element2, sortDirection2);
80
				} else {
81
					return result;
82
				}
83
			}
84
		} else {
85
			int result = sortByID(element1, element2, sortDirection);
86
			if (result != 0) {
87
				return result;
88
			}
89
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
90
				return sortByDate(element1, element2, sortDirection2);
91
			} else {
92
				if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
93
					return sortByPriority(element1, element2, sortDirection2);
94
				} else if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
95
					return sortBySummary(element1, element2, sortDirection2);
96
				} else {
97
					return result;
98
				}
99
			}
100
		}
101
	}
102
103
	private int sortBySummary(ITask element1, ITask element2, int sortDirection) {
104
		return sortDirection * (element1.getSummary().compareTo(element2.getSummary()));
105
	}
106
107
	private int sortByID(ITask element1, ITask element2, int sortDirection) {
108
		return sortDirection * (element1.getTaskId().compareTo(element2.getTaskId()));
109
	}
110
111
	private int sortByPriority(ITask element1, ITask element2, int sortDirection) {
112
		return sortDirection * (element1.getPriority().compareTo(element2.getPriority()));
113
	}
114
115
	private int sortByDate(ITask element1, ITask element2, int sortDirection) {
116
		return sortDirection * (element1.getCreationDate().compareTo(element2.getCreationDate()));
117
	}
118
119
	public SortByIndex getSortByIndex() {
120
		return sortByIndex;
121
	}
122
123
	public void setSortByIndex(SortByIndex sortByIndex) {
124
		this.sortByIndex = sortByIndex;
125
	}
126
127
	public int getSortDirection() {
128
		return sortDirection;
129
	}
130
131
	public void setSortDirection(int sortDirection) {
132
		this.sortDirection = sortDirection;
133
	}
134
135
	public SortByIndex getSortByIndex2() {
136
		return sortByIndex2;
137
	}
138
139
	public void setSortByIndex2(SortByIndex sortByIndex) {
140
		this.sortByIndex2 = sortByIndex;
141
	}
142
143
	public int getSortDirection2() {
144
		return sortDirection2;
145
	}
146
147
	public void setSortDirection2(int sortDirection) {
148
		this.sortDirection2 = sortDirection;
149
	}
150
151
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskCompareDialog.java (+275 lines)
Added 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.dialogs;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Comparator;
17
18
import org.eclipse.jface.window.IShellProvider;
19
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
20
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Combo;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.ui.dialogs.SelectionDialog;
32
33
public class TaskCompareDialog extends SelectionDialog {
34
	private Combo[] priorityCombos;
35
36
	private Button[] ascendingButtons;
37
38
	private Button[] descendingButtons;
39
40
	private final String[] propertyText;
41
42
	private boolean dirty = false;
43
44
	private final TaskComparator taskComparator;
45
46
	public TaskCompareDialog(IShellProvider parentShell, TaskComparator taskComparator) {
47
		super(parentShell.getShell());
48
		propertyText = new String[4];
49
		propertyText[0] = "Priority";
50
		propertyText[1] = "Summary";
51
		propertyText[2] = "Date Created";
52
		propertyText[3] = "Task ID";
53
		this.taskComparator = taskComparator;
54
		setTitle(TaskListView.LABEL_VIEW + " Sorting");
55
	}
56
57
	protected void createDialogStartArea(Composite parent) {
58
		Label sortByLabel = new Label(parent, SWT.NULL);
59
		sortByLabel.setText("Sort order:");
60
		GridData data = new GridData();
61
		data.horizontalSpan = 3;
62
		sortByLabel.setLayoutData(data);
63
	}
64
65
	@Override
66
	protected Control createDialogArea(Composite parent) {
67
		Composite composite = (Composite) super.createDialogArea(parent);
68
69
		initializeDialogUnits(composite);
70
71
		Composite prioritiesArea = new Composite(composite, SWT.NULL);
72
		prioritiesArea.setLayout(new GridLayout(3, false));
73
74
		createDialogStartArea(prioritiesArea);
75
76
		ascendingButtons = new Button[2];
77
		descendingButtons = new Button[2];
78
		priorityCombos = new Combo[2];
79
80
		for (int i = 0; i < 2; i++) {
81
			final int index = i;
82
			Label numberLabel = new Label(prioritiesArea, SWT.NULL);
83
			numberLabel.setText("" + (i + 1) + ".");
84
			priorityCombos[i] = new Combo(prioritiesArea, SWT.READ_ONLY);
85
			priorityCombos[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
86
87
			Composite directionGroup = new Composite(prioritiesArea, SWT.NONE);
88
			directionGroup.setLayout(new GridLayout(2, false));
89
			ascendingButtons[i] = new Button(directionGroup, SWT.RADIO);
90
			ascendingButtons[i].setText("Ascending");
91
			ascendingButtons[i].addSelectionListener(new SelectionAdapter() {
92
				@Override
93
				public void widgetSelected(SelectionEvent e) {
94
					markDirty();
95
				}
96
			});
97
			descendingButtons[i] = new Button(directionGroup, SWT.RADIO);
98
			descendingButtons[i].setText("Descending");
99
			descendingButtons[i].addSelectionListener(new SelectionAdapter() {
100
				@Override
101
				public void widgetSelected(SelectionEvent e) {
102
					markDirty();
103
				}
104
			});
105
			if (i < priorityCombos.length - 1) {
106
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
107
					@Override
108
					public void widgetSelected(SelectionEvent e) {
109
						int oldSelectionDirection = 1;
110
						if (descendingButtons[index].getSelection()) {
111
							oldSelectionDirection = -1;
112
						}
113
						ArrayList<String> oldSelectionList = new ArrayList<String>(
114
								Arrays.asList(priorityCombos[index].getItems()));
115
						oldSelectionList.removeAll(Arrays.asList(priorityCombos[index + 1].getItems()));
116
						if (oldSelectionList.size() != 1) {
117
							return;
118
						}
119
						String oldSelection = oldSelectionList.get(0);
120
						String newSelection = priorityCombos[index].getItem(priorityCombos[index].getSelectionIndex());
121
						if (oldSelection.equals(newSelection)) {
122
							return;
123
						}
124
						for (int j = index + 1; j < priorityCombos.length; j++) {
125
							int newSelectionIndex = priorityCombos[j].indexOf(newSelection);
126
							//this combo's current selection is equal to newSelection
127
							if (priorityCombos[j].getSelectionIndex() == newSelectionIndex) {
128
								priorityCombos[j].remove(newSelection);
129
								int insertionPoint = -1
130
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
131
												columnComparator);
132
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
133
									priorityCombos[j].add(oldSelection, insertionPoint);
134
								} else {
135
									priorityCombos[j].add(oldSelection);
136
								}
137
								priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection));
138
								ascendingButtons[index].setSelection(ascendingButtons[j].getSelection());
139
								descendingButtons[index].setSelection(descendingButtons[j].getSelection());
140
								ascendingButtons[j].setSelection(oldSelectionDirection == 1);
141
								descendingButtons[j].setSelection(oldSelectionDirection == -1);
142
							}
143
							//this combo contains newSelection
144
							else if (newSelectionIndex >= 0) {
145
								String currentText = priorityCombos[j].getText();
146
								priorityCombos[j].remove(newSelection);
147
								int insertionPoint = -1
148
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
149
												columnComparator);
150
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
151
									priorityCombos[j].add(oldSelection, insertionPoint);
152
									priorityCombos[j].select(priorityCombos[j].indexOf(currentText));
153
								} else {
154
									priorityCombos[j].add(oldSelection);
155
								}
156
							}
157
						}
158
						markDirty();
159
					}
160
				});
161
			} else {
162
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
163
					@Override
164
					public void widgetSelected(SelectionEvent e) {
165
						markDirty();
166
					}
167
				});
168
			}
169
170
		}
171
		int a[] = new int[2];
172
		int b[] = new int[2];
173
		switch (taskComparator.getSortByIndex()) {
174
		case PRIORITY:
175
			a[0] = 0;
176
			break;
177
		case SUMMARY:
178
			a[0] = 1;
179
			break;
180
		case DATE_CREATED:
181
			a[0] = 2;
182
			break;
183
		case TASK_ID:
184
			a[0] = 3;
185
			break;
186
		}
187
188
		switch (taskComparator.getSortByIndex2()) {
189
		case PRIORITY:
190
			a[1] = 0;
191
			break;
192
		case SUMMARY:
193
			a[1] = 1;
194
			break;
195
		case DATE_CREATED:
196
			a[1] = 2;
197
			break;
198
		case TASK_ID:
199
			a[1] = 3;
200
			break;
201
		}
202
		b[0] = taskComparator.getSortDirection();
203
		b[1] = taskComparator.getSortDirection2();
204
		updateUI(a, b);
205
		return composite;
206
	}
207
208
	@Override
209
	protected void okPressed() {
210
		if (isDirty()) {
211
			taskComparator.setSortByIndex(TaskComparator.SortByIndex.valueOf(priorityCombos[0].getItem(
212
					priorityCombos[0].getSelectionIndex()).replace(' ', '_').toUpperCase()));
213
			taskComparator.setSortByIndex2(TaskComparator.SortByIndex.valueOf(priorityCombos[1].getItem(
214
					priorityCombos[1].getSelectionIndex()).replace(' ', '_').toUpperCase()));
215
			if (descendingButtons[0].getSelection()) {
216
				taskComparator.setSortDirection(-1);
217
			} else {
218
				taskComparator.setSortDirection(1);
219
			}
220
			if (descendingButtons[1].getSelection()) {
221
				taskComparator.setSortDirection2(-1);
222
			} else {
223
				taskComparator.setSortDirection2(1);
224
			}
225
226
		}
227
		super.okPressed();
228
	}
229
230
	/**
231
	 * @return boolean
232
	 */
233
	public boolean isDirty() {
234
		return dirty;
235
	}
236
237
	/**
238
	 * Sets the dirty flag to true.
239
	 */
240
	public void markDirty() {
241
		dirty = true;
242
	}
243
244
	private final Comparator<String> columnComparator = new Comparator<String>() {
245
		public int compare(String arg0, String arg1) {
246
			int index0 = -1;
247
			int index1 = -1;
248
			for (int i = 0; i < propertyText.length; i++) {
249
				if (propertyText[i].equals(arg0)) {
250
					index0 = i;
251
				}
252
				if (propertyText[i].equals(arg1)) {
253
					index1 = i;
254
				}
255
			}
256
			return index0 - index1;
257
		}
258
	};
259
260
	protected void updateUI(int[] priorities, int[] directions) {
261
		ArrayList<String> availablePriorities = new ArrayList<String>(Arrays.asList(propertyText));
262
263
		for (int i = 0; i < priorityCombos.length; i++) {
264
			priorityCombos[i].removeAll();
265
			for (int j = 0; j < availablePriorities.size(); j++) {
266
				priorityCombos[i].add(availablePriorities.get(j));
267
			}
268
			priorityCombos[i].select(priorityCombos[i].indexOf(propertyText[priorities[i]]));
269
			availablePriorities.remove(propertyText[priorities[i]]);
270
			ascendingButtons[i].setSelection(directions[i] == 1);
271
			descendingButtons[i].setSelection(directions[i] == -1);
272
		}
273
	}
274
275
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/search/SearchResultSorter.java (+109 lines)
Added 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.internal.tasks.ui.util.TaskComparator;
17
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator.SortByIndex;
18
import org.eclipse.mylyn.tasks.core.ITask;
19
20
public class SearchResultSorter extends ViewerSorter {
21
22
	private final RepositorySearchResultView view;
23
24
	private final TaskComparator taskComparator = new TaskComparator();
25
26
	public SearchResultSorter(RepositorySearchResultView view) {
27
		super();
28
		this.view = view;
29
	}
30
31
	/**
32
	 * Returns a negative, zero, or positive number depending on whether the first bug's taskId is less than, equal to,
33
	 * or greater than the second bug's taskId.
34
	 * <p>
35
	 * 
36
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
37
	 *      java.lang.Object)
38
	 */
39
	@Override
40
	public int compare(Viewer viewer, Object e1, Object e2) {
41
		if (e1 instanceof ITask && e2 instanceof ITask) {
42
			ITask entry1 = (ITask) e1;
43
			ITask entry2 = (ITask) e2;
44
			return taskComparator.compare(entry1, entry2);
45
		} else {
46
			return super.compare(viewer, e1, e2);
47
		}
48
	}
49
50
	/**
51
	 * Returns the category of the given element. The category is a number used to allocate elements to bins; the bins
52
	 * are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort
53
	 * criterion.
54
	 * <p>
55
	 * 
56
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(Object)
57
	 */
58
	@Override
59
	public int category(Object element) {
60
		try {
61
			ITask hit = (ITask) element;
62
			return Integer.parseInt(hit.getTaskId());
63
		} catch (Exception ignored) {
64
			// ignore if there is a problem
65
		}
66
		// if that didn't work, use the default category method
67
		return super.category(element);
68
	}
69
70
	public int getSortDirection() {
71
		return taskComparator.getSortDirection();
72
	}
73
74
	public void setSortDirection(int sortDirection) {
75
		taskComparator.setSortDirection(sortDirection);
76
	}
77
78
	public SortByIndex getSortByIndex() {
79
		return taskComparator.getSortByIndex();
80
	}
81
82
	public void setSortByIndex(SortByIndex sortByIndex) {
83
		taskComparator.setSortByIndex(sortByIndex);
84
	}
85
86
	public int getSortDirection2() {
87
		return taskComparator.getSortDirection2();
88
	}
89
90
	public void setSortDirection2(int sortDirection) {
91
		taskComparator.setSortDirection2(sortDirection);
92
	}
93
94
	public SortByIndex getSortByIndex2() {
95
		return taskComparator.getSortByIndex2();
96
	}
97
98
	public void setSortByIndex2(SortByIndex sortByIndex) {
99
		taskComparator.setSortByIndex2(sortByIndex);
100
	}
101
102
	public TaskComparator getTaskComparator() {
103
		return taskComparator;
104
	}
105
106
	public void refreshView() {
107
		view.getViewer().refresh();
108
	}
109
}

Return to bug 216150