1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 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 28 class MarkerTypesModel { 29 30 34 static MarkerTypesModel getInstance(){ 35 if(instance == null) { 36 instance = new MarkerTypesModel(); 37 } 38 return instance; 39 } 40 41 static MarkerTypesModel instance; 42 43 46 private HashMap types; 47 48 51 private MarkerTypesModel() { 52 types = readTypes(); 53 } 54 55 59 public MarkerType getType(String id) { 60 return (MarkerType) types.get(id); 61 } 62 63 66 public MarkerType[] getTypes() { 67 MarkerType[] result = new MarkerType[types.size()]; 68 types.values().toArray(result); 69 return result; 70 } 71 72 76 private String getWellKnownLabel(String type) { 77 if (type.equals(IMarker.PROBLEM)) { 78 return "Problem"; } 80 if (type.equals(IMarker.TASK)) { 81 return "Task"; } 83 if (type.equals("org.eclipse.jdt.core.problem")) { return "Java Problem"; } 86 return type; 87 } 88 89 92 private HashMap readTypes() { 93 HashMap types = new HashMap (); 94 95 IExtensionPoint point = Platform.getExtensionRegistry() 96 .getExtensionPoint(ResourcesPlugin.PI_RESOURCES, 97 ResourcesPlugin.PT_MARKERS); 98 if (point != null) { 99 IExtension[] extensions = point.getExtensions(); 101 for (int i = 0; i < extensions.length; ++i) { 102 IExtension ext = extensions[i]; 103 String id = ext.getUniqueIdentifier(); 104 String label = ext.getLabel(); 105 if (label.equals("")) { label = getWellKnownLabel(id); 107 } 108 ArrayList supersList = new ArrayList (); 109 IConfigurationElement[] configElements = ext 110 .getConfigurationElements(); 111 for (int j = 0; j < configElements.length; ++j) { 112 IConfigurationElement elt = configElements[j]; 113 if (elt.getName().equalsIgnoreCase("super")) { String sup = elt.getAttribute("type"); if (sup != null) { 116 supersList.add(sup); 117 } 118 } 119 } 120 String [] superTypes = new String [supersList.size()]; 121 supersList.toArray(superTypes); 122 MarkerType type = new MarkerType(this, id, label, superTypes); 123 types.put(id, type); 124 } 125 } 126 return types; 127 } 128 } 129 | Popular Tags |