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