A label decorator decorates the label text and image for some element in eclipse RCP.
For example lets say I have a object called TextDoc. One of the users has opened the TextDoc and put a lock on the object. So the TextDoc object’s icon should be changed by some means so that other users are able to know that someone has put a lock on this object.
For instance, normal object icon should be
Where as the locked object icon should be
Now in the second image it can be noticed that a lock image has been put on the original image.
Now comes the implemantation part.
First we need to create class which will be handling the same. The class must implement the interface org.eclipse.jface.viewers.ILabelDecorator
Now on the implementing class we will only concentrate on the decorateImage method. For other methods in the interface, please refer to the ILabelProvider javadoc.
public class CustomDecorator implements ILabelDecorator { ..................... ..................... public Image decorateImage(Image image, Object element) { if(element instanceof TextDoc){ TextDoc doc = (TextDoc)element; if(doc.isLocked()){ /* * Here use the org.eclipse.ui.internal.OverlayIcon class to * put the lock icon on the bottom right on the original image * */ } } return image; } ............................................ ............................................ }
The the class is ready. The second step is to define one extension in the plugin.xml for the decoration
id="com.mindfire.decorator" label="Custom Decorator" state="true"
Now everything is ready. So when any object of TextDoc is locked then the locked icon will be shown on the original icon in the