# Tool Behavior Provider

The tool behavior provider is needed to integrate into the standard workbench tools. In most cases this means adding functionality to existing editing concepts of the workbench.

Typical examples are:

- Adding features to the palette or tool-bar
- Specifying the double-click behaviour
- Adding features to the context menu or context buttons of pictogram elements

## Creating a Tool Behavior Provider

To create a tool behavior provider the interface IToolBehaviorProvider has to be implemented. Instead of implementing this directly you should extend the base classe DefaultToolBehaviorProvider.

At this point we will just create an empty tool behavior provider by extending the base class. We will add further functionality in the next chapters.

You can see the implementation of the empty tool behavior provider here:

package org.eclipse.graphiti.examples.tutorial.diagram;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
public class MyTutorialToolBehaviorProvider extends DefaultToolBehaviorProvider{
public MyTutorialToolBehaviorProvider(IDiagramTypeProvider dtp) {
super(dtp);
}
}

Additionally the diagram type provider has to deliver this newly created tool behavior provider (overwrite the method getAvailableToolBehaviorProviders).

This implementation can be seen here:

package org.eclipse.graphiti.examples.tutorial.diagram;
import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
public class MyTutorialDiagramTypeProvider extends AbstractDiagramTypeProvider {
private IToolBehaviorProvider[] toolBehaviorProviders;
public MyTutorialDiagramTypeProvider() {
super();
setFeatureProvider(new TutorialFeatureProvider(this));
}
@Override
public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() {
if (toolBehaviorProviders == null) {
toolBehaviorProviders =
new IToolBehaviorProvider[] { new MyTutorialToolBehaviorProvider(
this) };
}
return toolBehaviorProviders;
}
}