|
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 |
} |