Search code examples
eclipseeclipse-rcpeclipse-plugineclipse-pde

How to create custom image decorator in java file using eclipse plugin


I would like to use some decorators in my Eclipse plugin. I have created a plugin where I created my own editor for my own .test file. If the user edits .test file and saves it. The file must show some decorations not only the .test file but also the project must show the decorator. I am stuck with this problem I can't find any good tutorial to create decorators.

I Have seen some of the websites like https://www.eclipse.org/articles/Article-Decorators/decorators.html but I couldn't get the exact point.

Will some one please tell me how to create custom decorator for my eclipse plugin.


Solution

  • A ILightweightLabelDecorator is the most common type of decorator

    Declare this in your plugin.xml with something like this:

    <extension point="org.eclipse.ui.decorators"> 
        <decorator
            id="my.decorator.id" 
            class="my.decorator.Decorator" 
            label="My Decorator" 
            state="true" 
            lightweight="true" 
            adaptable="true"> 
            <enablement>
                <objectClass name="org.eclipse.core.resources.IResource"/> 
            </enablement>
        </decorator>
    </extension>
    

    You will have to adjust the enablement to suit what you want.

    Your decorator class would be something like:

    public class Decorator extends BaseLabelDecorator implements ILightweightLabelDecorator
    {
      @Override
      public void decorate(final Object element, final IDecoration decoration)
      {
        // TODO call decoration methods to add overlay images or prefix / suffix text
      }
    }