KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > tasklist > MarkerTypesModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.ui.views.tasklist;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.IConfigurationElement;
20 import org.eclipse.core.runtime.IExtension;
21 import org.eclipse.core.runtime.IExtensionPoint;
22 import org.eclipse.core.runtime.Platform;
23
24 /**
25  * Maintains a model of all known marker types.
26  */

27 class MarkerTypesModel {
28     /**
29      * Maps from marker type id to MarkerType.
30      */

31     private HashMap JavaDoc types;
32
33     /**
34      * Creates a new marker types model.
35      */

36     public MarkerTypesModel() {
37         types = readTypes();
38     }
39
40     /**
41      * Returns the marker type with the given id, or <code>null</code> if there is no such marker type.
42      */

43     public MarkerType getType(String JavaDoc id) {
44         return (MarkerType) types.get(id);
45     }
46
47     /**
48      * Returns all known marker types.
49      */

50     public MarkerType[] getTypes() {
51         MarkerType[] result = new MarkerType[types.size()];
52         types.values().toArray(result);
53         return result;
54     }
55
56     /**
57      * Returns the label for the given marker type.
58      * Workaround until we have labels in XML.
59      */

60     private String JavaDoc getWellKnownLabel(String JavaDoc type) {
61         if (type.equals(IMarker.PROBLEM)) {
62             return "Problem";//$NON-NLS-1$
63
}
64         if (type.equals(IMarker.TASK)) {
65             return "Task";//$NON-NLS-1$
66
}
67         if (type.equals("org.eclipse.jdt.core.problem")) { //$NON-NLS-1$
68
return "Java Problem";//$NON-NLS-1$
69
}
70         return type;
71     }
72
73     /**
74      * Reads the marker types from the registry.
75      */

76     private HashMap JavaDoc readTypes() {
77         HashMap JavaDoc types = new HashMap JavaDoc();
78         IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(
79                 ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_MARKERS);
80         if (point != null) {
81             // Gather all registered marker types.
82
IExtension[] extensions = point.getExtensions();
83             for (int i = 0; i < extensions.length; ++i) {
84                 IExtension ext = extensions[i];
85                 String JavaDoc id = ext.getUniqueIdentifier();
86                 String JavaDoc label = ext.getLabel();
87                 if (label.equals("")) {//$NON-NLS-1$
88
label = getWellKnownLabel(id);
89                 }
90                 ArrayList JavaDoc supersList = new ArrayList JavaDoc();
91                 IConfigurationElement[] configElements = ext
92                         .getConfigurationElements();
93                 for (int j = 0; j < configElements.length; ++j) {
94                     IConfigurationElement elt = configElements[j];
95                     if (elt.getName().equalsIgnoreCase("super")) {//$NON-NLS-1$
96
String JavaDoc sup = elt.getAttribute("type");//$NON-NLS-1$
97
if (sup != null) {
98                             supersList.add(sup);
99                         }
100                     }
101                 }
102                 String JavaDoc[] superTypes = new String JavaDoc[supersList.size()];
103                 supersList.toArray(superTypes);
104                 MarkerType type = new MarkerType(this, id, label, superTypes);
105                 types.put(id, type);
106             }
107         }
108         return types;
109     }
110 }
111
Popular Tags