| <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> </p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"><span class="keyword">package </span>org.eclipse.graphiti.examples.tutorial.diagram;<br> <br> |
| <span class="keyword">import</span> org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;<br> |
| <span class="keyword">import</span> org.eclipse.graphiti.tb.IToolBehaviorProvider;<br> <br> |
| <span class="keyword">public class</span> MyTutorialDiagramTypeProvider |
| <span class="keyword">extends</span> AbstractDiagramTypeProvider {<br> <br> |
| <span class="keyword">private</span> IToolBehaviorProvider[]<span class="string"> |
| toolBehaviorProviders</span>;<br> <br> |
| <span class="keyword"> public</span> MyTutorialDiagramTypeProvider() |
| {<br> <span class="keyword"> super</span>();<br> |
| setFeatureProvider(<span class="keyword">new</span> TutorialFeatureProvider(this));<br> |
| }<br> <br> @Override<br> |
| <span class="keyword">public</span> IToolBehaviorProvider[] getAvailableToolBehaviorProviders() |
| {<br> <span class="keyword">if</span> |
| (<span class="string">toolBehaviorProviders </span>== |
| <span class="keyword">null</span>) {<br> |
| <span class="string">toolBehaviorProviders </span>=<br> |
| <span class="keyword">new</span> IToolBehaviorProvider[] { |
| <span class="keyword">new</span> MyTutorialToolBehaviorProvider(<br> |
| <span class="keyword">this</span>) };<br> |
| }<br> <span class="keyword">return</span> |
| <span class="string">toolBehaviorProviders</span>;<br> |
| }<br>}<br></p> |
| </div> |
| </div> |
| <p> </p> |
| <!-- End code ------------------------------------------------------------------------------- --> |
| |
| </body> |
| |
| </html> |