KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > MarkerSupportRegistry


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation 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  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.views.markers.internal;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.eclipse.core.resources.IMarker;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.IConfigurationElement;
25 import org.eclipse.core.runtime.IExtension;
26 import org.eclipse.core.runtime.IExtensionPoint;
27 import org.eclipse.core.runtime.IStatus;
28 import org.eclipse.core.runtime.Platform;
29 import org.eclipse.core.runtime.Status;
30 import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
31 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
32 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
33 import org.eclipse.osgi.util.NLS;
34 import org.eclipse.ui.PlatformUI;
35 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
36
37 /**
38  * The ProblemFilterRegistryReader is the registry reader for declarative
39  * problem filters. See the org.eclipse.ui.markerSupport extension point.
40  *
41  * @since 3.2
42  *
43  */

44 public class MarkerSupportRegistry implements IExtensionChangeHandler {
45
46     private static final String JavaDoc DESCRIPTION = "onDescription"; //$NON-NLS-1$
47

48     private static final String JavaDoc ENABLED = "enabled"; //$NON-NLS-1$
49

50     private static final Object JavaDoc ERROR = "ERROR";//$NON-NLS-1$
51

52     static final String JavaDoc ID = "id"; //$NON-NLS-1$
53

54     private static final Object JavaDoc INFO = "INFO";//$NON-NLS-1$
55

56     private static final Object JavaDoc WARNING = "WARNING";//$NON-NLS-1$
57

58     private static final String JavaDoc MARKER_ID = "markerId"; //$NON-NLS-1$
59

60     /**
61      * The tag for the marker support extension
62      */

63     public static final String JavaDoc MARKER_SUPPORT = "markerSupport";//$NON-NLS-1$
64

65     private static final String JavaDoc NAME = "name"; //$NON-NLS-1$
66

67     private static final Object JavaDoc ON_ANY = "ON_ANY"; //$NON-NLS-1$
68

69     private static final Object JavaDoc ON_ANY_IN_SAME_CONTAINER = "ON_ANY_IN_SAME_CONTAINER";//$NON-NLS-1$
70

71     private static final Object JavaDoc ON_SELECTED_AND_CHILDREN = "ON_SELECTED_AND_CHILDREN";//$NON-NLS-1$
72

73     private static final Object JavaDoc ON_SELECTED_ONLY = "ON_SELECTED_ONLY"; //$NON-NLS-1$
74

75     private static final Object JavaDoc PROBLEM_FILTER = "problemFilter";//$NON-NLS-1$
76

77     private static final String JavaDoc SCOPE = "scope"; //$NON-NLS-1$
78

79     private static final String JavaDoc SELECTED_TYPE = "selectedType"; //$NON-NLS-1$
80

81     private static final String JavaDoc SEVERITY = "severity";//$NON-NLS-1$
82

83     private static final String JavaDoc MARKER_TYPE_REFERENCE = "markerTypeReference"; //$NON-NLS-1$
84

85     private static final String JavaDoc MARKER_CATEGORY = "markerTypeCategory";//$NON-NLS-1$
86

87     private static final String JavaDoc ATTRIBUTE_MAPPING = "markerAttributeMapping"; //$NON-NLS-1$
88

89     private static final String JavaDoc MARKER_GROUPING = "markerGrouping"; //$NON-NLS-1$
90

91     private static final String JavaDoc ATTRIBUTE = "attribute"; //$NON-NLS-1$
92

93     private static final String JavaDoc VALUE = "value"; //$NON-NLS-1$
94

95     private static final String JavaDoc LABEL = "label"; //$NON-NLS-1$
96

97     private static final String JavaDoc MARKER_ATTRIBUTE_GROUPING = "markerAttributeGrouping";//$NON-NLS-1$
98

99     private static final String JavaDoc DEFAULT_GROUPING_ENTRY = "defaultGroupingEntry";//$NON-NLS-1$
100

101     private static final String JavaDoc MARKER_TYPE = "markerType";//$NON-NLS-1$
102

103     private static final String JavaDoc PRIORITY = "priority"; //$NON-NLS-1$
104

105     private static final String JavaDoc MARKER_GROUPING_ENTRY = "markerGroupingEntry"; //$NON-NLS-1$
106

107     private static final Object JavaDoc SEVERITY_ID = "org.eclipse.ui.ide.severity";//$NON-NLS-1$
108

109     private static MarkerSupportRegistry singleton;
110
111     // Create a lock so that initiization happens in one thread
112
private static Object JavaDoc creationLock = new Object JavaDoc();
113
114     /**
115      * Get the instance of the registry.
116      *
117      * @return MarkerSupportRegistry
118      */

119     public static MarkerSupportRegistry getInstance() {
120         if (singleton == null) {
121             synchronized (creationLock) {
122                 if (singleton == null) {
123                     // thread
124
singleton = new MarkerSupportRegistry();
125                 }
126             }
127         }
128         return singleton;
129     }
130
131     private Collection JavaDoc registeredFilters = new ArrayList JavaDoc();
132
133     private Map JavaDoc markerGroups = new HashMap JavaDoc();
134
135     private Map JavaDoc markerGroupingEntries = new HashMap JavaDoc();
136
137     private HashMap JavaDoc categories = new HashMap JavaDoc();
138
139     private HashMap JavaDoc hierarchyOrders = new HashMap JavaDoc();
140
141     private MarkerType rootType;
142
143     /**
144      * Create a new instance of the receiver and read the registry.
145      */

146     private MarkerSupportRegistry() {
147         IExtensionTracker tracker = PlatformUI.getWorkbench()
148                 .getExtensionTracker();
149         IExtensionPoint point = Platform.getExtensionRegistry()
150                 .getExtensionPoint(IDEWorkbenchPlugin.IDE_WORKBENCH,
151                         MARKER_SUPPORT);
152         if (point == null) {
153             return;
154         }
155         IExtension[] extensions = point.getExtensions();
156         // initial population
157
Map JavaDoc groupingEntries = new HashMap JavaDoc();
158         Set JavaDoc attributeMappings = new HashSet JavaDoc();
159         for (int i = 0; i < extensions.length; i++) {
160             IExtension extension = extensions[i];
161             processExtension(tracker, extension, groupingEntries,
162                     attributeMappings);
163         }
164         postProcessExtensions(groupingEntries, attributeMappings);
165         tracker.registerHandler(this, ExtensionTracker
166                 .createExtensionPointFilter(point));
167
168     }
169
170     /**
171      * Process the extension and register the result with the tracker. Fill the
172      * map of groupingEntries and attribueMappings processed for post
173      * processing.
174      *
175      * @param tracker
176      * @param extension
177      * @param groupingEntries
178      * Mapping of group names to the markerGroupingEntries registered
179      * for them
180      * @param attributeMappings
181      * the markerAttributeGroupings found
182      * @see #postProcessExtensions(Map, Collection)
183      */

184     private void processExtension(IExtensionTracker tracker,
185             IExtension extension, Map JavaDoc groupingEntries,
186             Collection JavaDoc attributeMappings) {
187         IConfigurationElement[] elements = extension.getConfigurationElements();
188
189         for (int j = 0; j < elements.length; j++) {
190             IConfigurationElement element = elements[j];
191             if (element.getName().equals(PROBLEM_FILTER)) {
192                 ProblemFilter filter = newFilter(element);
193                 registeredFilters.add(filter);
194                 tracker.registerObject(extension, filter,
195                         IExtensionTracker.REF_STRONG);
196
197                 continue;
198             }
199             if (element.getName().equals(MARKER_GROUPING)) {
200
201                 FieldMarkerGroup group = new FieldMarkerGroup(element
202                         .getAttribute(LABEL), element.getAttribute(ID));
203                 markerGroups.put(group.getId(), group);
204                 tracker.registerObject(extension, group,
205                         IExtensionTracker.REF_STRONG);
206             }
207
208             if (element.getName().equals(MARKER_GROUPING_ENTRY)) {
209
210                 MarkerGroupingEntry entry = new MarkerGroupingEntry(element
211                         .getAttribute(LABEL), element.getAttribute(ID),
212                         (Integer.valueOf(element.getAttribute(PRIORITY))
213                                 .intValue()));
214
215                 String JavaDoc groupName = element.getAttribute(MARKER_GROUPING);
216
217                 Collection JavaDoc entries;
218                 if (groupingEntries.containsKey(groupName)) {
219                     entries = (Collection JavaDoc) groupingEntries.get(groupName);
220                 } else {
221                     entries = new HashSet JavaDoc();
222                 }
223
224                 entries.add(entry);
225                 groupingEntries.put(groupName, entries);
226
227                 tracker.registerObject(extension, entry,
228                         IExtensionTracker.REF_STRONG);
229             }
230
231             if (element.getName().equals(MARKER_ATTRIBUTE_GROUPING)) {
232
233                 AttributeMarkerGrouping grouping = new AttributeMarkerGrouping(
234                         element.getAttribute(ATTRIBUTE), element
235                                 .getAttribute(MARKER_TYPE), element
236                                 .getAttribute(DEFAULT_GROUPING_ENTRY), element);
237
238                 attributeMappings.add(grouping);
239
240                 tracker.registerObject(extension, grouping,
241                         IExtensionTracker.REF_STRONG);
242             }
243
244             if (element.getName().equals(MARKER_CATEGORY)) {
245
246                 String JavaDoc[] markerTypes = getMarkerTypes(element);
247                 String JavaDoc categoryName = element.getAttribute(NAME);
248
249                 for (int i = 0; i < markerTypes.length; i++) {
250                     categories.put(markerTypes[i], categoryName);
251
252                 }
253                 tracker.registerObject(extension, categoryName,
254                         IExtensionTracker.REF_STRONG);
255             }
256
257         }
258     }
259
260     /**
261      * Process the cross references after all of the extensions have been read.
262      *
263      * @param groupingEntries
264      * @param attributeMappings
265      * @param groupingEntries
266      * Mapping of group names to the markerGroupingEntries registered
267      * for them
268      * @param attributeMappings
269      * the markerAttributeGroupings found
270      */

271     private void postProcessExtensions(Map JavaDoc groupingEntries,
272             Collection JavaDoc attributeMappings) {
273         processGroupingEntries(groupingEntries);
274         processAttributeMappings(attributeMappings);
275     }
276
277     /**
278      * Process the grouping entries into thier required grouping entries.
279      *
280      * @param groupingEntries
281      */

282     private void processGroupingEntries(Map JavaDoc groupingEntries) {
283         Iterator JavaDoc entriesIterator = groupingEntries.keySet().iterator();
284         while (entriesIterator.hasNext()) {
285             String JavaDoc nextGroupId = (String JavaDoc) entriesIterator.next();
286             Iterator JavaDoc nextEntriesIterator = ((Collection JavaDoc) groupingEntries
287                     .get(nextGroupId)).iterator();
288             if (markerGroups.containsKey(nextGroupId)) {
289                 while (nextEntriesIterator.hasNext()) {
290                     MarkerGroupingEntry next = (MarkerGroupingEntry) nextEntriesIterator
291                             .next();
292                     markerGroupingEntries.put(next.getId(), next);
293                     next.setGroupingEntry((FieldMarkerGroup) markerGroups
294                             .get(nextGroupId));
295
296                 }
297             } else {
298                 while (nextEntriesIterator.hasNext()) {
299                     MarkerGroupingEntry next = (MarkerGroupingEntry) nextEntriesIterator
300                             .next();
301                     IDEWorkbenchPlugin
302                             .log(NLS
303                                     .bind(
304                                             "markerGroupingEntry {0} defines invalid group {1}",//$NON-NLS-1$
305
new String JavaDoc[] { next.getId(),
306                                                     nextGroupId }));
307                 }
308             }
309         }
310     }
311
312     /**
313      * Process the attribute mappings into thier required grouping entries.
314      *
315      * @param attributeMappings
316      */

317     private void processAttributeMappings(Collection JavaDoc attributeMappings) {
318         Iterator JavaDoc mappingsIterator = attributeMappings.iterator();
319         while (mappingsIterator.hasNext()) {
320             AttributeMarkerGrouping next = (AttributeMarkerGrouping) mappingsIterator
321                     .next();
322             String JavaDoc defaultEntryId = next.getDefaultGroupingEntry();
323             if (defaultEntryId != null) {
324                 if (markerGroupingEntries.containsKey(defaultEntryId)) {
325                     MarkerGroupingEntry entry = (MarkerGroupingEntry) markerGroupingEntries
326                             .get(defaultEntryId);
327                     entry.setAsDefault(next.getMarkerType());
328                 } else {
329                     IDEWorkbenchPlugin.log(NLS.bind(
330                             "Reference to invalid markerGroupingEntry {0}",//$NON-NLS-1$
331
defaultEntryId));
332                 }
333             }
334             IConfigurationElement[] mappings = next.getElement().getChildren(
335                     ATTRIBUTE_MAPPING);
336
337             for (int i = 0; i < mappings.length; i++) {
338                 String JavaDoc entryId = mappings[i]
339                         .getAttribute(MARKER_GROUPING_ENTRY);
340
341                 if (markerGroupingEntries.containsKey(entryId)) {
342                     MarkerGroupingEntry entry = (MarkerGroupingEntry) markerGroupingEntries
343                             .get(entryId);
344                     entry.mapAttribute(next.getMarkerType(), next
345                             .getAttribute(), mappings[i].getAttribute(VALUE));
346                 } else {
347                     IDEWorkbenchPlugin.log(NLS.bind(
348                             "Reference to invaild markerGroupingEntry {0}", //$NON-NLS-1$
349
defaultEntryId));
350                 }
351
352             }
353         }
354
355     }
356
357     /**
358      * Get the markerTypes defined in element.
359      *
360      * @param element
361      * @return String[]
362      */

363     private String JavaDoc[] getMarkerTypes(IConfigurationElement element) {
364         IConfigurationElement[] types = element
365                 .getChildren(MARKER_TYPE_REFERENCE);
366         String JavaDoc[] ids = new String JavaDoc[types.length];
367         for (int i = 0; i < ids.length; i++) {
368             ids[i] = types[i].getAttribute(ID);
369         }
370         return ids;
371     }
372
373     /*
374      * (non-Javadoc)
375      *
376      * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamichelpers.IExtensionTracker,
377      * org.eclipse.core.runtime.IExtension)
378      */

379     public void addExtension(IExtensionTracker tracker, IExtension extension) {
380         Map JavaDoc groupingEntries = new HashMap JavaDoc();
381         Set JavaDoc attributeMappings = new HashSet JavaDoc();
382         processExtension(tracker, extension, groupingEntries, attributeMappings);
383         postProcessExtensions(groupingEntries, attributeMappings);
384     }
385
386     /**
387      * Get the collection of currently registered filters.
388      *
389      * @return Collection of ProblemFilter
390      */

391     public Collection JavaDoc getRegisteredFilters() {
392         Collection JavaDoc filteredFilters = new ArrayList JavaDoc();
393         Iterator JavaDoc registeredIterator = registeredFilters.iterator();
394         while (registeredIterator.hasNext()) {
395             ProblemFilter next = (ProblemFilter) registeredIterator.next();
396             if (next.isFilteredOutByActivity()) {
397                 continue;
398             }
399             filteredFilters.add(next);
400         }
401
402         return filteredFilters;
403     }
404
405     /**
406      * Get the constant for scope from element. Return -1 if there is no value.
407      *
408      * @param element
409      * @return int one of MarkerView#ON_ANY MarkerView#ON_SELECTED_ONLY
410      * MarkerView#ON_SELECTED_AND_CHILDREN
411      * MarkerView#ON_ANY_IN_SAME_CONTAINER
412      */

413     private int getScopeValue(IConfigurationElement element) {
414         String JavaDoc scope = element.getAttribute(SCOPE);
415         if (scope == null) {
416             return -1;
417         }
418         if (scope.equals(ON_ANY)) {
419             return MarkerFilter.ON_ANY;
420         }
421         if (scope.equals(ON_SELECTED_ONLY)) {
422             return MarkerFilter.ON_SELECTED_ONLY;
423         }
424         if (scope.equals(ON_SELECTED_AND_CHILDREN)) {
425             return MarkerFilter.ON_SELECTED_AND_CHILDREN;
426         }
427         if (scope.equals(ON_ANY_IN_SAME_CONTAINER)) {
428             return MarkerFilter.ON_ANY_IN_SAME_CONTAINER;
429         }
430
431         return -1;
432     }
433
434     /**
435      * Get the constant for scope from element. Return -1 if there is no value.
436      *
437      * @param element
438      * @return int one of MarkerView#ON_ANY MarkerView#ON_SELECTED_ONLY
439      * MarkerView#ON_SELECTED_AND_CHILDREN
440      * MarkerView#ON_ANY_IN_SAME_CONTAINER
441      */

442     private int getSeverityValue(IConfigurationElement element) {
443         String JavaDoc severity = element.getAttribute(SEVERITY);
444         if (severity == null) {
445             return -1;
446         }
447         if (severity.equals(INFO)) {
448             return ProblemFilter.SEVERITY_INFO;
449         }
450         if (severity.equals(WARNING)) {
451             return ProblemFilter.SEVERITY_WARNING;
452         }
453         if (severity.equals(ERROR)) {
454             return ProblemFilter.SEVERITY_ERROR;
455         }
456
457         return -1;
458     }
459
460     /**
461      * Read the problem filters in the receiver.
462      *
463      * @param element
464      * the filter element
465      * @return ProblemFilter
466      */

467     private ProblemFilter newFilter(IConfigurationElement element) {
468         ProblemFilter filter = new ProblemFilter(element.getAttribute(NAME));
469
470         filter.createContributionFrom(element);
471
472         String JavaDoc enabledValue = element.getAttribute(ENABLED);
473         filter.setEnabled(enabledValue == null
474                 || Boolean.valueOf(enabledValue).booleanValue());
475
476         int scopeValue = getScopeValue(element);
477         if (scopeValue >= 0) {
478             filter.setOnResource(scopeValue);
479         }
480
481         String JavaDoc description = element.getAttribute(DESCRIPTION);
482         if (description != null) {
483             boolean contains = true;
484             if (description.charAt(0) == '!') {// does not contain flag
485
description = description.substring(1, description.length());
486                 contains = false;
487             }
488             filter.setContains(contains);
489             filter.setDescription(description);
490         }
491
492         int severityValue = getSeverityValue(element);
493         if (severityValue > 0) {
494             filter.setSelectBySeverity(true);
495             filter.setSeverity(severityValue);
496         } else {
497             filter.setSelectBySeverity(false);
498         }
499
500         List JavaDoc selectedTypes = new ArrayList JavaDoc();
501         IConfigurationElement[] types = element.getChildren(SELECTED_TYPE);
502         for (int j = 0; j < types.length; j++) {
503             String JavaDoc markerId = types[j].getAttribute(MARKER_ID);
504             if (markerId != null) {
505                 MarkerType type = filter.getMarkerType(markerId);
506                 if (type == null) {
507                     IStatus status = new Status(IStatus.WARNING,
508                             IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.WARNING,
509                             MarkerMessages.ProblemFilterRegistry_nullType, null);
510                     IDEWorkbenchPlugin.getDefault().getLog().log(status);
511                 } else {
512                     selectedTypes.add(type);
513                 }
514             }
515         }
516
517         if (selectedTypes.size() > 0) {
518             // specified
519
filter.setSelectedTypes(selectedTypes);
520         }
521
522         return filter;
523
524     }
525
526     /*
527      * (non-Javadoc)
528      *
529      * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension,
530      * java.lang.Object[])
531      */

532     public void removeExtension(IExtension extension, Object JavaDoc[] objects) {
533
534         Collection JavaDoc removedGroups = new ArrayList JavaDoc();
535
536         for (int i = 0; i < objects.length; i++) {
537             if (objects[i] instanceof ProblemFilter) {
538                 registeredFilters.remove(objects[i]);
539             }
540
541             if (objects[i] instanceof FieldMarkerGroup) {
542                 markerGroups.remove(((FieldMarkerGroup) objects[i]).getId());
543                 removedGroups.add(objects[i]);
544             }
545
546             if (objects[i] instanceof MarkerGroupingEntry) {
547                 MarkerGroupingEntry entry = (MarkerGroupingEntry) objects[i];
548                 entry.getMarkerGroup().remove(entry);
549                 markerGroupingEntries.remove(entry.getId());
550             }
551
552             if (objects[i] instanceof String JavaDoc) {
553                 removeValues(objects[i], categories);
554             }
555
556         }
557
558         Iterator JavaDoc entriesIterator = markerGroupingEntries.keySet().iterator();
559         Collection JavaDoc removedKeys = new ArrayList JavaDoc();
560         while (entriesIterator.hasNext()) {
561             String JavaDoc entryId = (String JavaDoc) entriesIterator.next();
562             MarkerGroupingEntry entry = (MarkerGroupingEntry) markerGroupingEntries
563                     .get(entryId);
564             if (removedGroups.contains(entry.getMarkerGroup())) {
565                 removedKeys.add(entryId);
566             }
567         }
568
569         Iterator JavaDoc removedIterator = removedKeys.iterator();
570         while (removedIterator.hasNext()) {
571             markerGroupingEntries.remove(removedIterator.next());
572         }
573
574     }
575
576     /**
577      * Remove the value from all of the collection sets in cache. If the
578      * collection is empty remove the key as well.
579      *
580      * @param value
581      * @param cache
582      */

583     private void removeValues(Object JavaDoc value, HashMap JavaDoc cache) {
584         Collection JavaDoc keysToRemove = new ArrayList JavaDoc();
585         Iterator JavaDoc keys = cache.keySet().iterator();
586         while (keys.hasNext()) {
587             String JavaDoc key = (String JavaDoc) keys.next();
588             Object JavaDoc next = cache.get(key);
589             if (next instanceof Collection JavaDoc) {
590                 Collection JavaDoc collection = (Collection JavaDoc) next;
591                 if (collection.contains(value)) {
592                     collection.remove(value);
593                     if (collection.isEmpty()) {
594                         keysToRemove.add(key);
595                     }
596                     break;
597                 }
598             } else {
599                 if (cache.get(key).equals(value)) {
600                     keysToRemove.add(key);
601                 }
602             }
603         }
604         Iterator JavaDoc keysToRemoveIterator = keysToRemove.iterator();
605         while (keysToRemoveIterator.hasNext()) {
606             cache.remove(keysToRemoveIterator.next());
607         }
608     }
609
610     /**
611      * Get the category associated with marker. Return <code>null</code> if
612      * there are none.
613      *
614      * @param marker
615      * @return String or <code>null</code>
616      */

617     public String JavaDoc getCategory(IMarker marker) {
618         try {
619             return getCategory(marker.getType());
620         } catch (CoreException e) {
621             Util.log(e);
622         }
623         return null;
624     }
625
626     /**
627      * Get the category associated with markerType. Return <code>null</code>
628      * if there are none.
629      *
630      * @param markerType
631      * @return String or <code>null</code>
632      */

633     public String JavaDoc getCategory(String JavaDoc markerType) {
634         if (categories.containsKey(markerType)) {
635             return (String JavaDoc) categories.get(markerType);
636         }
637         return null;
638     }
639
640     /**
641      * Return the TableSorter that corresponds to type.
642      *
643      * @param type
644      * @return TableSorter
645      */

646     public TableComparator getSorterFor(String JavaDoc type) {
647         if (hierarchyOrders.containsKey(type)) {
648             return (TableComparator) hierarchyOrders.get(type);
649         }
650
651         TableComparator sorter = findSorterInChildren(type, getRootType());
652         if (sorter == null) {
653             return new TableComparator(new IField[0], new int[0], new int[0]);
654         }
655         return sorter;
656     }
657
658     /**
659      * Return the list of root marker types.
660      *
661      * @return List of MarkerType.
662      */

663     private MarkerType getRootType() {
664         if (rootType == null) {
665             rootType = (MarkerTypesModel.getInstance())
666                     .getType(IMarker.PROBLEM);
667         }
668         return rootType;
669     }
670
671     /**
672      * Find the best match sorter for typeName in the children. If it cannot be
673      * found then return <code>null</code>.
674      *
675      * @param typeName
676      * @param type
677      * @return TableSorter or <code>null</code>.
678      */

679     private TableComparator findSorterInChildren(String JavaDoc typeName, MarkerType type) {
680
681         MarkerType[] types = type.getAllSubTypes();
682         TableComparator defaultSorter = null;
683         if (hierarchyOrders.containsKey(type.getId())) {
684             defaultSorter = (TableComparator) hierarchyOrders.get(type.getId());
685         }
686
687         for (int i = 0; i < types.length; i++) {
688             MarkerType[] subtypes = types[i].getAllSubTypes();
689             for (int j = 0; j < subtypes.length; j++) {
690                 TableComparator sorter = findSorterInChildren(typeName, subtypes[j]);
691                 if (sorter != null) {
692                     return sorter;
693                 }
694             }
695         }
696         return defaultSorter;
697
698     }
699
700     /**
701      * Return the FieldMarkerGroups in the receiver.
702      *
703      * @return Collection of FieldMarkerGroup
704      */

705     public Collection JavaDoc getMarkerGroups() {
706         return markerGroups.values();
707     }
708
709     /**
710      * Return the default group.
711      *
712      * @return IField
713      */

714     public IField getDefaultGroup() {
715
716         return (IField) markerGroups.get(SEVERITY_ID);
717     }
718
719 }
720
Popular Tags