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

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListTableSorter.java (-20 / +103 lines)
Lines 12-17 Link Here
12
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.Viewer;
13
import org.eclipse.jface.viewers.ViewerSorter;
13
import org.eclipse.jface.viewers.ViewerSorter;
14
import org.eclipse.mylyn.internal.tasks.core.AbstractRepositoryQuery;
14
import org.eclipse.mylyn.internal.tasks.core.AbstractRepositoryQuery;
15
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
15
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
16
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
16
import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer;
17
import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer;
17
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
18
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
Lines 35-40 Link Here
35
36
36
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
37
	private SortByIndex sortByIndex = SortByIndex.PRIORITY;
37
38
39
	private int sortDirection2 = DEFAULT_SORT_DIRECTION;
40
41
	private SortByIndex sortByIndex2 = SortByIndex.DATE_CREATED;
42
38
	private final TaskListView view;
43
	private final TaskListView view;
39
44
40
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
45
	private final TaskKeyComparator taskKeyComparator = new TaskKeyComparator();
Lines 105-112 Link Here
105
			if (o2 instanceof ITaskElement || o2 instanceof AbstractRepositoryQuery) {
110
			if (o2 instanceof ITaskElement || o2 instanceof AbstractRepositoryQuery) {
106
111
107
				return this.sortDirection
112
				return this.sortDirection
108
						* ((ITaskElement) o1).getSummary().compareToIgnoreCase(
113
						* ((ITaskElement) o1).getSummary().compareToIgnoreCase(((ITaskElement) o2).getSummary());
109
								((ITaskElement) o2).getSummary());
110
			} else {
114
			} else {
111
				return -1;
115
				return -1;
112
			}
116
			}
Lines 127-156 Link Here
127
131
128
	private int compareElements(ITaskElement element1, ITaskElement element2) {
132
	private int compareElements(ITaskElement element1, ITaskElement 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);
135
138
139
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
140
				return sortByDate(element1, element2, sortDirection2);
141
			} else {
142
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
143
					return sortBySummary(element1, element2, sortDirection2);
144
				} else {
145
					return result;
146
				}
147
			}
136
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
148
		} else if (SortByIndex.DATE_CREATED.equals(sortByIndex)) {
137
			ITask t1 = null;
149
			int result = sortByDate(element1, element2, sortDirection);
138
			ITask t2 = null;
150
			if (result != 0) {
139
			if (element1 instanceof ITask) {
151
				return result;
140
				t1 = (ITask) element1;
152
			}
141
			}
153
			if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
142
			if (element2 instanceof ITask) {
154
				return sortByPriority(element1, element2, sortDirection2);
143
				t2 = (ITask) element2;
155
			} else {
144
			}
156
				if (SortByIndex.SUMMARY.equals(sortByIndex2)) {
145
			if (t1 != null && t2 != null) {
157
					return sortBySummary(element1, element2, sortDirection2);
146
				if (t1.getCreationDate() != null) {
158
				} else {
147
					return t1.getCreationDate().compareTo(t2.getCreationDate());
159
					return result;
148
				}
160
				}
149
			}
161
			}
150
		} else {
162
		} else {
151
			return sortBySummary(element1, element2);
163
			int result = sortBySummary(element1, element2, sortDirection);
164
			if (result != 0) {
165
				return result;
166
			}
167
			if (SortByIndex.DATE_CREATED.equals(sortByIndex2)) {
168
				return sortByDate(element1, element2, sortDirection2);
169
			} else {
170
				if (SortByIndex.PRIORITY.equals(sortByIndex2)) {
171
					return sortByPriority(element1, element2, sortDirection2);
172
				} else {
173
					return result;
174
				}
175
			}
152
		}
176
		}
153
		return 0;
154
	}
177
	}
155
178
156
	/**
179
	/**
Lines 160-172 Link Here
160
	 * @param element2
183
	 * @param element2
161
	 * @return sort order
184
	 * @return sort order
162
	 */
185
	 */
163
	private int sortBySummary(ITaskElement element1, ITaskElement element2) {
186
	private int sortBySummary(ITaskElement element1, ITaskElement element2, int sortDirection) {
164
		return this.sortDirection
187
		return sortDirection
165
				* taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
188
				* taskKeyComparator.compare(getSortableFromElement(element1), getSortableFromElement(element2));
166
	}
189
	}
167
190
168
	/**
191
	/**
169
	 * Return a sortable string in the format "key: summary"
192
	 * Determine the sort order of two tasks by priority
193
	 * 
194
	 * @param element1
195
	 * @param element2
196
	 * @return sort order
197
	 */
198
	private int sortByPriority(ITaskElement element1, ITaskElement element2, int sortDirection) {
199
		return sortDirection * element1.getPriority().compareTo(element2.getPriority());
200
	}
201
202
	/**
203
	 * Determine the sort order of two tasks by creation date
204
	 * 
205
	 * @param element1
206
	 * @param element2
207
	 * @return sort order
208
	 */
209
	private int sortByDate(ITaskElement element1, ITaskElement element2, int sortDirection) {
210
		AbstractTask t1 = null;
211
		AbstractTask t2 = null;
212
		if (element1 instanceof AbstractTask) {
213
			t1 = (AbstractTask) element1;
214
		}
215
		if (element2 instanceof AbstractTask) {
216
			t2 = (AbstractTask) element2;
217
		}
218
		if (t1 != null && t2 != null) {
219
			if (t1.getCreationDate() != null) {
220
				return sortDirection * t1.getCreationDate().compareTo(t2.getCreationDate());
221
			}
222
		}
223
		return 0;
224
	}
225
226
	/**
227
	 * * Return a sortable string in the format "key: summary"
170
	 * 
228
	 * 
171
	 * @param element
229
	 * @param element
172
	 * @return sortable string
230
	 * @return sortable string
Lines 228-231 Link Here
228
		}
286
		}
229
	}
287
	}
230
288
289
	public SortByIndex getSortByIndex2() {
290
		return sortByIndex2;
291
	}
292
293
	public void setSortByIndex2(SortByIndex sortByIndex) {
294
		SortByIndex oldValue = this.sortByIndex2;
295
		this.sortByIndex2 = sortByIndex;
296
		if (!oldValue.equals(sortByIndex)) {
297
			view.getViewer().refresh();
298
		}
299
300
	}
301
302
	public int getSortDirection2() {
303
		return sortDirection2;
304
	}
305
306
	public void setSortDirection2(int sortDirection) {
307
		int oldValue = this.sortDirection2;
308
		this.sortDirection2 = sortDirection;
309
		if (oldValue != this.sortDirection2) {
310
			view.getViewer().refresh();
311
		}
312
	}
313
231
}
314
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java (-5 / +44 lines)
Lines 94-99 Link Here
94
import org.eclipse.mylyn.internal.tasks.ui.actions.SynchronizeAutomaticallyAction;
94
import org.eclipse.mylyn.internal.tasks.ui.actions.SynchronizeAutomaticallyAction;
95
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
95
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
96
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskDeactivateAction;
96
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskDeactivateAction;
97
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListSortAction;
97
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskListChangeAdapter;
98
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskListChangeAdapter;
98
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
99
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener;
99
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
100
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
Lines 178-183 Link Here
178
179
179
	private static final String MEMENTO_KEY_SORTER = "sorter";
180
	private static final String MEMENTO_KEY_SORTER = "sorter";
180
181
182
	private static final String MEMENTO_KEY_SORTER2 = "sorter2";
183
181
	private static final String MEMENTO_KEY_SORT_INDEX = "sortIndex";
184
	private static final String MEMENTO_KEY_SORT_INDEX = "sortIndex";
182
185
183
	private static final String MEMENTO_SORT_INDEX = "org.eclipse.mylyn.tasklist.ui.views.tasklist.sortIndex";
186
	private static final String MEMENTO_SORT_INDEX = "org.eclipse.mylyn.tasklist.ui.views.tasklist.sortIndex";
Lines 269-275 Link Here
269
272
270
	private PriorityDropDownAction filterOnPriorityAction;
273
	private PriorityDropDownAction filterOnPriorityAction;
271
274
272
	private SortyByDropDownAction sortByAction;
275
	private TaskListSortAction sortDialogAction;
273
276
274
	private PresentationDropDownSelectionAction presentationDropDownSelectionAction;
277
	private PresentationDropDownSelectionAction presentationDropDownSelectionAction;
275
278
Lines 649-654 Link Here
649
		}
652
		}
650
653
651
		m.putInteger(MEMENTO_KEY_SORT_DIRECTION, tableSorter.getSortDirection());
654
		m.putInteger(MEMENTO_KEY_SORT_DIRECTION, tableSorter.getSortDirection());
655
		IMemento m2 = sorter.createChild(MEMENTO_KEY_SORTER2);
656
		switch (tableSorter.getSortByIndex2()) {
657
		case SUMMARY:
658
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 1);
659
			break;
660
		case DATE_CREATED:
661
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
662
			break;
663
		default:
664
			m2.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
665
		}
666
667
		m2.putInteger(MEMENTO_KEY_SORT_DIRECTION, tableSorter.getSortDirection2());
652
		memento.putString(MEMENTO_LINK_WITH_EDITOR, Boolean.toString(linkWithEditor));
668
		memento.putString(MEMENTO_LINK_WITH_EDITOR, Boolean.toString(linkWithEditor));
653
		memento.putString(MEMENTO_PRESENTATION, currentPresentation.getId());
669
		memento.putString(MEMENTO_PRESENTATION, currentPresentation.getId());
654
	}
670
	}
Lines 660-665 Link Here
660
			int restoredSortIndex = 0;
676
			int restoredSortIndex = 0;
661
			if (sorterMemento != null) {
677
			if (sorterMemento != null) {
662
				int sortDirection = -1;
678
				int sortDirection = -1;
679
				tableSorter = new TaskListTableSorter(this);
663
				IMemento m = sorterMemento.getChild(MEMENTO_KEY_SORTER);
680
				IMemento m = sorterMemento.getChild(MEMENTO_KEY_SORTER);
664
				if (m != null) {
681
				if (m != null) {
665
					Integer sortIndexInt = m.getInteger(MEMENTO_KEY_SORT_INDEX);
682
					Integer sortIndexInt = m.getInteger(MEMENTO_KEY_SORT_INDEX);
Lines 669-675 Link Here
669
					Integer sortDirInt = m.getInteger(MEMENTO_KEY_SORT_DIRECTION);
686
					Integer sortDirInt = m.getInteger(MEMENTO_KEY_SORT_DIRECTION);
670
					if (sortDirInt != null) {
687
					if (sortDirInt != null) {
671
						sortDirection = sortDirInt.intValue();
688
						sortDirection = sortDirInt.intValue();
672
						tableSorter = new TaskListTableSorter(this);
673
						tableSorter.setSortDirection(sortDirection);
689
						tableSorter.setSortDirection(sortDirection);
674
						switch (restoredSortIndex) {
690
						switch (restoredSortIndex) {
675
						case 1:
691
						case 1:
Lines 683-688 Link Here
683
						}
699
						}
684
					}
700
					}
685
				}
701
				}
702
703
				IMemento m2 = sorterMemento.getChild(MEMENTO_KEY_SORTER2);
704
				if (m2 != null) {
705
					Integer sortIndexInt = m2.getInteger(MEMENTO_KEY_SORT_INDEX);
706
					if (sortIndexInt != null) {
707
						restoredSortIndex = sortIndexInt.intValue();
708
					}
709
					Integer sortDirInt = m2.getInteger(MEMENTO_KEY_SORT_DIRECTION);
710
					if (sortDirInt != null) {
711
						sortDirection = sortDirInt.intValue();
712
						tableSorter.setSortDirection2(sortDirection);
713
						switch (restoredSortIndex) {
714
						case 1:
715
							tableSorter.setSortByIndex2(SortByIndex.SUMMARY);
716
							break;
717
						case 2:
718
							tableSorter.setSortByIndex2(SortByIndex.DATE_CREATED);
719
							break;
720
						default:
721
							tableSorter.setSortByIndex2(SortByIndex.PRIORITY);
722
						}
723
					}
724
				}
686
			}
725
			}
687
			applyPresentation(taskListMemento.getString(MEMENTO_PRESENTATION));
726
			applyPresentation(taskListMemento.getString(MEMENTO_PRESENTATION));
688
		}
727
		}
Lines 1069-1075 Link Here
1069
		manager.add(collapseAll);
1108
		manager.add(collapseAll);
1070
		manager.add(expandAll);
1109
		manager.add(expandAll);
1071
		manager.add(new Separator(ID_SEPARATOR_FILTERS));
1110
		manager.add(new Separator(ID_SEPARATOR_FILTERS));
1072
		manager.add(sortByAction);
1111
		manager.add(sortDialogAction);
1073
		manager.add(filterOnPriorityAction);
1112
		manager.add(filterOnPriorityAction);
1074
		manager.add(filterCompleteTask);
1113
		manager.add(filterCompleteTask);
1075
		//manager.add(filterArchiveCategory);
1114
		//manager.add(filterArchiveCategory);
Lines 1314-1320 Link Here
1314
		synchronizeAutomatically = new SynchronizeAutomaticallyAction();
1353
		synchronizeAutomatically = new SynchronizeAutomaticallyAction();
1315
		openPreferencesAction = new OpenTasksUiPreferencesAction();
1354
		openPreferencesAction = new OpenTasksUiPreferencesAction();
1316
		//filterArchiveCategory = new FilterArchiveContainerAction(this);
1355
		//filterArchiveCategory = new FilterArchiveContainerAction(this);
1317
		sortByAction = new SortyByDropDownAction(this);
1356
		sortDialogAction = new TaskListSortAction(getSite(), this);
1318
		filterOnPriorityAction = new PriorityDropDownAction(this);
1357
		filterOnPriorityAction = new PriorityDropDownAction(this);
1319
		linkWithEditorAction = new LinkWithEditorAction(this);
1358
		linkWithEditorAction = new LinkWithEditorAction(this);
1320
		presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this);
1359
		presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this);
Lines 1578-1584 Link Here
1578
	}
1617
	}
1579
1618
1580
	public void setManualFiltersEnabled(boolean enabled) {
1619
	public void setManualFiltersEnabled(boolean enabled) {
1581
		sortByAction.setEnabled(enabled);
1620
		sortDialogAction.setEnabled(enabled);
1582
		filterOnPriorityAction.setEnabled(enabled);
1621
		filterOnPriorityAction.setEnabled(enabled);
1583
		filterCompleteTask.setEnabled(enabled);
1622
		filterCompleteTask.setEnabled(enabled);
1584
		//filterArchiveCategory.setEnabled(enabled);
1623
		//filterArchiveCategory.setEnabled(enabled);
(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java (+266 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.window.IShellProvider;
16
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
17
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Combo;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.ui.dialogs.SelectionDialog;
29
30
public class TaskListSortDialog extends SelectionDialog {
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.getShell());
45
		propertyText = new String[3];
46
		propertyText[0] = "Priority";
47
		propertyText[1] = "Summary";
48
		propertyText[2] = "Date Created";
49
		this.taskListView = taskListView;
50
		setTitle(TaskListView.LABEL_VIEW + " Sorting");
51
	}
52
53
	@Override
54
	protected Control createDialogArea(Composite parent) {
55
		Composite composite = (Composite) super.createDialogArea(parent);
56
57
		initializeDialogUnits(composite);
58
59
		Composite prioritiesArea = new Composite(composite, SWT.NULL);
60
		prioritiesArea.setLayout(new GridLayout(3, false));
61
62
		Label sortByLabel = new Label(prioritiesArea, SWT.NULL);
63
		sortByLabel.setText("Sort order:");
64
		GridData data = new GridData();
65
		data.horizontalSpan = 3;
66
		sortByLabel.setLayoutData(data);
67
68
		ascendingButtons = new Button[2];
69
		descendingButtons = new Button[2];
70
		priorityCombos = new Combo[2];
71
72
		for (int i = 0; i < 2; i++) {
73
			final int index = i;
74
			Label numberLabel = new Label(prioritiesArea, SWT.NULL);
75
			numberLabel.setText("" + (i + 1) + ".");
76
			priorityCombos[i] = new Combo(prioritiesArea, SWT.READ_ONLY);
77
			priorityCombos[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
78
79
			Composite directionGroup = new Composite(prioritiesArea, SWT.NONE);
80
			directionGroup.setLayout(new GridLayout(2, false));
81
			ascendingButtons[i] = new Button(directionGroup, SWT.RADIO);
82
			ascendingButtons[i].setText("Ascending");
83
			ascendingButtons[i].addSelectionListener(new SelectionAdapter() {
84
				@Override
85
				public void widgetSelected(SelectionEvent e) {
86
					markDirty();
87
				}
88
			});
89
			descendingButtons[i] = new Button(directionGroup, SWT.RADIO);
90
			descendingButtons[i].setText("Descending");
91
			descendingButtons[i].addSelectionListener(new SelectionAdapter() {
92
				@Override
93
				public void widgetSelected(SelectionEvent e) {
94
					markDirty();
95
				}
96
			});
97
			if (i < priorityCombos.length - 1) {
98
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
99
					@Override
100
					public void widgetSelected(SelectionEvent e) {
101
						int oldSelectionDirection = 1;
102
						if (descendingButtons[index].getSelection()) {
103
							oldSelectionDirection = -1;
104
						}
105
						ArrayList<String> oldSelectionList = new ArrayList<String>(
106
								Arrays.asList(priorityCombos[index].getItems()));
107
						oldSelectionList.removeAll(Arrays.asList(priorityCombos[index + 1].getItems()));
108
						if (oldSelectionList.size() != 1) {
109
							return;
110
						}
111
						String oldSelection = oldSelectionList.get(0);
112
						String newSelection = priorityCombos[index].getItem(priorityCombos[index].getSelectionIndex());
113
						if (oldSelection.equals(newSelection)) {
114
							return;
115
						}
116
						for (int j = index + 1; j < priorityCombos.length; j++) {
117
							int newSelectionIndex = priorityCombos[j].indexOf(newSelection);
118
							//this combo's current selection is equal to newSelection
119
							if (priorityCombos[j].getSelectionIndex() == newSelectionIndex) {
120
								priorityCombos[j].remove(newSelection);
121
								int insertionPoint = -1
122
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
123
												columnComparator);
124
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
125
									priorityCombos[j].add(oldSelection, insertionPoint);
126
								} else {
127
									priorityCombos[j].add(oldSelection);
128
								}
129
								priorityCombos[j].select(priorityCombos[j].indexOf(oldSelection));
130
								ascendingButtons[index].setSelection(ascendingButtons[j].getSelection());
131
								descendingButtons[index].setSelection(descendingButtons[j].getSelection());
132
								ascendingButtons[j].setSelection(oldSelectionDirection == 1);
133
								descendingButtons[j].setSelection(oldSelectionDirection == -1);
134
							}
135
							//this combo contains newSelection
136
							else if (newSelectionIndex >= 0) {
137
								String currentText = priorityCombos[j].getText();
138
								priorityCombos[j].remove(newSelection);
139
								int insertionPoint = -1
140
										- Arrays.binarySearch(priorityCombos[j].getItems(), oldSelection,
141
												columnComparator);
142
								if (insertionPoint >= 0 && insertionPoint <= priorityCombos[j].getItemCount()) {
143
									priorityCombos[j].add(oldSelection, insertionPoint);
144
									priorityCombos[j].select(priorityCombos[j].indexOf(currentText));
145
								} else {
146
									priorityCombos[j].add(oldSelection);
147
								}
148
							}
149
						}
150
						markDirty();
151
					}
152
				});
153
			} else {
154
				priorityCombos[i].addSelectionListener(new SelectionAdapter() {
155
					@Override
156
					public void widgetSelected(SelectionEvent e) {
157
						markDirty();
158
					}
159
				});
160
			}
161
162
		}
163
		int a[] = new int[2];
164
		int b[] = new int[2];
165
		switch (taskListView.getSorter().getSortByIndex()) {
166
		case PRIORITY:
167
			a[0] = 0;
168
			break;
169
		case SUMMARY:
170
			a[0] = 1;
171
			break;
172
		case DATE_CREATED:
173
			a[0] = 2;
174
			break;
175
		}
176
177
		switch (taskListView.getSorter().getSortByIndex2()) {
178
		case PRIORITY:
179
			a[1] = 0;
180
			break;
181
		case SUMMARY:
182
			a[1] = 1;
183
			break;
184
		case DATE_CREATED:
185
			a[1] = 2;
186
			break;
187
		}
188
		b[0] = taskListView.getSorter().getSortDirection();
189
		b[1] = taskListView.getSorter().getSortDirection2();
190
		updateUI(a, b);
191
		return composite;
192
	}
193
194
	@Override
195
	protected void okPressed() {
196
		if (isDirty()) {
197
			taskListView.getSorter()
198
					.setSortByIndex(
199
							SortByIndex.valueOf(priorityCombos[0].getItem(priorityCombos[0].getSelectionIndex())
200
									.toUpperCase()));
201
			taskListView.getSorter()
202
					.setSortByIndex2(
203
							SortByIndex.valueOf(priorityCombos[1].getItem(priorityCombos[1].getSelectionIndex())
204
									.toUpperCase()));
205
			if (descendingButtons[0].getSelection()) {
206
				taskListView.getSorter().setSortDirection(-1);
207
			} else {
208
				taskListView.getSorter().setSortDirection(1);
209
			}
210
			if (descendingButtons[1].getSelection()) {
211
				taskListView.getSorter().setSortDirection2(-1);
212
			} else {
213
				taskListView.getSorter().setSortDirection2(1);
214
			}
215
216
		}
217
		super.okPressed();
218
	}
219
220
	/**
221
	 * @return boolean
222
	 */
223
	public boolean isDirty() {
224
		return dirty;
225
	}
226
227
	/**
228
	 * Sets the dirty flag to true.
229
	 */
230
	public void markDirty() {
231
		dirty = true;
232
	}
233
234
	private final Comparator<String> columnComparator = new Comparator<String>() {
235
		public int compare(String arg0, String arg1) {
236
			int index0 = -1;
237
			int index1 = -1;
238
			for (int i = 0; i < propertyText.length; i++) {
239
				if (propertyText[i].equals(arg0)) {
240
					index0 = i;
241
				}
242
				if (propertyText[i].equals(arg1)) {
243
					index1 = i;
244
				}
245
			}
246
			return index0 - index1;
247
		}
248
	};
249
250
	private void updateUI(int[] priorities, int[] directions) {
251
		ArrayList<String> availablePriorities = new ArrayList<String>(Arrays.asList(propertyText));
252
253
		for (int i = 0; i < priorityCombos.length; i++) {
254
			priorityCombos[i].removeAll();
255
			for (int j = 0; j < availablePriorities.size(); j++) {
256
				priorityCombos[i].add(availablePriorities.get(j));
257
			}
258
			priorityCombos[i].select(priorityCombos[i].indexOf(propertyText[priorities[i]]));
259
			availablePriorities.remove(propertyText[priorities[i]]);
260
261
			ascendingButtons[i].setSelection(directions[i] == 1);
262
			descendingButtons[i].setSelection(directions[i] == -1);
263
		}
264
	}
265
266
}
(-)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("Sort...");
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