### Eclipse Workspace Patch 1.0
#P org.eclipse.ui.ide
Index: src/org/eclipse/ui/views/markers/internal/MarkerGroupingEntry.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/MarkerGroupingEntry.java,v
retrieving revision 1.6
diff -u -r1.6 MarkerGroupingEntry.java
--- src/org/eclipse/ui/views/markers/internal/MarkerGroupingEntry.java 24 Mar 2008 19:13:34 -0000 1.6
+++ src/org/eclipse/ui/views/markers/internal/MarkerGroupingEntry.java 2 Feb 2009 13:43:27 -0000
@@ -11,7 +11,13 @@
package org.eclipse.ui.views.markers.internal;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.internal.views.markers.MarkerSupportInternalUtilities;
/**
@@ -24,11 +30,12 @@
public class MarkerGroupingEntry {
private static final String PRIORITY = "priority"; //$NON-NLS-1$
-
+
private MarkerGroup markerGroup;
private String label;
private String id;
private int sortPriority;
+ private ImageDescriptor imageDescriptor;
/**
* Create a new instance of the receiver from element.
@@ -39,6 +46,13 @@
id = element.getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ID);
sortPriority = Integer.valueOf(element.getAttribute(PRIORITY))
.intValue();
+ String imagePath = element
+ .getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ICON);
+ if (imagePath != null) {
+ URL url = FileLocator.find(Platform.getBundle(element
+ .getContributor().getName()), new Path(imagePath), null);
+ imageDescriptor = ImageDescriptor.createFromURL(url);
+ }
}
/**
@@ -107,4 +121,12 @@
return markerGroup;
}
+ /**
+ * Returns the icon for the receiver.
+ *
+ * @return ImageDescriptor
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return imageDescriptor;
+ }
}
Index: src/org/eclipse/ui/views/markers/internal/TypeMarkerGroup.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/TypeMarkerGroup.java,v
retrieving revision 1.9
diff -u -r1.9 TypeMarkerGroup.java
--- src/org/eclipse/ui/views/markers/internal/TypeMarkerGroup.java 24 Mar 2008 19:13:34 -0000 1.9
+++ src/org/eclipse/ui/views/markers/internal/TypeMarkerGroup.java 2 Feb 2009 13:43:27 -0000
@@ -11,8 +11,13 @@
package org.eclipse.ui.views.markers.internal;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.Policy;
import org.eclipse.ui.views.markers.MarkerItem;
@@ -25,6 +30,7 @@
*/
public class TypeMarkerGroup extends MarkerGroup {
+ private Map entries=new HashMap();
/**
* TypeMarkerField is the MarkerField used for MarkerGroupungs
*
@@ -102,6 +108,33 @@
markerField = new TypeMarkerField();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.views.markers.internal.MarkerGroup#findGroupValue(java
+ * .lang.String, org.eclipse.core.resources.IMarker)
+ */
+ public MarkerGroupingEntry findGroupValue(String typeId, IMarker marker) {
+ TypesMarkerGroupingEntry entry = (TypesMarkerGroupingEntry) entries
+ .get(typeId);
+ if (entry == null) {
+ String groupName = MarkerSupportRegistry.getInstance().getCategory(
+ marker);
+ if (groupName == null) {
+ MarkerType mkType = MarkerTypesModel.getInstance().getType(
+ typeId);
+ groupName = mkType.getLabel();
+ }
+ entry = new TypesMarkerGroupingEntry(groupName, null);
+ entry.setGroup(this);
+ entries.put(typeId, entry);
+ }
+ // update the icon
+ entry.setImageDescriptor(IDEWorkbenchPlugin.getDefault()
+ .getMarkerImageProviderRegistry().getImageDescriptor(marker));
+ return entry;
+ }
/* (non-Javadoc)
* @see org.eclipse.ui.views.markers.internal.MarkerGroup#getId()
*/
@@ -116,4 +149,26 @@
return name;
}
+ private class TypesMarkerGroupingEntry extends MarkerGroupingEntry {
+ private ImageDescriptor imageDescriptor;
+
+ public TypesMarkerGroupingEntry(String label,
+ ImageDescriptor imageDescriptor) {
+ super(label);
+ this.imageDescriptor = imageDescriptor;
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.views.markers.internal.MarkerGroupingEntry#
+ * getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return imageDescriptor;
+ }
+
+ void setImageDescriptor(ImageDescriptor imageDescriptor) {
+ this.imageDescriptor = imageDescriptor;
+ }
+ }
}
Index: src/org/eclipse/ui/internal/views/markers/MarkerEntry.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java,v
retrieving revision 1.13
diff -u -r1.13 MarkerEntry.java
--- src/org/eclipse/ui/internal/views/markers/MarkerEntry.java 8 Dec 2008 19:11:53 -0000 1.13
+++ src/org/eclipse/ui/internal/views/markers/MarkerEntry.java 2 Feb 2009 13:43:27 -0000
@@ -18,7 +18,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.Policy;
import org.eclipse.ui.views.markers.MarkerViewUtil;
import org.eclipse.ui.views.markers.internal.MarkerMessages;
@@ -359,4 +361,13 @@
collationKeys = null;
attributeCache.clear();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.views.markers.MarkerItem#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ if(marker!=null){
+ return IDEWorkbenchPlugin.getDefault().getMarkerImageProviderRegistry().getImageDescriptor(marker);
+ }
+ return super.getImageDescriptor();
+ }
}
Index: src/org/eclipse/ui/internal/views/markers/MarkerSeverityAndDescriptionField.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerSeverityAndDescriptionField.java,v
retrieving revision 1.4
diff -u -r1.4 MarkerSeverityAndDescriptionField.java
--- src/org/eclipse/ui/internal/views/markers/MarkerSeverityAndDescriptionField.java 11 Mar 2008 15:29:23 -0000 1.4
+++ src/org/eclipse/ui/internal/views/markers/MarkerSeverityAndDescriptionField.java 2 Feb 2009 13:43:27 -0000
@@ -11,7 +11,7 @@
package org.eclipse.ui.internal.views.markers;
-import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.markers.MarkerItem;
@@ -53,15 +53,10 @@
* @return Image or null
*/
private Image getImage(MarkerItem item) {
-
- int severity = -1;
- if (item.getMarker() == null)
- severity = ((MarkerCategory) item).getHighestSeverity();
- else
- severity = MarkerSupportInternalUtilities.getSeverity(item);
-
- if (severity >= IMarker.SEVERITY_WARNING)
- return MarkerSupportInternalUtilities.getSeverityImage(severity);
+ ImageDescriptor descriptor=item.getImageDescriptor();
+ if(descriptor!=null){
+ return getImageManager().createImage(descriptor);
+ }
return null;
}
Index: src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java,v
retrieving revision 1.23
diff -u -r1.23 CachedMarkerBuilder.java
--- src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java 8 Dec 2008 19:11:53 -0000 1.23
+++ src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java 2 Feb 2009 13:43:26 -0000
@@ -39,6 +39,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.IMemento;
@@ -275,6 +276,17 @@
if (previous != null) {
// Are we at a category boundary?
if (sorter.compareCategory(previous, elements[i]) != 0) {
+ MarkerEntry entry=markers.elementAt(categoryStart);
+ IMarker marker=entry.getMarker();
+ ImageDescriptor imgDesc=null;
+ if(marker!=null){
+ try{
+ String typeID=marker.getType();
+ imgDesc=getCategoryGroup().findGroupValue(typeID, marker).getImageDescriptor();
+ }catch(CoreException e){
+ Policy.handle(e);
+ }
+ }
categories
.add(new MarkerCategory(
this,
@@ -284,7 +296,7 @@
.getMarkerField()
.getValue(
markers
- .elementAt(categoryStart))));
+ .elementAt(categoryStart)),imgDesc));
categoryStart = i;
}
}
@@ -293,9 +305,19 @@
}
if (end >= categoryStart) {
+ MarkerEntry entry=markers.elementAt(categoryStart);
+ IMarker marker=entry.getMarker();
+ ImageDescriptor imgDesc=null;
+ if(marker!=null){
+ try{
+ String typeID=marker.getType();
+ imgDesc=getCategoryGroup().findGroupValue(typeID, marker).getImageDescriptor();
+ }catch(CoreException e){
+ Policy.handle(e);
+ }
+ }
categories.add(new MarkerCategory(this, categoryStart, end,
- getCategoryGroup().getMarkerField().getValue(
- markers.elementAt(categoryStart))));
+ getCategoryGroup().getMarkerField().getValue(entry),imgDesc));
}
MarkerCategory[] nodes = new MarkerCategory[categories.size()];
Index: src/org/eclipse/ui/internal/views/markers/MarkerCategory.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerCategory.java,v
retrieving revision 1.4
diff -u -r1.4 MarkerCategory.java
--- src/org/eclipse/ui/internal/views/markers/MarkerCategory.java 24 Mar 2008 19:13:33 -0000 1.4
+++ src/org/eclipse/ui/internal/views/markers/MarkerCategory.java 2 Feb 2009 13:43:26 -0000
@@ -12,6 +12,7 @@
package org.eclipse.ui.internal.views.markers;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.views.markers.MarkerItem;
import org.eclipse.ui.views.markers.internal.MarkerMessages;
@@ -29,6 +30,8 @@
private CachedMarkerBuilder cachedMarkerBuilder;
private int severity = -1;
+
+ private ImageDescriptor imageDescriptor;
/**
* Create a new instance of the receiver that has the markers between
@@ -46,7 +49,24 @@
end = endIndex;
name = categoryName;
}
+ /**
+ * Create a new instance of the receiver that has the markers between
+ * startIndex and endIndex showing.
+ *
+ * @param cachedMarkerBuilder
+ * @param startIndex
+ * @param endIndex
+ * @param imageDescriptor
+ * the builder used to generate the children lazily.
+ *
+ */
+ MarkerCategory(CachedMarkerBuilder cachedMarkerBuilder, int startIndex,
+ int endIndex, String categoryName,ImageDescriptor imageDescriptor) {
+ this(cachedMarkerBuilder, startIndex, endIndex, categoryName);
+ this.imageDescriptor=imageDescriptor;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getChildren()
*/
@@ -154,4 +174,10 @@
return false;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.internal.views.markers.MarkerItem#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return imageDescriptor;
+ }
}
Index: src/org/eclipse/ui/views/markers/MarkerItem.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/MarkerItem.java,v
retrieving revision 1.6
diff -u -r1.6 MarkerItem.java
--- src/org/eclipse/ui/views/markers/MarkerItem.java 2 May 2008 19:37:07 -0000 1.6
+++ src/org/eclipse/ui/views/markers/MarkerItem.java 2 Feb 2009 13:43:27 -0000
@@ -13,6 +13,7 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.internal.views.markers.MarkerSupportInternalUtilities;
/**
@@ -101,4 +102,13 @@
public IMarker getMarker() {
return null;
}
+
+ /**
+ * Returns the image for receiver's marker.
+ *
+ * @return ImageDescriptor
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
}
Index: plugin.xml
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.xml,v
retrieving revision 1.283
diff -u -r1.283 plugin.xml
--- plugin.xml 19 Jan 2009 14:35:31 -0000 1.283
+++ plugin.xml 2 Feb 2009 13:43:24 -0000
@@ -1419,11 +1419,13 @@
-
+
-
+
The Marker Support extension point defines extensions to the workbench tools that show markers such as the problems, bookmarks and tasks views.
+
+
+
+
+
@@ -34,9 +39,9 @@
-
+
-
+
@@ -143,9 +148,9 @@
The id of a marker that is enabled by default.
-
+
-
+
@@ -166,9 +171,9 @@
The label is the human readable name that will be presented to the user.
-
+
-
+
@@ -186,9 +191,9 @@
The id of the markerType
-
+
-
+
@@ -213,9 +218,9 @@
The id of the markerType this grouping applies to.
-
+
-
+
@@ -259,9 +264,9 @@
The label is the human readable String that will be used to create the entry in the Group By-> menu for this marker grouping.
-
+
-
+
@@ -328,9 +333,9 @@
The translable label of the entry.
-
+
-
+
@@ -340,6 +345,17 @@
+
+
+
+ Specified with a plug-in relative path, the icon for the grouping entry.
+ <em>Since: 3.5</em>
+
+
+
+
+
+
@@ -370,9 +386,9 @@
The name attribute is the human readable name of the content generator.
-
+
-
+
@@ -404,9 +420,9 @@
The class is the type used to instantiate the field.
-
+
-
+
@@ -421,9 +437,9 @@
The icon is the plug-in relative path for the icon.
-
+
-
+
@@ -431,9 +447,9 @@
The filterClass is the class that does filtering on this field when enabled. If this is not specified no filtering will occur based on this field.
-
+
-
+
@@ -441,9 +457,9 @@
The filterConfigurationClass is an optional area that is used for configuration of the field in a filter dialog.
-
+
-
+
@@ -461,9 +477,9 @@
The id is the id of the markerField being referred to.
-
+
-
+
@@ -495,9 +511,9 @@
The human readable name of the grouping.
-
+
-
+
@@ -505,9 +521,9 @@
The values is a class that specifies the values that are to be set in the filterClass of a markerField for the enclosing markerContentGenerator.
-
+
-
+
@@ -568,27 +584,27 @@
The id of the generator being extended
-
+
-
+
-
+
-
+
3.2
-
+
-
+
The following is an example of a problem filter definition in the marker support. This example only shows java warnings on the selected element and it's children and filters out those with the String NON-NLS
<p>
@@ -613,18 +629,18 @@
-
+
-
+
The severity markerGrouping is provided in the org.eclipse.ui.ide plug-in by default.
-
+
-
+
Copyright (c) 2005, 2007 IBM Corporation and others.<br>
All rights reserved. This program and the accompanying materials are made
Index: src/org/eclipse/ui/internal/ide/registry/MarkerImageProviderRegistry.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerImageProviderRegistry.java,v
retrieving revision 1.17
diff -u -r1.17 MarkerImageProviderRegistry.java
--- src/org/eclipse/ui/internal/ide/registry/MarkerImageProviderRegistry.java 24 Mar 2008 19:13:35 -0000 1.17
+++ src/org/eclipse/ui/internal/ide/registry/MarkerImageProviderRegistry.java 2 Feb 2009 13:43:26 -0000
@@ -11,10 +11,18 @@
package org.eclipse.ui.internal.ide.registry;
import java.net.URL;
-import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
@@ -22,145 +30,242 @@
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.IMarkerImageProvider;
import org.eclipse.ui.internal.ide.Policy;
+import org.eclipse.ui.views.markers.internal.MarkerType;
+import org.eclipse.ui.views.markers.internal.MarkerTypesModel;
import org.osgi.framework.Bundle;
/**
- * Implementation of a marker image registry which maps either
- * a marker type to a provider or to a static image.
+ * Implementation of a marker image registry which maps either a marker type to
+ * a provider or to a static image.
*/
public class MarkerImageProviderRegistry {
- private static final String ATT_PROVIDER_CLASS = "class";//$NON-NLS-1$
+ private static final String ATT_PROVIDER_CLASS = "class";//$NON-NLS-1$
- private static final String ATT_ICON = "icon";//$NON-NLS-1$
+ private static final String ATT_ICON = "icon";//$NON-NLS-1$
- private static final String ATT_MARKER_TYPE = "markertype";//$NON-NLS-1$
+ private static final String ATT_MARKER_TYPE = "markertype";//$NON-NLS-1$
- private static final String ATT_ID = "id";//$NON-NLS-1$
+ private static final String ATT_ID = "id";//$NON-NLS-1$
- private static final String MARKER_ATT_KEY = "org.eclipse.ui.internal.registry.MarkerImageProviderRegistry";//$NON-NLS-1$
-
- private static final String TAG_PROVIDER = "imageprovider";//$NON-NLS-1$
-
- private ArrayList descriptors = new ArrayList();
-
- class Descriptor {
- String id;
-
- String markerType;
-
- String className;
-
- String imagePath;
-
- ImageDescriptor imageDescriptor;
-
- IConfigurationElement element;
-
- Bundle pluginBundle;
-
- IMarkerImageProvider provider;
- }
-
- /**
- * Initialize this new MarkerImageProviderRegistry.
- */
- public MarkerImageProviderRegistry() {
- class MarkerImageReader extends IDERegistryReader {
- protected boolean readElement(IConfigurationElement element) {
- if (element.getName().equals(TAG_PROVIDER)) {
- addProvider(element);
- return true;
- }
-
- return false;
- }
-
- public void readRegistry() {
- readRegistry(Platform.getExtensionRegistry(),
- IDEWorkbenchPlugin.IDE_WORKBENCH,
- IDEWorkbenchPlugin.PL_MARKER_IMAGE_PROVIDER);
- }
- }
-
- new MarkerImageReader().readRegistry();
- }
-
- /**
- * Creates a descriptor for the marker provider extension
- * and add it to the list of providers.
- */
- public void addProvider(IConfigurationElement element) {
- Descriptor desc = new Descriptor();
- desc.element = element;
- desc.pluginBundle = Platform.getBundle(element.getNamespace());
- desc.id = element.getAttribute(ATT_ID);
- desc.markerType = element.getAttribute(ATT_MARKER_TYPE);
- desc.imagePath = element.getAttribute(ATT_ICON);
- desc.className = element.getAttribute(ATT_PROVIDER_CLASS);
- if (desc.imagePath != null) {
- desc.imageDescriptor = getImageDescriptor(desc);
- }
- if (desc.className == null) {
- //Don't need to keep these references.
- desc.element = null;
- desc.pluginBundle = null;
- }
- descriptors.add(desc);
- }
-
- /**
- * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(Object)
- */
- public ImageDescriptor getImageDescriptor(IMarker marker) {
- int size = descriptors.size();
- for (int i = 0; i < size; i++) {
- Descriptor desc = (Descriptor) descriptors.get(i);
- try {
- if (marker.isSubtypeOf(desc.markerType)) {
- if (desc.className != null) {
- if (desc.pluginBundle.getState()==Bundle.ACTIVE) {
- //-- Get the image descriptor from the provider.
- //-- Save the image descriptor url as a persistable property, so a
- //image descriptor can be created without activating the plugin next
- //time the workbench is started.
- if (desc.provider == null) {
- desc.provider = (IMarkerImageProvider) IDEWorkbenchPlugin
- .createExtension(desc.element,
- ATT_PROVIDER_CLASS);
- }
- String path = desc.provider.getImagePath(marker);
- if (path != desc.imagePath) {
- desc.imagePath = path;
- desc.imageDescriptor = getImageDescriptor(desc);
- return desc.imageDescriptor;
- }
- return desc.imageDescriptor;
- } else {
- if (desc.imageDescriptor == null) {
- //Create a image descriptor to be used until the plugin gets activated.
- desc.imagePath = (String) marker
- .getAttribute(MARKER_ATT_KEY);
- desc.imageDescriptor = getImageDescriptor(desc);
- }
- return desc.imageDescriptor;
- }
- } else if (desc.imageDescriptor != null) {
- return desc.imageDescriptor;
- }
- }
- } catch (CoreException e) {
- Policy.handle(e);
- return null;
- }
- }
- return null;
- }
-
- /**
- * Returns the image descriptor with the given relative path.
- */
- ImageDescriptor getImageDescriptor(Descriptor desc) {
- URL url = Platform.find(desc.pluginBundle, new Path(desc.imagePath));
- return ImageDescriptor.createFromURL(url);
- }
+ //private static final String MARKER_ATT_KEY = "org.eclipse.ui.internal.registry.MarkerImageProviderRegistry";//$NON-NLS-1$
+
+ private static final String TAG_PROVIDER = "imageprovider";//$NON-NLS-1$
+
+ private SortedMap descriptors = new TreeMap();
+
+ private Map typesMap = new HashMap();
+
+ class Descriptor {
+ String id;
+
+ String markerType;
+
+ String className;
+
+ String imagePath;
+
+ ImageDescriptor imageDescriptor;
+
+ IConfigurationElement element;
+
+ Bundle pluginBundle;
+
+ IMarkerImageProvider provider;
+
+ }
+
+ /**
+ * Initialize this new MarkerImageProviderRegistry.
+ */
+ public MarkerImageProviderRegistry() {
+ class MarkerImageReader extends IDERegistryReader {
+ protected boolean readElement(IConfigurationElement element) {
+ if (element.getName().equals(TAG_PROVIDER)) {
+ addProvider(element, false);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void readRegistry() {
+ readRegistry(Platform.getExtensionRegistry(),
+ IDEWorkbenchPlugin.IDE_WORKBENCH,
+ IDEWorkbenchPlugin.PL_MARKER_IMAGE_PROVIDER);
+ }
+ }
+
+ new MarkerImageReader().readRegistry();
+ }
+
+ /**
+ * Creates a descriptor for the marker provider extension and add it to the
+ * list of providers.
+ * @param element
+ */
+ public void addProvider(IConfigurationElement element) {
+ addProvider(element, true);
+ }
+
+ /**
+ * Creates a descriptor for the marker provider extension and add it to the
+ * list of providers.
+ *
+ * @param element
+ * @param updateTypesMap
+ * true checks to see if the new provider is a better
+ * alternative for another marker type and updates
+ * the internal map accordingly
+ */
+ private void addProvider(IConfigurationElement element,
+ boolean updateTypesMap) {
+ Descriptor desc = new Descriptor();
+ desc.element = element;
+ desc.pluginBundle = Platform.getBundle(element.getContributor().getName());
+ desc.id = element.getAttribute(ATT_ID);
+ desc.markerType = element.getAttribute(ATT_MARKER_TYPE);
+ desc.imagePath = element.getAttribute(ATT_ICON);
+ desc.className = element.getAttribute(ATT_PROVIDER_CLASS);
+ if (desc.imagePath != null) {
+ desc.imageDescriptor = getImageDescriptor(desc);
+ }
+ if (desc.className == null) {
+ // Don't need to keep these references.
+ desc.element = null;
+ desc.pluginBundle = null;
+ }
+ descriptors.put(desc.markerType, desc);
+ typesMap.put(desc.markerType, desc);
+ if (updateTypesMap) {
+ // only check marker types not declaring an imageprovider extension
+ Set keys = new HashSet(typesMap.keySet());
+ keys.removeAll(descriptors.keySet());
+ Iterator iterator = keys.iterator();
+ // check to see if the addition is a better alternative for another
+ // marker type
+ while (iterator.hasNext()) {
+ String mkId = (String) iterator.next();
+ MarkerType type = MarkerTypesModel.getInstance().getType(mkId);
+ MarkerType otherType = MarkerTypesModel.getInstance().getType(
+ desc.markerType);
+ // check super
+ if (type.isSubtypeOf(otherType)) {
+ Descriptor oldDesc = (Descriptor) typesMap.get(mkId);
+ MarkerType oldSuper = MarkerTypesModel.getInstance()
+ .getType(oldDesc.markerType);
+ // check if the new one is closer to the type in hierarchy
+ // than the old one
+ if (otherType.isSubtypeOf(oldSuper)) {
+ typesMap.put(mkId, desc);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the ImageDescriptor for the given marker by querying the
+ * markerImageProvider extension declared for its type.If a
+ * markerImageProvider is not directly declared for a type, then a provider
+ * declared for one of its super type is used. Returns the image specified
+ * by the IMarkerImageProvider class or the static image declared in the
+ * extension. A null is returned for types not having a markerImageProvider.
+ *
+ * @param marker
+ * @return ImageDescriptor
+ * @see org.eclipse.ui.internal.ide.IMarkerImageProvider
+ * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(Object)
+ */
+ public ImageDescriptor getImageDescriptor(IMarker marker) {
+ String typeId = null;
+ try {
+ typeId = marker.getType();
+ } catch (CoreException e1) {
+ Policy.handle(e1);
+ return null;
+ }
+ Descriptor descriptor = getDescriptorFor(typeId);
+ if (descriptor == null) {
+ return null;
+ }
+ if (descriptor.className == null) {
+ return descriptor.imageDescriptor;
+ }
+ try {
+ // TODO: Decide whether to activate contributing bundle or not
+ // Note: plugin activation should be expected by the client
+ // if a class is specified.The marker's image may be expected
+ // to be different based on attributes.
+
+ /*String persistedPath = (String) marker.getAttribute(MARKER_ATT_KEY);
+ if (descriptor.pluginBundle.getState() == Bundle.ACTIVE
+ || (persistedPath == null && descriptor.imageDescriptor == null)) {*/
+
+ if (descriptor.provider == null) {
+ descriptor.provider = (IMarkerImageProvider) IDEWorkbenchPlugin
+ .createExtension(descriptor.element,
+ ATT_PROVIDER_CLASS);
+ }
+ String path = descriptor.provider.getImagePath(marker);
+
+ // marker.setAttribute(MARKER_ATT_KEY, path);
+
+ if (path != descriptor.imagePath) {
+ descriptor.imagePath = path;
+ descriptor.imageDescriptor = getImageDescriptor(descriptor);
+ }
+
+ /*} else if (persistedPath != null) {
+ descriptor.imagePath = persistedPath;
+ descriptor.imageDescriptor = getImageDescriptor(descriptor);
+ }*/
+ return descriptor.imageDescriptor;
+ } catch (CoreException e) {
+ Policy.handle(e);
+ return null;
+ }
+ }
+
+ /**
+ * @param typeId
+ * @return Descriptor
+ */
+ private Descriptor getDescriptorFor(String typeId) {
+ Descriptor descriptor = (Descriptor) typesMap.get(typeId);
+ if (descriptor == null) {
+ MarkerType markerType = MarkerTypesModel.getInstance().getType(
+ typeId);
+ LinkedList queue = new LinkedList();
+ queue.addLast(markerType);
+ while (!queue.isEmpty()) {
+ MarkerType type = (MarkerType) queue.removeFirst();
+ descriptor = (Descriptor) descriptors.get(type.getId());
+ if (descriptor != null) {
+ typesMap.put(typeId, descriptor);
+ break;
+ }
+ MarkerType[] subTypes = type.getSupertypes();
+ // TODO: Decide whether to sort or keep in order in which they
+ // were declared
+ /*Arrays.sort(subTypes, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return ((MarkerType) o1).getId().compareTo(
+ ((MarkerType) o2).getId());
+ }
+ });*/
+ for (int j = 0; j < subTypes.length; j++) {
+ queue.addLast(subTypes[j]);
+ }
+ }
+ }
+ return descriptor;
+ }
+
+ /**
+ * Returns the image descriptor with the given relative path.
+ */
+ private ImageDescriptor getImageDescriptor(Descriptor desc) {
+ URL url = FileLocator.find(desc.pluginBundle, new Path(desc.imagePath), null);
+ return ImageDescriptor.createFromURL(url);
+ }
}