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

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/TaskListSortDialog.java (-1 / +41 lines)
Lines 13-21 Link Here
13
13
14
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.jface.window.IShellProvider;
15
import org.eclipse.jface.window.IShellProvider;
16
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListSorter;
16
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
17
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
18
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListSorter.GroupBy;
17
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.SelectionAdapter;
21
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.widgets.Combo;
19
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Label;
21
26
Lines 24-42 Link Here
24
 */
29
 */
25
public class TaskListSortDialog extends TaskCompareDialog {
30
public class TaskListSortDialog extends TaskCompareDialog {
26
31
32
	private Combo modeCombo;
33
34
	private final TaskListView taskListView;
35
27
	public TaskListSortDialog(IShellProvider parentShell, TaskListView taskListView) {
36
	public TaskListSortDialog(IShellProvider parentShell, TaskListView taskListView) {
28
		super(parentShell, taskListView.getSorter().getComparator());
37
		super(parentShell, taskListView.getSorter().getComparator());
38
		this.taskListView = taskListView;
29
		setTitle(Messages.TaskListSortDialog_Title);
39
		setTitle(Messages.TaskListSortDialog_Title);
30
	}
40
	}
31
41
32
	@Override
42
	@Override
33
	protected void createDialogStartArea(Composite parent) {
43
	protected void createDialogStartArea(Composite parent) {
44
		Label numberLabel = new Label(parent, SWT.NULL);
45
		numberLabel.setText(Messages.TaskListSortDialog_Grouped_by);
46
		modeCombo = new Combo(parent, SWT.READ_ONLY);
47
		modeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
48
		GridData data = new GridData();
49
		data.horizontalSpan = 2;
50
		modeCombo.setLayoutData(data);
51
		GroupBy[] values = TaskListSorter.GroupBy.values();
52
		for (GroupBy groupBy : values) {
53
			modeCombo.add(groupBy.getLabel());
54
		}
55
		modeCombo.addSelectionListener(new SelectionAdapter() {
56
			@Override
57
			public void widgetSelected(SelectionEvent e) {
58
				markDirty();
59
			}
60
		});
61
		modeCombo.select(taskListView.getSorter().getGroupBy().ordinal());
62
34
		Label sortByLabel = new Label(parent, SWT.NULL);
63
		Label sortByLabel = new Label(parent, SWT.NULL);
35
		sortByLabel.setText(Messages.TaskListSortDialog_Sort_order);
64
		sortByLabel.setText(Messages.TaskListSortDialog_Sort_order);
36
		GridData data = new GridData();
65
		data = new GridData();
37
		data.horizontalSpan = 3;
66
		data.horizontalSpan = 3;
38
		sortByLabel.setLayoutData(data);
67
		sortByLabel.setLayoutData(data);
39
		Dialog.applyDialogFont(parent);
68
		Dialog.applyDialogFont(parent);
40
	}
69
	}
41
70
71
	@Override
72
	protected void okPressed() {
73
		if (isDirty()) {
74
			int selectionIndex = modeCombo.getSelectionIndex();
75
			if (selectionIndex != -1) {
76
				taskListView.getSorter().setGroupBy(TaskListSorter.GroupBy.values()[selectionIndex]);
77
			}
78
		}
79
		super.okPressed();
80
	}
81
42
}
82
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/Messages.java (+2 lines)
Lines 41-46 Link Here
41
41
42
	public static String TaskCompareDialog_TaskID;
42
	public static String TaskCompareDialog_TaskID;
43
43
44
	public static String TaskListSortDialog_Grouped_by;
45
44
	public static String TaskListSortDialog_Sort_order;
46
	public static String TaskListSortDialog_Sort_order;
45
47
46
	public static String TaskListSortDialog_Title;
48
	public static String TaskListSortDialog_Title;
(-)src/org/eclipse/mylyn/internal/tasks/ui/dialogs/messages.properties (+1 lines)
Lines 6-11 Link Here
6
TaskCompareDialog_SortOrder=Sort order:
6
TaskCompareDialog_SortOrder=Sort order:
7
TaskCompareDialog_Summary=Summary
7
TaskCompareDialog_Summary=Summary
8
TaskCompareDialog_TaskID=Task ID
8
TaskCompareDialog_TaskID=Task ID
9
TaskListSortDialog_Grouped_by=Grouped by:
9
TaskListSortDialog_Sort_order=Sort order for tasks\:
10
TaskListSortDialog_Sort_order=Sort order for tasks\:
10
TaskListSortDialog_Title=Task List Sorting
11
TaskListSortDialog_Title=Task List Sorting
11
12
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/Messages.java (+6 lines)
Lines 59-64 Link Here
59
59
60
	public static String TaskListFilteredTree_Workweek_Progress;
60
	public static String TaskListFilteredTree_Workweek_Progress;
61
61
62
	public static String TaskListSorter_Catagory_and_Query;
63
64
	public static String TaskListSorter_Catagory_and_Repository;
65
66
	public static String TaskListSorter_No_Grouping;
67
62
	public static String TaskListToolTip_Automatic_container_for_all_local_tasks;
68
	public static String TaskListToolTip_Automatic_container_for_all_local_tasks;
63
69
64
	public static String TaskListToolTip_Automatic_container_for_repository_tasks;
70
	public static String TaskListToolTip_Automatic_container_for_repository_tasks;
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListSorter.java (-43 / +141 lines)
Lines 11-20 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.text.Collator;
15
16
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.ViewerSorter;
18
import org.eclipse.jface.viewers.ViewerSorter;
16
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
19
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
17
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
20
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
21
import org.eclipse.mylyn.internal.tasks.core.ITaskRepositoryElement;
18
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
22
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
19
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
23
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
20
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
24
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
Lines 24-44 Link Here
24
import org.eclipse.mylyn.internal.tasks.core.UnsubmittedTaskContainer;
28
import org.eclipse.mylyn.internal.tasks.core.UnsubmittedTaskContainer;
25
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
29
import org.eclipse.mylyn.internal.tasks.ui.util.TaskComparator;
26
import org.eclipse.mylyn.tasks.core.ITask;
30
import org.eclipse.mylyn.tasks.core.ITask;
31
import org.eclipse.mylyn.tasks.core.TaskRepository;
32
import org.eclipse.mylyn.tasks.ui.TasksUi;
27
33
28
/**
34
/**
29
 * @author Mik Kersten
35
 * @author Mik Kersten
30
 */
36
 */
31
public class TaskListSorter extends ViewerSorter {
37
public class TaskListSorter extends ViewerSorter {
32
38
39
	public enum GroupBy {
40
		NONE, CATEGORY_QUERY, CATEGORY_REPOSITORY;
41
42
		public String getLabel() {
43
			switch (this) {
44
			case NONE:
45
				return Messages.TaskListSorter_No_Grouping;
46
			case CATEGORY_QUERY:
47
				return Messages.TaskListSorter_Catagory_and_Query;
48
			case CATEGORY_REPOSITORY:
49
				return Messages.TaskListSorter_Catagory_and_Repository;
50
			default:
51
				return null;
52
			}
53
		}
54
55
		public static GroupBy valueOfLabel(String label) {
56
			for (GroupBy value : values()) {
57
				if (value.getLabel().equals(label)) {
58
					return value;
59
				}
60
			}
61
			return null;
62
		}
63
64
	}
65
66
	private class SortKey {
67
68
		private int weight;
69
70
		private final String[] values = new String[3];
71
72
	}
73
33
	public static final int DEFAULT_SORT_DIRECTION = 1;
74
	public static final int DEFAULT_SORT_DIRECTION = 1;
34
75
35
	private int sortDirectionRootElement;
76
	private int sortDirectionRootElement;
36
77
37
	private final TaskComparator taskComparator;
78
	private final TaskComparator taskComparator;
38
79
80
	private GroupBy groupBy;
81
82
	private final SortKey key1;
83
84
	private final SortKey key2;
85
39
	public TaskListSorter() {
86
	public TaskListSorter() {
40
		this.sortDirectionRootElement = DEFAULT_SORT_DIRECTION;
87
		this.sortDirectionRootElement = DEFAULT_SORT_DIRECTION;
41
		this.taskComparator = new TaskComparator();
88
		this.taskComparator = new TaskComparator();
89
		this.groupBy = GroupBy.NONE;
90
		this.key1 = new SortKey();
91
		this.key2 = new SortKey();
42
	}
92
	}
43
93
44
	/**
94
	/**
Lines 57-110 Link Here
57
			ScheduledTaskContainer dateRangeTaskContainer2 = (ScheduledTaskContainer) o2;
107
			ScheduledTaskContainer dateRangeTaskContainer2 = (ScheduledTaskContainer) o2;
58
			return dateRangeTaskContainer1.getDateRange().compareTo(dateRangeTaskContainer2.getDateRange());
108
			return dateRangeTaskContainer1.getDateRange().compareTo(dateRangeTaskContainer2.getDateRange());
59
		} else {
109
		} else {
60
			int o1Type;
110
			updateKey(key1, o1);
61
			if (o1 instanceof AbstractTask) {
111
			updateKey(key2, o2);
62
				o1Type = 0;
112
63
			} else if (o1 instanceof UncategorizedTaskContainer) {
113
			if (key1.weight != key2.weight) {
64
				o1Type = 1;
114
				return key1.weight - key2.weight < 0 ? -1 : 1;
65
			} else if (o1 instanceof UnsubmittedTaskContainer) {
66
				o1Type = 2;
67
			} else if (o1 instanceof TaskCategory) {
68
				o1Type = 3;
69
			} else if (o1 instanceof RepositoryQuery) {
70
				o1Type = 4;
71
			} else if (o1 instanceof TaskGroup) { // support for the experimental grouping of tasks
72
				o1Type = 5;
73
			} else if (o1 instanceof UnmatchedTaskContainer) {
74
				o1Type = 6;
75
			} else {
76
				o1Type = 99;
77
			}
78
			int o2Type;
79
			if (o2 instanceof AbstractTask) {
80
				o2Type = 0;
81
			} else if (o2 instanceof UncategorizedTaskContainer) {
82
				o2Type = 1;
83
			} else if (o2 instanceof UnsubmittedTaskContainer) {
84
				o2Type = 2;
85
			} else if (o2 instanceof TaskCategory) {
86
				o2Type = 3;
87
			} else if (o2 instanceof RepositoryQuery) {
88
				o2Type = 4;
89
			} else if (o2 instanceof TaskGroup) { // support for the experimental grouping of tasks
90
				o2Type = 5;
91
			} else if (o2 instanceof UnmatchedTaskContainer) {
92
				o2Type = 6;
93
			} else {
94
				o2Type = 99;
95
			}
115
			}
96
			if (o1Type != o2Type) {
116
			int result = compare(key1.values[0], key2.values[0]);
97
				return o1Type - o2Type < 0 ? -1 : 1;
117
			if (result != 0) {
118
				return result;
98
			}
119
			}
99
			if (o1Type < 7) {
120
			result = compare(key1.values[1], key2.values[1]);
100
				AbstractTaskContainer taskContainer1 = (AbstractTaskContainer) o1;
121
			return (result != 0) ? result : compare(key1.values[2], key2.values[2]);
101
				AbstractTaskContainer taskContainer2 = (AbstractTaskContainer) o2;
122
		}
123
	}
124
125
	private int compare(String key1, String key2) {
126
		if (key1 == null) {
127
			return (key2 != null) ? sortDirectionRootElement : 0;
128
		} else if (key2 == null) {
129
			return -sortDirectionRootElement;
130
		}
131
		return sortDirectionRootElement * Collator.getInstance().compare(key1, key2);
132
	}
133
134
	private void updateKey(SortKey key, Object object) {
135
		int weight;
136
		if (object instanceof AbstractTask) {
137
			weight = 0;
138
		} else if (object instanceof UncategorizedTaskContainer) {
139
			weight = 1;
140
		} else if (object instanceof UnsubmittedTaskContainer) {
141
			weight = 2;
142
		} else if (object instanceof TaskCategory) {
143
			weight = 3;
144
		} else if (object instanceof RepositoryQuery) {
145
			weight = 4;
146
		} else if (object instanceof TaskGroup) { // support for the experimental grouping of tasks
147
			weight = 5;
148
		} else if (object instanceof UnmatchedTaskContainer) {
149
			weight = 6;
150
		} else {
151
			weight = 99;
152
		}
102
153
103
				return this.sortDirectionRootElement
154
		key.values[0] = ((AbstractTaskContainer) object).getSummary();
104
						* taskContainer1.getSummary().compareToIgnoreCase(taskContainer2.getSummary());
155
		key.values[1] = null;
156
		key.values[2] = null;
157
158
		switch (groupBy) {
159
		case NONE:
160
			weight = 1;
161
			break;
162
		case CATEGORY_QUERY:
163
			break;
164
		case CATEGORY_REPOSITORY:
165
			if (weight == 1) {
166
				// keep
167
			} else if (weight == 3) {
168
				weight = 2;
169
			} else {
170
				key.values[0] = getRepositoryUrl(object);
171
				key.values[1] = weight + ""; //$NON-NLS-1$
172
				key.values[2] = ((AbstractTaskContainer) object).getSummary();
173
				weight = 3;
105
			}
174
			}
175
			break;
176
		}
177
178
		key.weight = weight;
179
	}
180
181
	private String getRepositoryUrl(Object object) {
182
		if (object instanceof ITaskRepositoryElement) {
183
			ITaskRepositoryElement repositoryElement = (ITaskRepositoryElement) object;
184
			String repositoryUrl = repositoryElement.getRepositoryUrl();
185
			TaskRepository taskRepository = TasksUi.getRepositoryManager().getRepository(
186
					repositoryElement.getConnectorKind(), repositoryUrl);
187
			return taskRepository != null ? taskRepository.getRepositoryLabel() : null;
106
		}
188
		}
107
		return 0;
189
//		if (object instanceof UnsubmittedTaskContainer) {
190
//			return ((UnsubmittedTaskContainer) object).getRepositoryUrl();
191
//		} else if (object instanceof RepositoryQuery) {
192
//			return ((RepositoryQuery) object).getRepositoryUrl();
193
//		} else if (object instanceof UnmatchedTaskContainer) {
194
//			return ((UnmatchedTaskContainer) object).getRepositoryUrl();
195
//		}
196
		return null;
108
	}
197
	}
109
198
110
	private int compareElements(ITask element1, ITask element2) {
199
	private int compareElements(ITask element1, ITask element2) {
Lines 124-127 Link Here
124
		this.sortDirectionRootElement = sortDirection;
213
		this.sortDirectionRootElement = sortDirection;
125
	}
214
	}
126
215
216
	public GroupBy getGroupBy() {
217
		return groupBy;
218
	}
219
220
	public void setGroupBy(GroupBy sortByIndex) {
221
		Assert.isNotNull(sortByIndex);
222
		this.groupBy = sortByIndex;
223
	}
224
127
}
225
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/messages.properties (+3 lines)
Lines 19-24 Link Here
19
TaskListFilteredTree_Select_Active_Task=Select Active Task
19
TaskListFilteredTree_Select_Active_Task=Select Active Task
20
TaskListFilteredTree_Select_Working_Set=Select Working Set
20
TaskListFilteredTree_Select_Working_Set=Select Working Set
21
TaskListFilteredTree_Workweek_Progress=Workweek Progress
21
TaskListFilteredTree_Workweek_Progress=Workweek Progress
22
TaskListSorter_Catagory_and_Query=Category and Query
23
TaskListSorter_Catagory_and_Repository=Category and Repository
24
TaskListSorter_No_Grouping=no Grouping
22
25
23
TaskListToolTip_Automatic_container_for_all_local_tasks=Automatic container for all local tasks\nwith no category set
26
TaskListToolTip_Automatic_container_for_all_local_tasks=Automatic container for all local tasks\nwith no category set
24
TaskListToolTip_Automatic_container_for_repository_tasks=Automatic container for repository tasks\nnot matched by any query
27
TaskListToolTip_Automatic_container_for_repository_tasks=Automatic container for repository tasks\nnot matched by any query
(-)plugin.properties (+2 lines)
Lines 11-16 Link Here
11
LocalRepositoryConnectorUi.name = Local Repository Ui
11
LocalRepositoryConnectorUi.name = Local Repository Ui
12
12
13
CategorizedPresentation.name = Categorized
13
CategorizedPresentation.name = Categorized
14
CategorizedQueryPresentation.name = Categorized by Query
15
CategorizedRepositoryPresentation.name = Categorized by Repository
14
ScheduledPresentation.name = Scheduled
16
ScheduledPresentation.name = Scheduled
15
17
16
views.category.name = Tasks
18
views.category.name = Tasks

Return to bug 212967