# Providing Rendering Decorators

## Enhancing the Tool Behavior Provider

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.

Graphiti supports the following decorators to decorate shapes:

- ImageDecorators: render an image at the defined location and can show a text message as tooltip
- ColorDecorators: render a shape with a different background and/or foreground color
- BorderDecorators: render a shape with an additional surrounding border with a defined color, width and style
- TextDecorators: render a text at the defined location with a specific font, font size and color

Besides ColorDecorators can be used to change the foreground color of connections (the background color cannot be changed).

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);
}

## Test: Show Warning Decorator for EClass

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.