It is possible to draw so called “rendering decorators” on top of active pictogram elements. These rendering decorators are transiently determined and not persisted in the diagram.
A typical use case is the rendering of error-markers on top of incorrect pictogram elements.
The rendering decorators are defined in the tool behavior provider.
If you didn’t do so already you must first create a tool behavior provider and add it to the diagram type provider as described here.
There is one method of the tool behavior provider to overwrite:
The method getDecorators has to return the rendering decorators for the given pictogram element. A rendering decorator must implement the interface IDecorator and may also implement ILocation, which provides the decorator location relative to the pictogram element.
Currently only the ImageDecorator is supported, which renders an image at the defined location and can show a text message as tooltip.
In this example we want to show an image decorator for a EClass, whenever the class name does not start with an upper case letter.
Figure: Rendering decorator displaying a warning
You can see the complete implementation of the rendering decorators here:
@Override public IDecorator[] getDecorators(PictogramElement pe) { IFeatureProvider featureProvider = getFeatureProvider(); Object bo = featureProvider.getBusinessObjectForPictogramElement(pe); if (bo instanceof EClass) { EClass eClass = (EClass) bo; String name = eClass.getName(); if (name != null && name.length() > 0 && !(name.charAt(0) >= 'A' && name.charAt(0) <= 'Z')) { IDecorator imageRenderingDecorator = new ImageDecorator( IPlatformImageConstants.IMG_ECLIPSE_WARNING_TSK); imageRenderingDecorator .setMessage("Name should start with upper case letter"); return new IDecorator[] { imageRenderingDecorator }; } }
return super.getDecorators(pe); }
|
Now start the editor and create a new EClass named “address”. Verify that the warning decorator is shown and the tooltip displays the warning message. Create another EClass named “Address” and verify that no warning decorator is displayed.