Lines 11-734
Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.ui.views.markers.internal; |
12 |
package org.eclipse.ui.views.markers.internal; |
13 |
|
13 |
|
14 |
import java.util.ArrayList; |
|
|
15 |
import java.util.Arrays; |
16 |
import java.util.Collection; |
17 |
import java.util.Collections; |
18 |
import java.util.HashSet; |
14 |
import java.util.HashSet; |
19 |
import java.util.Iterator; |
15 |
import java.util.Iterator; |
20 |
import java.util.List; |
|
|
21 |
import java.util.Set; |
16 |
import java.util.Set; |
22 |
import java.util.StringTokenizer; |
|
|
23 |
|
17 |
|
24 |
import org.eclipse.core.resources.IContainer; |
|
|
25 |
import org.eclipse.core.resources.IMarker; |
18 |
import org.eclipse.core.resources.IMarker; |
26 |
import org.eclipse.core.resources.IProject; |
19 |
import org.eclipse.core.runtime.IPath; |
27 |
import org.eclipse.core.resources.IResource; |
20 |
import org.eclipse.jface.viewers.deferred.IFilter; |
28 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
|
29 |
import org.eclipse.core.runtime.CoreException; |
30 |
import org.eclipse.core.runtime.IAdaptable; |
31 |
import org.eclipse.core.runtime.IProgressMonitor; |
32 |
import org.eclipse.jface.dialogs.IDialogSettings; |
33 |
import org.eclipse.ui.IWorkingSet; |
34 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
35 |
|
21 |
|
36 |
public class MarkerFilter { |
22 |
public class MarkerFilter implements IFilter { |
37 |
|
23 |
|
38 |
private static final String TAG_DIALOG_SECTION = "filter"; //$NON-NLS-1$ |
24 |
final static int DEFAULT_SEVERITY = 0; |
39 |
|
25 |
final static int SEVERITY_ERROR = 1 << 2; |
40 |
private static final String TAG_ENABLED = "enabled"; //$NON-NLS-1$ |
26 |
final static int SEVERITY_WARNING = 1 << 1; |
41 |
|
27 |
final static int SEVERITY_INFO = 1 << 0; |
42 |
private static final String TAG_FILTER_ON_MARKER_LIMIT = "filterOnMarkerLimit"; //$NON-NLS-1$ |
28 |
|
43 |
|
29 |
final static int PRIORITY_HIGH = 1 << 2; |
44 |
private static final String TAG_MARKER_LIMIT = "markerLimit"; //$NON-NLS-1$ |
30 |
final static int PRIORITY_NORMAL = 1 << 1; |
45 |
|
31 |
final static int PRIORITY_LOW = 1 << 0; |
46 |
private static final String TAG_ON_RESOURCE = "onResource"; //$NON-NLS-1$ |
32 |
|
47 |
|
33 |
protected String[] requiredTypes; |
48 |
private static final String TAG_SELECTED_TYPES = "selectedType"; //$NON-NLS-1$ |
34 |
|
49 |
|
35 |
private String description = ""; //$NON-NLS-1$ |
50 |
private static final String TAG_WORKING_SET = "workingSet"; //$NON-NLS-1$ |
36 |
private boolean contains; |
51 |
|
37 |
|
52 |
private static final String TAG_TYPES_DELIMITER = ":"; //$NON-NLS-1$ |
38 |
private boolean selectBySeverity; |
53 |
|
39 |
private int severity; |
54 |
static final int ON_ANY_RESOURCE = 0; |
40 |
|
55 |
|
41 |
private boolean done; |
56 |
static final int ON_SELECTED_RESOURCE_ONLY = 1; |
42 |
private int priority; |
57 |
|
43 |
private boolean selectByPriority; |
58 |
static final int ON_SELECTED_RESOURCE_AND_CHILDREN = 2; |
44 |
private boolean selectByDone; |
59 |
|
45 |
|
60 |
static final int ON_ANY_RESOURCE_OF_SAME_PROJECT = 3; |
46 |
/** |
61 |
|
47 |
* Set of IPath containing workspace-relative paths to resources accepted |
62 |
static final int ON_WORKING_SET = 4; |
48 |
* by this filter. null if the filter accepts any resource. |
63 |
|
49 |
*/ |
64 |
static final int DEFAULT_MARKER_LIMIT = 100; |
50 |
private Set resourcePaths; |
65 |
|
51 |
private boolean includeChildResources = false; |
66 |
static final boolean DEFAULT_FILTER_ON_MARKER_LIMIT = true; |
52 |
private Set requiredTypeSet; |
67 |
|
53 |
|
68 |
static final int DEFAULT_ON_RESOURCE = ON_ANY_RESOURCE; |
54 |
MarkerFilter(String[] requiredTypes) { |
69 |
|
55 |
this.requiredTypes = requiredTypes; |
70 |
static final boolean DEFAULT_ACTIVATION_STATUS = true; |
56 |
this.resourcePaths = null; |
71 |
|
57 |
} |
72 |
protected List rootTypes = new ArrayList(); |
58 |
|
73 |
|
59 |
// MarkerFilter(String[] requiredTypes, IResource[] exactResources) { |
74 |
protected List selectedTypes = new ArrayList(); |
60 |
// this.requiredTypes = requiredTypes; |
75 |
|
61 |
// this.requiredResources = exactResources; |
76 |
protected IWorkingSet workingSet; |
62 |
// } |
77 |
|
63 |
|
78 |
protected int onResource; |
64 |
/** |
79 |
|
65 |
* @param resourcePathSet Set of IPath |
80 |
protected boolean filterOnMarkerLimit; |
66 |
*/ |
81 |
|
67 |
MarkerFilter(String[] requiredTypes, Set resourcePathSet, boolean includeChildResources) { |
82 |
protected boolean enabled; |
68 |
this.requiredTypes = requiredTypes; |
83 |
|
69 |
resourcePaths = resourcePathSet; |
84 |
protected int markerLimit; |
70 |
this.includeChildResources = includeChildResources; |
85 |
|
71 |
} |
86 |
private MarkerTypesModel typesModel; |
72 |
|
87 |
|
73 |
/* (non-Javadoc) |
88 |
private IResource[] focusResource; |
74 |
* @see java.lang.Object#equals(java.lang.Object) |
89 |
|
75 |
*/ |
90 |
private Set cachedWorkingSet; |
76 |
public boolean equals(Object arg0) { |
91 |
|
77 |
if (!(arg0 instanceof MarkerFilter)) { |
92 |
MarkerFilter(String[] rootTypes) { |
78 |
return false; |
93 |
typesModel = new MarkerTypesModel(); |
79 |
} |
94 |
|
80 |
|
95 |
for (int i = 0; i < rootTypes.length; i++) { |
81 |
MarkerFilter other = (MarkerFilter)arg0; |
96 |
MarkerType type = typesModel.getType(rootTypes[i]); |
82 |
|
|
|
83 |
if (!(other.contains == contains |
84 |
&& other.description.equals(description) |
85 |
&& other.selectBySeverity == selectBySeverity |
86 |
&& other.severity == severity |
87 |
&& other.done == done |
88 |
&& other.priority == priority |
89 |
&& other.includeChildResources == includeChildResources |
90 |
&& other.selectByPriority == selectByPriority |
91 |
&& other.selectBySeverity == selectBySeverity |
92 |
&& other.requiredTypes.length == requiredTypes.length)) return false; |
93 |
|
94 |
for (int i = 0; i < other.requiredTypes.length; i++) { |
95 |
String type = other.requiredTypes[i]; |
96 |
|
97 |
if (!selectByType(type)) { |
98 |
return false; |
99 |
} |
100 |
} |
101 |
|
102 |
if (resourcePaths == null || other.resourcePaths == null) { |
103 |
// Unless they're both null, the filters aren't equal |
104 |
if (resourcePaths != other.resourcePaths) { |
105 |
return false; |
106 |
} |
107 |
} else { |
108 |
if (!includeChildResources) { |
109 |
if (!resourcePaths.equals(other.resourcePaths)) return false; |
110 |
} else { |
111 |
// Check for "resources + children" style matches |
112 |
for (Iterator iter = resourcePaths.iterator(); iter.hasNext();) { |
113 |
IPath next = (IPath) iter.next(); |
114 |
|
115 |
if (!other.selectByResource(next)) { |
116 |
return false; |
117 |
} |
118 |
} |
119 |
for (Iterator iter = other.resourcePaths.iterator(); iter.hasNext();) { |
120 |
IPath next = (IPath) iter.next(); |
121 |
|
122 |
if (!selectByResource(next)) { |
123 |
return false; |
124 |
} |
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
return true; |
130 |
} |
131 |
|
132 |
/* (non-Javadoc) |
133 |
* @see org.eclipse.jface.viewers.deferred.IFilter#select(java.lang.Object) |
134 |
*/ |
135 |
public boolean select(Object toTest) { |
136 |
if (!(toTest instanceof ConcreteMarker)) { |
137 |
return false; |
138 |
} |
139 |
ConcreteMarker m = (ConcreteMarker)toTest; |
140 |
|
141 |
if (selectByType(m.getType()) && selectByResource(m.getResource().getFullPath()) && selectByDescription(m) && selectBySeverity(m) |
142 |
&& selectByDone(m) && selectByPriority(m)) { |
143 |
return true; |
144 |
} |
145 |
|
146 |
return false; |
147 |
} |
148 |
|
149 |
private boolean selectByResource(IPath resource) { |
150 |
|
151 |
if (resourcePaths == null) { |
152 |
return true; |
153 |
} |
154 |
|
155 |
if (includeChildResources) { |
156 |
if (resourcePaths.contains(resource)) { |
157 |
return true; |
158 |
} |
159 |
|
160 |
if (resource.segmentCount() == 0) { |
161 |
return false; |
162 |
} |
163 |
|
164 |
return selectByResource(resource.removeLastSegments(1)); |
165 |
} else { |
166 |
return resourcePaths.contains(resource); |
167 |
} |
168 |
} |
169 |
|
170 |
private boolean selectByType(String type) { |
171 |
if (requiredTypeSet == null) { |
172 |
requiredTypeSet = new HashSet(); |
173 |
for (int i = 0; i < requiredTypes.length; i++) { |
174 |
String next = requiredTypes[i]; |
175 |
|
176 |
requiredTypeSet.add(next); |
177 |
} |
178 |
} |
179 |
|
180 |
return requiredTypeSet.contains(type); |
181 |
} |
182 |
|
183 |
public void setDescription(String description, boolean contains) { |
184 |
this.description = description; |
185 |
this.contains = contains; |
186 |
} |
187 |
|
188 |
private boolean selectByDescription(ConcreteMarker marker) { |
189 |
if (description == null || description.equals("")) //$NON-NLS-1$ |
190 |
return true; |
97 |
|
191 |
|
98 |
if (!this.rootTypes.contains(type)) |
192 |
String markerDescription = marker.getDescription(); |
99 |
this.rootTypes.add(type); |
193 |
int index = markerDescription.indexOf(description); |
100 |
} |
194 |
return contains ? (index >= 0) : (index < 0); |
101 |
} |
195 |
} |
102 |
|
196 |
|
103 |
private void addAllSubTypes() { |
197 |
public void setSelectBySeverity(boolean selectBySeverity) { |
104 |
for (int i = 0; i < rootTypes.size(); i++) { |
198 |
this.selectBySeverity = selectBySeverity; |
105 |
MarkerType rootType = (MarkerType) rootTypes.get(i); |
|
|
106 |
addAllSubTypes(rootType); |
107 |
} |
108 |
} |
199 |
} |
109 |
|
200 |
|
110 |
private void addAllSubTypes(MarkerType type) { |
201 |
public void setSeverity(int severity) { |
111 |
if (type == null) |
202 |
this.severity = severity; |
112 |
return; |
|
|
113 |
|
114 |
if (!selectedTypes.contains(type)) |
115 |
selectedTypes.add(type); |
116 |
|
117 |
MarkerType[] subTypes = type.getSubtypes(); |
118 |
|
119 |
for (int i = 0; i < subTypes.length; i++) |
120 |
addAllSubTypes(subTypes[i]); |
121 |
} |
203 |
} |
122 |
|
204 |
|
123 |
/** |
205 |
private boolean selectBySeverity(ConcreteMarker item) { |
124 |
* Adds all markers in the given set of resources to the given list |
206 |
if (selectBySeverity) { |
125 |
* |
207 |
int markerSeverity = item.getSeverity(); |
126 |
* @param resultList |
|
|
127 |
* @param resources |
128 |
* @param markerTypeId |
129 |
* @param depth |
130 |
* @throws CoreException |
131 |
*/ |
132 |
private List findMarkers(IResource[] resources, int depth, int limit, |
133 |
IProgressMonitor mon, boolean ignoreExceptions) |
134 |
throws CoreException { |
135 |
if (resources == null) { |
136 |
return Collections.EMPTY_LIST; |
137 |
} |
138 |
|
139 |
List resultList = new ArrayList(resources.length * 2); |
140 |
|
141 |
// Optimization: if a type appears in the selectedTypes list along with all of its |
142 |
// subtypes, then combine these in a single search. |
143 |
|
144 |
// List of types that haven't been replaced by one of their supertypes |
145 |
HashSet typesToSearch = new HashSet(selectedTypes.size()); |
146 |
|
147 |
// List of types that appeared in selectedTypes along with all of their subtypes |
148 |
HashSet includeAllSubtypes = new HashSet(selectedTypes.size()); |
149 |
|
150 |
typesToSearch.addAll(selectedTypes); |
151 |
|
152 |
Iterator iter = selectedTypes.iterator(); |
153 |
|
154 |
while (iter.hasNext()) { |
155 |
MarkerType type = (MarkerType) iter.next(); |
156 |
|
157 |
Collection subtypes = Arrays.asList(type.getAllSubTypes()); |
158 |
|
159 |
if (selectedTypes.containsAll(subtypes)) { |
160 |
typesToSearch.removeAll(subtypes); |
161 |
|
162 |
includeAllSubtypes.add(type); |
163 |
} |
164 |
} |
165 |
|
166 |
mon |
167 |
.beginTask( |
168 |
Messages.getString("MarkerFilter.searching"), typesToSearch.size() * resources.length); //$NON-NLS-1$ |
169 |
|
170 |
// Use this hash set to determine if there are any resources in the |
171 |
// list that appear along with their parent. |
172 |
HashSet resourcesToSearch = new HashSet(); |
173 |
|
174 |
// Insert all the resources into the hashset |
175 |
for (int idx = 0; idx < resources.length; idx++) { |
176 |
IResource next = resources[idx]; |
177 |
|
178 |
if (!next.exists()) { |
179 |
continue; |
180 |
} |
181 |
|
182 |
if (resourcesToSearch.contains(next)) { |
183 |
mon.worked(typesToSearch.size()); |
184 |
} else { |
185 |
resourcesToSearch.add(next); |
186 |
} |
187 |
} |
188 |
|
208 |
|
189 |
// Iterate through all the selected resources |
209 |
if (markerSeverity == IMarker.SEVERITY_ERROR) |
190 |
for (int resourceIdx = 0; resourceIdx < resources.length; resourceIdx++) { |
210 |
return (severity & SEVERITY_ERROR) > 0; |
191 |
iter = typesToSearch.iterator(); |
211 |
else if (markerSeverity == IMarker.SEVERITY_WARNING) |
192 |
|
212 |
return (severity & SEVERITY_WARNING) > 0; |
193 |
IResource resource = resources[resourceIdx]; |
213 |
else if (markerSeverity == IMarker.SEVERITY_INFO) |
194 |
|
214 |
return (severity & SEVERITY_INFO) > 0; |
195 |
// Skip resources that don't exist |
|
|
196 |
if (!resource.isAccessible()) { |
197 |
continue; |
198 |
} |
199 |
|
200 |
if (depth == IResource.DEPTH_INFINITE) { |
201 |
// Determine if any parent of this resource is also in our filter |
202 |
IResource parent = resource.getParent(); |
203 |
boolean found = false; |
204 |
while (parent != null) { |
205 |
if (resourcesToSearch.contains(parent)) { |
206 |
found = true; |
207 |
} |
208 |
|
209 |
parent = parent.getParent(); |
210 |
} |
211 |
|
212 |
// If a parent of this resource is also in the filter, we can skip it |
213 |
// because we'll pick up its markers when we search the parent. |
214 |
if (found) { |
215 |
continue; |
216 |
} |
217 |
} |
218 |
|
219 |
// Iterate through all the marker types |
220 |
while (iter.hasNext()) { |
221 |
MarkerType markerType = (MarkerType) iter.next(); |
222 |
|
223 |
// Only search for subtypes of the marker if we found all of its |
224 |
// subtypes in the filter criteria. |
225 |
IMarker[] markers = resource.findMarkers(markerType.getId(), |
226 |
includeAllSubtypes.contains(markerType), depth); |
227 |
|
228 |
mon.worked(1); |
229 |
|
230 |
for (int idx = 0; idx < markers.length; idx++) { |
231 |
ConcreteMarker marker; |
232 |
try { |
233 |
marker = MarkerList.createMarker(markers[idx]); |
234 |
} catch (CoreException e) { |
235 |
if (ignoreExceptions) { |
236 |
continue; |
237 |
} else { |
238 |
throw e; |
239 |
} |
240 |
} |
241 |
|
242 |
if (limit != -1 && resultList.size() >= limit) { |
243 |
return resultList; |
244 |
} |
245 |
|
246 |
if (selectMarker(marker)) { |
247 |
resultList.add(marker); |
248 |
} |
249 |
} |
250 |
} |
251 |
} |
215 |
} |
252 |
|
216 |
|
253 |
mon.done(); |
|
|
254 |
|
255 |
return resultList; |
256 |
} |
257 |
|
258 |
/** |
259 |
* Subclasses should override to determine if the given marker passes the filter. |
260 |
* |
261 |
* @param marker |
262 |
* @return <code>true</code> if the marker passes the filter and <code>false</code> otherwise |
263 |
*/ |
264 |
protected boolean selectMarker(ConcreteMarker marker) { |
265 |
return true; |
217 |
return true; |
266 |
} |
218 |
} |
267 |
|
219 |
|
268 |
/** |
220 |
public void setDone(boolean done) { |
269 |
* Searches the workspace for markers that pass this filter. |
221 |
this.done = done; |
270 |
* |
|
|
271 |
* @return |
272 |
*/ |
273 |
ConcreteMarker[] findMarkers(IProgressMonitor mon, boolean ignoreExceptions) |
274 |
throws CoreException { |
275 |
|
276 |
List unfiltered = Collections.EMPTY_LIST; |
277 |
|
278 |
if (!isEnabled()) { |
279 |
unfiltered = findMarkers(new IResource[] { ResourcesPlugin |
280 |
.getWorkspace().getRoot() }, IResource.DEPTH_INFINITE, -1, |
281 |
mon, ignoreExceptions); |
282 |
} else { |
283 |
//int limit = getFilterOnMarkerLimit() ? getMarkerLimit() + 1 : -1; |
284 |
int limit = -1; |
285 |
|
286 |
switch (getOnResource()) { |
287 |
case ON_ANY_RESOURCE: { |
288 |
unfiltered = findMarkers(new IResource[] { ResourcesPlugin |
289 |
.getWorkspace().getRoot() }, IResource.DEPTH_INFINITE, |
290 |
limit, mon, ignoreExceptions); |
291 |
break; |
292 |
} |
293 |
case ON_SELECTED_RESOURCE_ONLY: { |
294 |
unfiltered = findMarkers(focusResource, IResource.DEPTH_ZERO, |
295 |
limit, mon, ignoreExceptions); |
296 |
break; |
297 |
} |
298 |
case ON_SELECTED_RESOURCE_AND_CHILDREN: { |
299 |
unfiltered = findMarkers(focusResource, |
300 |
IResource.DEPTH_INFINITE, limit, mon, ignoreExceptions); |
301 |
break; |
302 |
} |
303 |
case ON_ANY_RESOURCE_OF_SAME_PROJECT: { |
304 |
unfiltered = findMarkers(getProjects(focusResource), |
305 |
IResource.DEPTH_INFINITE, limit, mon, ignoreExceptions); |
306 |
break; |
307 |
} |
308 |
case ON_WORKING_SET: { |
309 |
unfiltered = findMarkers(getResourcesInWorkingSet(), |
310 |
IResource.DEPTH_INFINITE, limit, mon, ignoreExceptions); |
311 |
} |
312 |
} |
313 |
} |
314 |
|
315 |
if (unfiltered == null) { |
316 |
unfiltered = Collections.EMPTY_LIST; |
317 |
} |
318 |
|
319 |
return (ConcreteMarker[]) unfiltered |
320 |
.toArray(new ConcreteMarker[unfiltered.size()]); |
321 |
} |
322 |
|
323 |
IResource[] getResourcesInWorkingSet() { |
324 |
if (workingSet == null) { |
325 |
return new IResource[0]; |
326 |
} |
327 |
|
328 |
IAdaptable[] elements = workingSet.getElements(); |
329 |
List result = new ArrayList(elements.length); |
330 |
|
331 |
for (int idx = 0; idx < elements.length; idx++) { |
332 |
IResource next = (IResource) elements[idx] |
333 |
.getAdapter(IResource.class); |
334 |
|
335 |
if (next != null) { |
336 |
result.add(next); |
337 |
} |
338 |
} |
339 |
|
340 |
return (IResource[]) result.toArray(new IResource[result.size()]); |
341 |
} |
222 |
} |
342 |
|
223 |
|
343 |
/** |
224 |
public void setPriority(int priority) { |
344 |
* Returns a set of strings representing the full pathnames to every resource directly |
225 |
this.priority = priority; |
345 |
* or indirectly contained in the working set. A resource is in the working set iff its |
|
|
346 |
* path name can be found in this set. |
347 |
* |
348 |
* @return |
349 |
*/ |
350 |
private Set getWorkingSetAsSetOfPaths() { |
351 |
if (cachedWorkingSet == null) { |
352 |
HashSet result = new HashSet(); |
353 |
|
354 |
addResourcesAndChildren(result, getResourcesInWorkingSet()); |
355 |
|
356 |
cachedWorkingSet = result; |
357 |
} |
358 |
|
359 |
return cachedWorkingSet; |
360 |
} |
361 |
|
362 |
/*** |
363 |
* Adds the paths of all resources in the given array to the given set. |
364 |
*/ |
365 |
private void addResourcesAndChildren(HashSet result, IResource[] resources) { |
366 |
for (int idx = 0; idx < resources.length; idx++) { |
367 |
|
368 |
IResource currentResource = resources[idx]; |
369 |
|
370 |
result.add(currentResource.getFullPath().toString()); |
371 |
|
372 |
if (currentResource instanceof IContainer) { |
373 |
IContainer cont = (IContainer) currentResource; |
374 |
|
375 |
try { |
376 |
addResourcesAndChildren(result, cont.members()); |
377 |
} catch (CoreException e) { |
378 |
// Ignore errors |
379 |
} |
380 |
} |
381 |
|
382 |
} |
383 |
} |
384 |
|
385 |
/** |
386 |
* Returns the set of projects that contain the given set of resources. |
387 |
* |
388 |
* @param resources |
389 |
* @return |
390 |
*/ |
391 |
static IProject[] getProjects(IResource[] resources) { |
392 |
if (resources == null) { |
393 |
return new IProject[0]; |
394 |
} |
395 |
|
396 |
Collection projects = getProjectsAsCollection(resources); |
397 |
|
398 |
return (IProject[]) projects.toArray(new IProject[projects.size()]); |
399 |
} |
400 |
|
401 |
static Collection getProjectsAsCollection(IResource[] resources) { |
402 |
HashSet projects = new HashSet(); |
403 |
|
404 |
for (int idx = 0; idx < resources.length; idx++) { |
405 |
projects.add(resources[idx].getProject()); |
406 |
} |
407 |
|
408 |
return projects; |
409 |
} |
226 |
} |
410 |
|
227 |
|
411 |
public boolean select(ConcreteMarker marker) { |
228 |
public void setSelectByDone(boolean selectByDone) { |
412 |
if (!isEnabled()) { |
229 |
this.selectByDone = selectByDone; |
413 |
return true; |
|
|
414 |
} |
415 |
|
416 |
return selectByType(marker) && selectBySelection(marker) |
417 |
&& selectMarker(marker); |
418 |
} |
230 |
} |
419 |
|
231 |
|
420 |
private boolean selectByType(ConcreteMarker marker) { |
232 |
public void setSelectByPriority(boolean selectByPriority) { |
421 |
return selectedTypes.contains(typesModel.getType(marker.getType())); |
233 |
this.selectByPriority = selectByPriority; |
422 |
} |
234 |
} |
423 |
|
235 |
|
424 |
/** |
236 |
private boolean selectByDone(ConcreteMarker item) { |
425 |
* Returns whether the specified marker should be filter out or not. |
237 |
if (selectByDone) |
426 |
* |
238 |
return done == (item.getDone() == 1); |
427 |
* @param marker the marker to test |
|
|
428 |
* @return |
429 |
* true=the marker should not be filtered out |
430 |
* false=the marker should be filtered out |
431 |
*/ |
432 |
private boolean selectBySelection(ConcreteMarker marker) { |
433 |
if (onResource == ON_ANY_RESOURCE || marker == null) |
434 |
return true; |
435 |
|
239 |
|
436 |
if (focusResource == null) |
240 |
return true; |
437 |
return true; |
|
|
438 |
|
439 |
IResource resource = marker.getResource(); |
440 |
|
441 |
if (onResource == ON_WORKING_SET) { |
442 |
if (workingSet == null) |
443 |
return true; |
444 |
|
445 |
if (resource != null) |
446 |
return isEnclosed(resource); |
447 |
|
448 |
} else if (onResource == ON_ANY_RESOURCE_OF_SAME_PROJECT) { |
449 |
IProject project = resource.getProject(); |
450 |
|
451 |
if (project == null) { |
452 |
return false; |
453 |
} |
454 |
|
455 |
for (int i = 0; i < focusResource.length; i++) { |
456 |
IProject selectedProject = focusResource[i].getProject(); |
457 |
|
458 |
if (selectedProject == null) { |
459 |
continue; |
460 |
} |
461 |
|
462 |
if (project.equals(selectedProject)) |
463 |
return true; |
464 |
} |
465 |
} else if (onResource == ON_SELECTED_RESOURCE_ONLY) { |
466 |
for (int i = 0; i < focusResource.length; i++) { |
467 |
if (resource.equals(focusResource[i])) |
468 |
return true; |
469 |
} |
470 |
} else if (onResource == ON_SELECTED_RESOURCE_AND_CHILDREN) { |
471 |
for (int i = 0; i < focusResource.length; i++) { |
472 |
IResource parentResource = resource; |
473 |
|
474 |
while (parentResource != null) { |
475 |
if (parentResource.equals(focusResource[i])) |
476 |
return true; |
477 |
|
478 |
parentResource = parentResource.getParent(); |
479 |
} |
480 |
} |
481 |
} |
482 |
|
483 |
return false; |
484 |
} |
241 |
} |
485 |
|
242 |
|
486 |
/** |
243 |
private boolean selectByPriority(ConcreteMarker marker) { |
487 |
* Returns if the given resource is enclosed by a working set element. |
244 |
if (priority != 0 && selectByPriority) { |
488 |
* Previous versions of this method used IContainmentAdapter for |
245 |
int markerPriority = marker.getPriority(); |
489 |
* containment tests. For performance reasons, this is no longer possible. |
246 |
|
490 |
* Code that relies on this behavior should be updated appropriately. |
247 |
if (markerPriority == IMarker.PRIORITY_HIGH) |
491 |
* |
248 |
return (priority & PRIORITY_HIGH) > 0; |
492 |
* @param element resource to test for enclosure by a working set |
249 |
else if (markerPriority == IMarker.PRIORITY_NORMAL) |
493 |
* element |
250 |
return (priority & PRIORITY_NORMAL) > 0; |
494 |
* @return true if element is enclosed by a working set element and |
251 |
else if (markerPriority == IMarker.PRIORITY_LOW) |
495 |
* false otherwise. |
252 |
return (priority & PRIORITY_LOW) > 0; |
496 |
*/ |
|
|
497 |
private boolean isEnclosed(IResource element) { |
498 |
if (workingSet == null) { |
499 |
return false; |
500 |
} |
253 |
} |
501 |
Set workingSetPaths = getWorkingSetAsSetOfPaths(); |
|
|
502 |
|
503 |
return workingSetPaths.contains(element.getFullPath().toString()); |
504 |
} |
505 |
|
506 |
/** |
507 |
* @return the defined limit on the number of markers to be displayed. |
508 |
*/ |
509 |
int getMarkerLimit() { |
510 |
return markerLimit; |
511 |
} |
512 |
|
513 |
/** |
514 |
* Sets the limit on the number of markers to be displayed. |
515 |
* |
516 |
* @param the new limit |
517 |
*/ |
518 |
void setMarkerLimit(int markerLimit) { |
519 |
this.markerLimit = markerLimit; |
520 |
} |
521 |
|
522 |
/** |
523 |
* @return <ul> |
524 |
* <li><code>MarkerFilter.ON_ANY_RESOURCE</code> if showing items associated with any resource.</li> |
525 |
* <li><code>MarkerFilter.ON_SELECTED_RESOURCE_ONLY</code> if showing items associated with |
526 |
* the selected resource within the workbench.</li> |
527 |
* <li><code>MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN</code> if showing items associated with |
528 |
* the selected resource within the workbench and its children.</li> |
529 |
* <li><code>MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT</code> if showing items in the same project |
530 |
* as the selected resource within the workbench.</li> |
531 |
* <li><code>MarkerFilter.ON_WORKING_SET</code> if showing items in some working set.</li> |
532 |
* </ul> |
533 |
*/ |
534 |
int getOnResource() { |
535 |
return onResource; |
536 |
} |
537 |
|
538 |
/** |
539 |
* Sets the type of filtering by selection. |
540 |
* |
541 |
* @param onResource must be one of: |
542 |
* <ul> |
543 |
* <li><code>MarkerFilter.ON_ANY_RESOURCE</code></li> |
544 |
* <li><code>MarkerFilter.ON_SELECTED_RESOURCE_ONLY</code></li> |
545 |
* <li><code>MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN</code></li> |
546 |
* <li><code>MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT</code></li> |
547 |
* <li><code>MarkerFilter.ON_WORKING_SET</code></li> |
548 |
* </ul> |
549 |
*/ |
550 |
void setOnResource(int onResource) { |
551 |
if (onResource >= ON_ANY_RESOURCE && onResource <= ON_WORKING_SET) |
552 |
this.onResource = onResource; |
553 |
} |
554 |
|
555 |
/** |
556 |
* @return the selected resource(s) withing the workbench. |
557 |
*/ |
558 |
IResource[] getFocusResource() { |
559 |
return focusResource; |
560 |
} |
561 |
|
562 |
/** |
563 |
* Sets the focused resources. |
564 |
*/ |
565 |
public void setFocusResource(IResource[] resources) { |
566 |
focusResource = resources; |
567 |
} |
568 |
|
569 |
/** |
570 |
* @return |
571 |
* <ul> |
572 |
* <li><code>true</code> if the filter is enabled.</li> |
573 |
* <li><code>false</code> if the filter is not enabled.</li> |
574 |
* </ul> |
575 |
*/ |
576 |
boolean isEnabled() { |
577 |
return enabled; |
578 |
} |
579 |
|
580 |
/** |
581 |
* @return |
582 |
* <ul> |
583 |
* <li><code>true</code> if filtering by marker limit is enabled.</li> |
584 |
* <li><code>false</code> if filtering by marker limit is not enabled.</li> |
585 |
* </ul> |
586 |
*/ |
587 |
boolean getFilterOnMarkerLimit() { |
588 |
return filterOnMarkerLimit; |
589 |
} |
590 |
|
591 |
/** |
592 |
* @return the root marker types. |
593 |
*/ |
594 |
List getRootTypes() { |
595 |
return rootTypes; |
596 |
} |
597 |
|
598 |
/** |
599 |
* @return the selected marker types to be displayed. |
600 |
*/ |
601 |
List getSelectedTypes() { |
602 |
return selectedTypes; |
603 |
} |
604 |
|
254 |
|
605 |
/** |
255 |
return true; |
606 |
* @return the current working set or <code>null</code> if no working set is defined. |
|
|
607 |
*/ |
608 |
IWorkingSet getWorkingSet() { |
609 |
return workingSet; |
610 |
} |
611 |
|
612 |
/** |
613 |
* Sets the enablement state of the filter. |
614 |
*/ |
615 |
void setEnabled(boolean enabled) { |
616 |
this.enabled = enabled; |
617 |
} |
618 |
|
619 |
/** |
620 |
* Sets the enablement state of filtering by marker limit. |
621 |
*/ |
622 |
void setFilterOnMarkerLimit(boolean filterOnMarkerLimit) { |
623 |
this.filterOnMarkerLimit = filterOnMarkerLimit; |
624 |
} |
625 |
|
626 |
/** |
627 |
* Sets the selected marker types to be displayed. The List <b>MUST ONLY</b> contain |
628 |
* <code>MarkerType</code> objects. |
629 |
*/ |
630 |
void setSelectedTypes(List selectedTypes) { |
631 |
this.selectedTypes = selectedTypes; |
632 |
} |
633 |
|
634 |
/** |
635 |
* Sets the current working set. |
636 |
*/ |
637 |
void setWorkingSet(IWorkingSet workingSet) { |
638 |
this.workingSet = workingSet; |
639 |
cachedWorkingSet = null; |
640 |
} |
641 |
|
642 |
void resetState() { |
643 |
enabled = DEFAULT_ACTIVATION_STATUS; |
644 |
filterOnMarkerLimit = DEFAULT_FILTER_ON_MARKER_LIMIT; |
645 |
markerLimit = DEFAULT_MARKER_LIMIT; |
646 |
onResource = DEFAULT_ON_RESOURCE; |
647 |
selectedTypes.clear(); |
648 |
addAllSubTypes(); |
649 |
setWorkingSet(null); |
650 |
} |
651 |
|
652 |
public void restoreState(IDialogSettings dialogSettings) { |
653 |
resetState(); |
654 |
IDialogSettings settings = dialogSettings |
655 |
.getSection(TAG_DIALOG_SECTION); |
656 |
|
657 |
if (settings != null) { |
658 |
String setting = settings.get(TAG_ENABLED); |
659 |
|
660 |
if (setting != null) |
661 |
enabled = Boolean.valueOf(setting).booleanValue(); |
662 |
|
663 |
setting = settings.get(TAG_FILTER_ON_MARKER_LIMIT); |
664 |
|
665 |
if (setting != null) |
666 |
filterOnMarkerLimit = Boolean.valueOf(setting).booleanValue(); |
667 |
|
668 |
setting = settings.get(TAG_MARKER_LIMIT); |
669 |
|
670 |
if (setting != null) |
671 |
try { |
672 |
markerLimit = Integer.parseInt(setting); |
673 |
} catch (NumberFormatException eNumberFormat) { |
674 |
} |
675 |
|
676 |
setting = settings.get(TAG_ON_RESOURCE); |
677 |
|
678 |
if (setting != null) |
679 |
try { |
680 |
onResource = Integer.parseInt(setting); |
681 |
} catch (NumberFormatException eNumberFormat) { |
682 |
} |
683 |
|
684 |
setting = settings.get(TAG_SELECTED_TYPES); |
685 |
|
686 |
if (setting != null) { |
687 |
selectedTypes.clear(); |
688 |
StringTokenizer stringTokenizer = new StringTokenizer(setting); |
689 |
|
690 |
while (stringTokenizer.hasMoreTokens()) { |
691 |
MarkerType markerType = typesModel.getType(stringTokenizer |
692 |
.nextToken(TAG_TYPES_DELIMITER)); |
693 |
|
694 |
if (markerType != null |
695 |
&& !selectedTypes.contains(markerType)) |
696 |
selectedTypes.add(markerType); |
697 |
} |
698 |
} |
699 |
|
700 |
setting = settings.get(TAG_WORKING_SET); |
701 |
|
702 |
if (setting != null) |
703 |
setWorkingSet(WorkbenchPlugin.getDefault() |
704 |
.getWorkingSetManager().getWorkingSet(setting)); |
705 |
} |
706 |
} |
256 |
} |
707 |
|
257 |
|
708 |
public void saveState(IDialogSettings dialogSettings) { |
|
|
709 |
if (dialogSettings != null) { |
710 |
IDialogSettings settings = dialogSettings |
711 |
.getSection(TAG_DIALOG_SECTION); |
712 |
|
713 |
if (settings == null) |
714 |
settings = dialogSettings.addNewSection(TAG_DIALOG_SECTION); |
715 |
|
716 |
settings.put(TAG_ENABLED, enabled); |
717 |
settings.put(TAG_FILTER_ON_MARKER_LIMIT, filterOnMarkerLimit); |
718 |
settings.put(TAG_MARKER_LIMIT, markerLimit); |
719 |
settings.put(TAG_ON_RESOURCE, onResource); |
720 |
|
721 |
String markerTypeIds = ""; //$NON-NLS-1$ |
722 |
|
723 |
for (int i = 0; i < selectedTypes.size(); i++) { |
724 |
MarkerType markerType = (MarkerType) selectedTypes.get(i); |
725 |
markerTypeIds += markerType.getId() + TAG_TYPES_DELIMITER; |
726 |
} |
727 |
|
728 |
settings.put(TAG_SELECTED_TYPES, markerTypeIds); |
729 |
|
730 |
if (workingSet != null) |
731 |
settings.put(TAG_WORKING_SET, workingSet.getName()); |
732 |
} |
733 |
} |
734 |
} |
258 |
} |