Providing Tooltips

Enhancing the Tool Behavior Provider

Tooltips can be shown on top of active pictogram elements. A typical use case is to show the name of pictogram elements or anything else you can get from the business object.

The tooltips 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:

In this example we want to show a tooltip for a EClass.

 

Figure: Tooltip from EClass with name "Beton"

You can see the complete implementation of the tooltip here:

 

@Override
public String getToolTip(GraphicsAlgorithm ga) {
    PictogramElement pe = ga.getPictogramElement();
    Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe);
    if (bo instanceof EClass) {
        String name = ((EClass)bo).getName();
        if (name != null && !name.isEmpty()) {
            return name;        
        }
    }
    return super.getToolTip(ga);
}

 

Note: Because the tooltip is bound to a business object of the domain model, every change of the business object will automatically update the tooltip.

Test: Show Tooltip for EClass

Remember, the name of an EClass should start with a upper case letter. Start the editor and create a new EClass named "Anton". Hover over the shape and verify that the tooltip is shown and the tooltip displays the name. Change the name of the EClass to "Beton" and verify that it is displayed accordingly.