blob: 94c3542204f782a6e60e49cf84663e21ebdca624 [file] [log] [blame]
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Tool behavior provider</title>
<link href="../book.css" rel="Stylesheet" type="text/css">
<link href="../code.css" rel="Stylesheet" type="text/css">
</head>
<body>
<h1>Tool Behavior Provider</h1>
<p>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.</p>
<p>Typical examples are:</p>
<ul>
<li>Adding features to the palette or tool-bar</li>
<li>Specifying the double-click behaviour</li>
<li>Adding features to the context menu or context buttons of pictogram elements</li>
</ul>
<h2>Creating a Tool Behavior Provider</h2>
<p>To create a tool behavior provider the interface
<a href="../../../javadoc/org/eclipse/graphiti/tb/IToolBehaviorProvider.html">IToolBehaviorProvider</a>
has to be implemented. Instead of implementing this directly you should extend the
base classe
<a href="../../../javadoc/org/eclipse/graphiti/tb/DefaultToolBehaviorProvider.html">
DefaultToolBehaviorProvider</a>.</p>
<p>At this point we will just create an empty tool behavior provider by extending
the base class. </p>
<p>You can see the implementation of the empty tool behavior provider
<a href="custom-feature.htm">here</a> . We will add further functionality in the
next chapters.</p>
<p>Additionally the diagram type provider has to deliver this newly created tool
behavior provider (overwrite the method
<a href="../../../javadoc/org/eclipse/graphiti/dt/AbstractDiagramTypeProvider.html#getAvailableToolBehaviorProviders()">
getAvailableToolBehaviorProviders</a>). </p>
<p>This implementation can be seen here:</p>
<!-- Begin code ------------------------------------------------------------------------------- -->
<p>&nbsp;</p>
<div class="literallayout">
<div class="incode">
<p class="code"><span class="keyword">package </span>org.eclipse.graphiti.examples.tutorial.diagram;<br>&nbsp;<br>
<span class="keyword">import</span> org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;<br>
<span class="keyword">import</span> org.eclipse.graphiti.tb.IToolBehaviorProvider;<br>&nbsp;<br>
<span class="keyword">public class</span> MyTutorialDiagramTypeProvider
<span class="keyword">extends</span> AbstractDiagramTypeProvider {<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;
<span class="keyword">private</span> IToolBehaviorProvider[]<span class="string">
toolBehaviorProviders</span>;<br>&nbsp;<br>&nbsp;&nbsp;
<span class="keyword">&nbsp;public</span> MyTutorialDiagramTypeProvider()
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">&nbsp;super</span>();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
setFeatureProvider(<span class="keyword">new</span> TutorialFeatureProvider(this));<br>&nbsp;&nbsp;&nbsp;
}<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; @Override<br>&nbsp;&nbsp;&nbsp;
<span class="keyword">public</span> IToolBehaviorProvider[] getAvailableToolBehaviorProviders()
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>
(<span class="string">toolBehaviorProviders </span>==
<span class="keyword">null</span>) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="string">toolBehaviorProviders </span>=<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="keyword">new</span> IToolBehaviorProvider[] {
<span class="keyword">new</span> MyTutorialToolBehaviorProvider(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="keyword">this</span>) };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">return</span>
<span class="string">toolBehaviorProviders</span>;<br>&nbsp;&nbsp;&nbsp;
}<br>}<br></p>
</div>
</div>
<p>&nbsp;</p>
<!-- End code ------------------------------------------------------------------------------- -->
</body>
</html>