View | Details | Raw Unified | Return to bug 219540 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/tasks/tests/TableSorterTest.java (+48 lines)
Lines 112-115 Link Here
112
		sorter.sort(new EmptyViewer(), tasks);
112
		sorter.sort(new EmptyViewer(), tasks);
113
	}
113
	}
114
114
115
	public void test2LevelSort() {
116
		final TaskListTableSorter sorter = new TaskListTableSorter(TaskListView.getFromActivePerspective());
117
		final MockTask[] tasks = new MockTask[5];
118
		tasks[0] = new MockTask("local", "4", "c");
119
		tasks[1] = new MockTask("local", "1", "b");
120
		tasks[2] = new MockTask("local", "11", "a");
121
		tasks[2].setPriority("P1");
122
		tasks[3] = new MockTask("local", "3", "c");
123
		tasks[4] = new MockTask("local", "5", "a");
124
125
		// sort by PRIORITY then by SUMMARY
126
		sorter.setSortByIndex(TaskListTableSorter.SortByIndex.PRIORITY);
127
		sorter.setSortByIndex2(TaskListTableSorter.SortByIndex.SUMMARY);
128
		sorter.sort(new EmptyViewer(), tasks);
129
		assertTrue("11".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary()));
130
		assertTrue("1".equals(tasks[1].getTaskKey()) && "b".equals(tasks[1].getSummary()));
131
		assertTrue("3".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
132
		assertTrue("4".equals(tasks[3].getTaskKey()) && "c".equals(tasks[3].getSummary()));
133
		assertTrue("5".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary()));
134
135
		// sort by PRIORITY then by SUMMARY descending
136
		sorter.setSortDirection2(-1);
137
		sorter.sort(new EmptyViewer(), tasks);
138
		assertTrue("11".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary()));
139
		assertTrue("1".equals(tasks[4].getTaskKey()) && "b".equals(tasks[4].getSummary()));
140
		assertTrue("3".equals(tasks[3].getTaskKey()) && "c".equals(tasks[3].getSummary()));
141
		assertTrue("4".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
142
		assertTrue("5".equals(tasks[1].getTaskKey()) && "a".equals(tasks[1].getSummary()));
143
144
		// sort by PRIORITY descending then by SUMMARY descending
145
		sorter.setSortDirection(-1);
146
		sorter.sort(new EmptyViewer(), tasks);
147
		assertTrue("11".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary()));
148
		assertTrue("1".equals(tasks[3].getTaskKey()) && "b".equals(tasks[3].getSummary()));
149
		assertTrue("3".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
150
		assertTrue("4".equals(tasks[1].getTaskKey()) && "c".equals(tasks[1].getSummary()));
151
		assertTrue("5".equals(tasks[0].getTaskKey()) && "a".equals(tasks[0].getSummary()));
152
153
		// sort by PRIORITY descending then by SUMMARY
154
		sorter.setSortDirection2(1);
155
		sorter.sort(new EmptyViewer(), tasks);
156
		assertTrue("11".equals(tasks[4].getTaskKey()) && "a".equals(tasks[4].getSummary()));
157
		assertTrue("1".equals(tasks[0].getTaskKey()) && "b".equals(tasks[0].getSummary()));
158
		assertTrue("3".equals(tasks[1].getTaskKey()) && "c".equals(tasks[1].getSummary()));
159
		assertTrue("4".equals(tasks[2].getTaskKey()) && "c".equals(tasks[2].getSummary()));
160
		assertTrue("5".equals(tasks[3].getTaskKey()) && "a".equals(tasks[3].getSummary()));
161
	}
162
115
}
163
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java (-18 / +100 lines)
Lines 35-40 Link Here
35
35
36
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
36
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
37
37
38
	private int sortDirection2 = DEFAULT_SORT_DIRECTION;
39
40
	private SortByIndex sortByIndex2 = SortByIndex.DATE_CREATED;
41
38
	private final TaskListView view;
42
	private final TaskListView view;
39
43
40
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
44
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
Lines 127-156 Link Here
127
131
128
	private int compareElements(AbstractTaskContainer element1, AbstractTaskContainer element2) {
132
	private int compareElements(AbstractTaskContainer element1, AbstractTaskContainer element2) {
129
		if (SortByIndex.PRIORITY.equals(sortByIndex)) {
133
		if (SortByIndex.PRIORITY.equals(sortByIndex)) {
130
			int result = this.sortDirection * element1.getPriority().compareTo(element2.getPriority());
134
			int result = sortByPriority(element1, element2, sortDirection);
131
			if (result != 0) {
135
			if (result != 0) {
132
				return result;
136
				return result;
133
			}
137
			}
134
			return sortBySummary(element1, element2);
138
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
135
139
				return sortByDate(element1, element2, sortDirection2);
140
			} else {
141
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
142
					return sortBySummary(element1, element2, sortDirection2);
143
				} else {
144
					return result;
145
				}
146
			}
136
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
147
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
137
			AbstractTask t1 = null;
148
			int result = sortByDate(element1, element2, sortDirection);
138
			AbstractTask t2 = null;
149
			if (result != 0) {
139
			if (element1 instanceof AbstractTask) {
150
				return result;
140
				t1 = (AbstractTask) element1;
151
			}
141
			}
152
			if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
142
			if (element2 instanceof AbstractTask) {
153
				return sortByPriority(element1, element2, sortDirection2);
143
				t2 = (AbstractTask) element2;
154
			} else {
144
			}
155
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
145
			if (t1 != null && t2 != null) {
156
					return sortBySummary(element1, element2, sortDirection2);
146
				if (t1.getCreationDate() != null) {
157
				} else {
147
					return t1.getCreationDate().compareTo(t2.getCreationDate());
158
					return result;
148
				}
159
				}
149
			}
160
			}
150
		} else {
161
		} else {
151
			return sortBySummary(element1, element2);
162
			int result = sortBySummary(element1, element2, sortDirection);
163
			if (result != 0) {
164
				return result;
165
			}
166
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
167
				return sortByDate(element1, element2, sortDirection2);
168
			} else {
169
				if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
170
					return sortByPriority(element1, element2, sortDirection2);
171
				} else {
172
					return result;
173
				}
174
			}
152
		}
175
		}
153
		return 0;
154
	}
176
	}
155
177
156
	/**
178
	/**
Lines 160-171 Link Here
160
	 * @param element2
182
	 * @param element2
161
	 * @return sort order
183
	 * @return sort order
162
	 */
184
	 */
163
	private int sortBySummary(AbstractTaskContainer element1, AbstractTaskContainer element2) {
185
	private int sortBySummary(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
164
		return this.sortDirection
186
		return sortDirection
165
				* taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
187
				* taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
166
	}
188
	}
167
189
168
	/**
190
	/**
191
	 * Determine the sort order of two tasks by priority
192
	 * 
193
	 * @param element1
194
	 * @param element2
195
	 * @return sort order
196
	 */
197
	private int sortByPriority(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
198
		return sortDirection * element1.getPriority().compareTo(element2.getPriority());
199
	}
200
201
	/**
202
	 * Determine the sort order of two tasks by creation date
203
	 * 
204
	 * @param element1
205
	 * @param element2
206
	 * @return sort order
207
	 */
208
	private int sortByDate(AbstractTaskContainer element1, AbstractTaskContainer element2, int sortDirection) {
209
		AbstractTask t1 = null;
210
		AbstractTask t2 = null;
211
		if (element1 instanceof AbstractTask) {
212
			t1 = (AbstractTask) element1;
213
		}
214
		if (element2 instanceof AbstractTask) {
215
			t2 = (AbstractTask) element2;
216
		}
217
		if (t1 != null && t2 != null) {
218
			if (t1.getCreationDate() != null) {
219
				return sortDirection * t1.getCreationDate().compareTo(t2.getCreationDate());
220
			}
221
		}
222
		return 0;
223
	}
224
225
	/**
169
	 * Return a sortable string in the format "key: summary"
226
	 * Return a sortable string in the format "key: summary"
170
	 * 
227
	 * 
171
	 * @param element
228
	 * @param element
Lines 228-231 Link Here
228
		}
285
		}
229
	}
286
	}
230
287
288
	public SortByIndex getSortByIndex2() {
289
		return sortByIndex2;
290
	}
291
292
	public void setSortByIndex2(SortByIndex sortByIndex) {
293
		SortByIndex oldValue = this.sortByIndex2;
294
		this.sortByIndex2 = sortByIndex;
295
		if (!oldValue.equals(sortByIndex)) {
296
			view.getViewer().refresh();
297
		}
298
299
	}
300
301
	public int getSortDirection2() {
302
		return sortDirection2;
303
	}
304
305
	public void setSortDirection2(int sortDirection) {
306
		int oldValue = this.sortDirection2;
307
		this.sortDirection2 = sortDirection;
308
		if (oldValue != this.sortDirection2) {
309
			view.getViewer().refresh();
310
		}
311
	}
312
231
}
313
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/SortyByDropDownAction.java (-143 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.views;
10
11
import org.eclipse.jface.action.Action;
12
import org.eclipse.jface.action.ActionContributionItem;
13
import org.eclipse.jface.action.IMenuCreator;
14
import org.eclipse.jface.action.Separator;
15
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
16
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Menu;
19
20
/**
21
 * @author Mik Kersten
22
 */
23
class SortyByDropDownAction extends Action implements IMenuCreator {
24
25
	private final TaskListView taskListView;
26
27
	private static final String LABEL = "Sort by";
28
29
	private Action byPriority;
30
31
	private Action bySummary;
32
33
	private Action byDateCreated;
34
35
	private Menu dropDownMenu = null;
36
37
	public SortyByDropDownAction(TaskListView taskListView) {
38
		super();
39
		this.taskListView = taskListView;
40
		setText(LABEL);
41
		setToolTipText(LABEL);
42
		setMenuCreator(this);
43
	}
44
45
	public void dispose() {
46
		if (dropDownMenu != null) {
47
			dropDownMenu.dispose();
48
			dropDownMenu = null;
49
		}
50
	}
51
52
	public Menu getMenu(Control parent) {
53
		if (dropDownMenu != null) {
54
			dropDownMenu.dispose();
55
		}
56
		dropDownMenu = new Menu(parent);
57
		addActionsToMenu();
58
		return dropDownMenu;
59
	}
60
61
	public Menu getMenu(Menu parent) {
62
		if (dropDownMenu != null) {
63
			dropDownMenu.dispose();
64
		}
65
		dropDownMenu = new Menu(parent);
66
		addActionsToMenu();
67
		return dropDownMenu;
68
	}
69
70
	public void addActionsToMenu() {
71
		byPriority = new Action("", AS_CHECK_BOX) {
72
			@Override
73
			public void run() {
74
				taskListView.getSorter().setSortByIndex(SortByIndex.PRIORITY);
75
				byPriority.setChecked(true);
76
				bySummary.setChecked(false);
77
				byDateCreated.setChecked(false);
78
			}
79
		};
80
		byPriority.setEnabled(true);
81
		byPriority.setText("Priority");
82
		byPriority.setImageDescriptor(TasksUiImages.PRIORITY_1);
83
		new ActionContributionItem(byPriority).fill(dropDownMenu, -1);
84
85
		bySummary = new Action("", AS_CHECK_BOX) {
86
			@Override
87
			public void run() {
88
				taskListView.getSorter().setSortByIndex(SortByIndex.SUMMARY);
89
				byPriority.setChecked(false);
90
				bySummary.setChecked(true);
91
				byDateCreated.setChecked(false);
92
			}
93
		};
94
		bySummary.setEnabled(true);
95
		bySummary.setText("Summary");
96
		new ActionContributionItem(bySummary).fill(dropDownMenu, -1);
97
98
		byDateCreated = new Action("", AS_CHECK_BOX) {
99
			@Override
100
			public void run() {
101
				taskListView.getSorter().setSortByIndex(SortByIndex.DATE_CREATED);
102
				byPriority.setChecked(false);
103
				bySummary.setChecked(false);
104
				byDateCreated.setChecked(true);
105
			}
106
		};
107
		byDateCreated.setEnabled(true);
108
		byDateCreated.setText("Date Created");
109
		byDateCreated.setImageDescriptor(TasksUiImages.CALENDAR_SMALL);
110
		new ActionContributionItem(byDateCreated).fill(dropDownMenu, -1);
111
112
		new Separator().fill(dropDownMenu, -1);
113
114
		Action reverse = new Action("", AS_CHECK_BOX) {
115
			@Override
116
			public void run() {
117
				taskListView.getSorter().setSortDirection(taskListView.getSorter().getSortDirection() * -1);
118
				setChecked(taskListView.getSorter().getSortDirection() < 0);
119
			}
120
		};
121
		reverse.setEnabled(true);
122
		reverse.setText("Descending");
123
		reverse.setChecked(taskListView.getSorter().getSortDirection() < 0);
124
		new ActionContributionItem(reverse).fill(dropDownMenu, -1);
125
126
		switch (taskListView.getSorter().getSortByIndex()) {
127
		case PRIORITY:
128
			byPriority.setChecked(true);
129
			break;
130
		case SUMMARY:
131
			bySummary.setChecked(true);
132
			break;
133
		case DATE_CREATED:
134
			byDateCreated.setChecked(true);
135
			break;
136
		}
137
	}
138
139
	@Override
140
	public void run() {
141
		this.setChecked(isChecked());
142
	}
143
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java (-4 / +7 lines)
Lines 89-94 Link Here
89
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
89
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
90
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskDeactivateAction;
90
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskDeactivateAction;
91
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListElementPropertiesAction;
91
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListElementPropertiesAction;
92
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListSortAction;
92
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
93
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
93
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
94
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
94
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewLocalTaskWizard;
95
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewLocalTaskWizard;
Lines 273-279 Link Here
273
274
274
	private PriorityDropDownAction filterOnPriorityAction;
275
	private PriorityDropDownAction filterOnPriorityAction;
275
276
276
	private SortyByDropDownAction sortByAction;
277
	private TaskListSortAction sortDialogAction;
277
278
278
	private PresentationDropDownSelectionAction presentationDropDownSelectionAction;
279
	private PresentationDropDownSelectionAction presentationDropDownSelectionAction;
279
280
Lines 1085-1091 Link Here
1085
		manager.add(collapseAll);
1086
		manager.add(collapseAll);
1086
		manager.add(expandAll);
1087
		manager.add(expandAll);
1087
		manager.add(new Separator(ID_SEPARATOR_FILTERS));
1088
		manager.add(new Separator(ID_SEPARATOR_FILTERS));
1088
		manager.add(sortByAction);
1089
		manager.add(sortDialogAction);
1089
		manager.add(filterOnPriorityAction);
1090
		manager.add(filterOnPriorityAction);
1090
		manager.add(filterCompleteTask);
1091
		manager.add(filterCompleteTask);
1091
		//manager.add(filterArchiveCategory);
1092
		//manager.add(filterArchiveCategory);
Lines 1340-1346 Link Here
1340
		synchronizeAutomatically = new SynchronizeAutomaticallyAction();
1341
		synchronizeAutomatically = new SynchronizeAutomaticallyAction();
1341
		openPreferencesAction = new OpenTasksUiPreferencesAction();
1342
		openPreferencesAction = new OpenTasksUiPreferencesAction();
1342
		//filterArchiveCategory = new FilterArchiveContainerAction(this);
1343
		//filterArchiveCategory = new FilterArchiveContainerAction(this);
1343
		sortByAction = new SortyByDropDownAction(this);
1344
1345
		sortDialogAction = new TaskListSortAction(getSite(), this);
1346
1344
		filterOnPriorityAction = new PriorityDropDownAction(this);
1347
		filterOnPriorityAction = new PriorityDropDownAction(this);
1345
		linkWithEditorAction = new LinkWithEditorAction(this);
1348
		linkWithEditorAction = new LinkWithEditorAction(this);
1346
		presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this);
1349
		presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this);
Lines 1623-1629 Link Here
1623
	}
1626
	}
1624
1627
1625
	public void setManualFiltersEnabled(boolean enabled) {
1628
	public void setManualFiltersEnabled(boolean enabled) {
1626
		sortByAction.setEnabled(enabled);
1629
		sortDialogAction.setEnabled(enabled);
1627
		filterOnPriorityAction.setEnabled(enabled);
1630
		filterOnPriorityAction.setEnabled(enabled);
1628
		filterCompleteTask.setEnabled(enabled);
1631
		filterCompleteTask.setEnabled(enabled);
1629
		//filterArchiveCategory.setEnabled(enabled);
1632
		//filterArchiveCategory.setEnabled(enabled);
(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java (+265 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.dialogs;
10
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.Comparator;
14
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.window.IShellProvider;
17
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
18
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.SelectionAdapter;
21
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Label;
29
30
public class TaskListSortDialog extends Dialog {
31
	private Combo[] priorityCombos;
32
33
	private Button[] ascendingButtons;
34
35
	private Button[] descendingButtons;
36
37
	private final String[] propertyText;
38
39
	private boolean dirty = false;
40
41
	private final TaskListView taskListView;
42
43
	public TaskListSortDialog(IShellProvider parentShell, TaskListView taskListView) {
44
		super(parentShell);
45
		propertyText = new String[3];
46
		propertyText[0] = "Priority";
47
		propertyText[1] = "Summary";
48
		propertyText[2] = "Date_Created";
49
		this.taskListView = taskListView;
50
	}
51
52
	@Override
53
	protected Control createDialogArea(Composite parent) {
54
		Composite composite = (Composite) super.createDialogArea(parent);
55
56
		initializeDialogUnits(composite);
57
58
		Composite prioritiesArea = new Composite(composite, SWT.NULL);
59
		prioritiesArea.setLayout(new GridLayout(3, false));
60
61
		Label sortByLabel = new Label(prioritiesArea, SWT.NULL);
62
		sortByLabel.setText("Sort by:");
63
		GridData data = new GridData();
64
		data.horizontalSpan = 3;
65
		sortByLabel.setLayoutData(data);
66
67
		ascendingButtons = new Button[2];
68
		descendingButtons = new Button[2];
69
		priorityCombos = new Combo[2];
70
71
		for (int i = 0; i < 2; i++) {
72
			final int index = i;
73
			Label numberLabel = new Label(prioritiesArea, SWT.NULL);
74
			numberLabel.setText("" + (i + 1) + ".");
75
			priorityCombos[i] = new Combo(prioritiesArea, SWT.READ_ONLY);
76
			priorityCombos[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
77
78
			Composite directionGroup = new Composite(prioritiesArea, SWT.NONE);
79
			directionGroup.setLayout(new GridLayout(2, false));
80
			ascendingButtons[i] = new Button(directionGroup, SWT.RADIO);
81
			ascendingButtons[i].setText("Ascending");
82
			ascendingButtons[i].addSelectionListener(new SelectionAdapter() {
83
				@Override
84
				public void widgetSelected(SelectionEvent e) {
85
					markDirty();
86
				}
87
			});
88
			descendingButtons[i] = new Button(directionGroup, SWT.RADIO);
89
			descendingButtons[i].setText("Descending");
90
			descendingButtons[i].addSelectionListener(new SelectionAdapter() {
91
				@Override
92
				public void widgetSelected(SelectionEvent e) {
93
					markDirty();
94
				}
95
			});
96
			if (i < priorityCombos.length - 1) {
97
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
98
					@Override
99
					public void widgetSelected(SelectionEvent e) {
100
						int oldSelectionDirection = 1;
101
						if (descendingButtons[index].getSelection()) {
102
							oldSelectionDirection = -1;
103
						}
104
						ArrayList<String> oldSelectionList = new ArrayList<String>(
105
								Arrays.asList(priorityCombos[index].getItems()));
106
						oldSelectionList.removeAll(Arrays.asList(priorityCombos[index + 1].getItems()));
107
						if (oldSelectionList.size() != 1) {
108
							return;
109
						}
110
						String oldSelection = oldSelectionList.get(0);
111
						String newSelection = priorityCombos[index].getItem(priorityCombos[index].getSelectionIndex());
112
						if (oldSelection.equals(newSelection)) {
113
							return;
114
						}
115
						for (int j = index + 1; j < priorityCombos.length; j++) {
116
							int newSelectionIndex = priorityCombos[j].indexOf(newSelection);
117
							//this combo's current selection is equal to newSelection
118
							if (priorityCombos[j].getSelectionIndex() == newSelectionIndex) {
119
								priorityCombos[j].remove(newSelection);
120
								int insertionPoint = -1
121
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
122
												columnComparator);
123
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
124
									priorityCombos[j].add(oldSelection, insertionPoint);
125
								} else {
126
									priorityCombos[j].add(oldSelection);
127
								}
128
								priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection));
129
								ascendingButtons[index].setSelection(ascendingButtons[j].getSelection());
130
								descendingButtons[index].setSelection(descendingButtons[j].getSelection());
131
								ascendingButtons[j].setSelection(oldSelectionDirection == 1);
132
								descendingButtons[j].setSelection(oldSelectionDirection == -1);
133
							}
134
							//this combo contains newSelection
135
							else if (newSelectionIndex >= 0) {
136
								String currentText = priorityCombos[j].getText();
137
								priorityCombos[j].remove(newSelection);
138
								int insertionPoint = -1
139
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
140
												columnComparator);
141
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
142
									priorityCombos[j].add(oldSelection, insertionPoint);
143
									priorityCombos[j].select(priorityCombos[j].indexOf(currentText));
144
								} else {
145
									priorityCombos[j].add(oldSelection);
146
								}
147
							}
148
						}
149
						markDirty();
150
					}
151
				});
152
			} else {
153
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
154
					@Override
155
					public void widgetSelected(SelectionEvent e) {
156
						markDirty();
157
					}
158
				});
159
			}
160
161
		}
162
		int a[] = new int[2];
163
		int b[] = new int[2];
164
		switch (taskListView.getSorter().getSortByIndex()) {
165
		case PRIORITY:
166
			a[0] = 0;
167
			break;
168
		case SUMMARY:
169
			a[0] = 1;
170
			break;
171
		case DATE_CREATED:
172
			a[0] = 2;
173
			break;
174
		}
175
176
		switch (taskListView.getSorter().getSortByIndex2()) {
177
		case PRIORITY:
178
			a[1] = 0;
179
			break;
180
		case SUMMARY:
181
			a[1] = 1;
182
			break;
183
		case DATE_CREATED:
184
			a[1] = 2;
185
			break;
186
		}
187
		b[0] = taskListView.getSorter().getSortDirection();
188
		b[1] = taskListView.getSorter().getSortDirection2();
189
		updateUI(a, b);
190
		return composite;
191
	}
192
193
	@Override
194
	protected void okPressed() {
195
		if (isDirty()) {
196
			taskListView.getSorter()
197
					.setSortByIndex(
198
							SortByIndex.valueOf(priorityCombos[0].getItem(priorityCombos[0].getSelectionIndex())
199
									.toUpperCase()));
200
			taskListView.getSorter()
201
					.setSortByIndex2(
202
							SortByIndex.valueOf(priorityCombos[1].getItem(priorityCombos[1].getSelectionIndex())
203
									.toUpperCase()));
204
			if (descendingButtons[0].getSelection()) {
205
				taskListView.getSorter().setSortDirection(-1);
206
			} else {
207
				taskListView.getSorter().setSortDirection(1);
208
			}
209
			if (descendingButtons[1].getSelection()) {
210
				taskListView.getSorter().setSortDirection2(-1);
211
			} else {
212
				taskListView.getSorter().setSortDirection2(1);
213
			}
214
215
		}
216
		super.okPressed();
217
	}
218
219
	/**
220
	 * @return boolean
221
	 */
222
	public boolean isDirty() {
223
		return dirty;
224
	}
225
226
	/**
227
	 * Sets the dirty flag to true.
228
	 */
229
	public void markDirty() {
230
		dirty = true;
231
	}
232
233
	private final Comparator<String> columnComparator = new Comparator<String>() {
234
		public int compare(String arg0, String arg1) {
235
			int index0 = -1;
236
			int index1 = -1;
237
			for (int i = 0; i < propertyText.length; i++) {
238
				if (propertyText[i].equals(arg0)) {
239
					index0 = i;
240
				}
241
				if (propertyText[i].equals(arg1)) {
242
					index1 = i;
243
				}
244
			}
245
			return index0 - index1;
246
		}
247
	};
248
249
	private void updateUI(int[] priorities, int[] directions) {
250
		ArrayList<String> availablePriorities = new ArrayList<String>(Arrays.asList(propertyText));
251
252
		for (int i = 0; i < priorityCombos.length; i++) {
253
			priorityCombos[i].removeAll();
254
			for (int j = 0; j < availablePriorities.size(); j++) {
255
				priorityCombos[i].add(availablePriorities.get(j));
256
			}
257
			priorityCombos[i].select(priorityCombos[i].indexOf(propertyText[priorities[i]]));
258
			availablePriorities.remove(propertyText[priorities[i]]);
259
260
			ascendingButtons[i].setSelection(directions[i] == 1);
261
			descendingButtons[i].setSelection(directions[i] == -1);
262
		}
263
	}
264
265
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskListSortAction.java (+31 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.actions;
10
11
import org.eclipse.jface.action.Action;
12
import org.eclipse.mylyn.internal.tasks.ui.dialogs.TaskListSortDialog;
13
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
14
import org.eclipse.ui.IWorkbenchPartSite;
15
16
public class TaskListSortAction extends Action {
17
18
	private final TaskListSortDialog dialog;
19
20
	public TaskListSortAction(IWorkbenchPartSite site, TaskListView taskListView) {
21
		super("Task Sort Order");
22
		setEnabled(true);
23
		dialog = new TaskListSortDialog(site, taskListView);
24
	}
25
26
	@Override
27
	public void run() {
28
		dialog.open();
29
	}
30
31
}

Return to bug 219540