public class TaggedLabelDecorator implements ILightweightLabelDecorator, ITagAssociationManagerListener { private static final ImageDescriptor OVERLAY = TaggerActivator.imageDescriptorFromPlugin( TaggerActivator.getDefault().getBundle().getSymbolicName(), "icons/tagger_labeldeco.gif"); private final List<ILabelProviderListener> labelProviderListeners = new LinkedList<ILabelProviderListener>(); public TaggedLabelDecorator() { TagAssociationManager.getInstance().addTagAssociationListener(this); } public void dispose() { TagAssociationManager.getInstance().removeTagAssociationListener(this); } public void decorate(Object element, IDecoration decoration) { try { final IResource resource = (IResource) element; if (resource.exists() && TaggedMarkerHelper.getMarker(resource) != null) { decoration.addOverlay( OVERLAY, TaggerActivator.getDefault() .getPreferenceStore() .getInt(PreferenceConstants.POSITION_LABEL_DECORATION.getKey())); } } catch (CoreException ce) { TaggerLog.error("Unable to decorate resource: " + ce.getMessage(), ce); } } public void addListener(ILabelProviderListener listener) { if (!labelProviderListeners.contains(listener)) { labelProviderListeners.add(listener); } } public void removeListener(ILabelProviderListener listener) { labelProviderListeners.remove(listener); } public boolean isLabelProperty(Object element, String property) { return false; } public void handleTagAssociationEvent(TagAssociationEvent tme) { fireLabelProviderEvent(new LabelProviderChangedEvent(this, tme.getResource())); } private void fireLabelProviderEvent(LabelProviderChangedEvent evt) { for (ILabelProviderListener listener : labelProviderListeners) { listener.labelProviderChanged(evt); } } }
public void decorate(Object element, IDecoration decoration) { try { final IResource resource = (IResource) element; if (resource.exists() && TaggedMarkerHelper.getMarker(resource) != null) { decoration.addOverlay( OVERLAY, TaggerActivator.getDefault() .getPreferenceStore() .getInt(PreferenceConstants.POSITION_LABEL_DECORATION.getKey())); } } catch (CoreException ce) { TaggerLog.error("Unable to decorate resource: " + ce.getMessage(), ce); } }