| <html> |
| |
| <head> |
| <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> |
| <title>Providing double-click behavior</title> |
| <link href="../book.css" rel="Stylesheet" type="text/css"> |
| <link href="../code.css" rel="Stylesheet" type="text/css"> |
| </head> |
| |
| <body> |
| |
| <h1>Providing Double-Click Behavior</h1> |
| <p>Enhancing the Tool Behavior Provider</p> |
| <p>The double-click behaviour is defined in the tool behavior provider.</p> |
| <p>If you didn’t do so already you must <strong>first create a tool behavior provider |
| and add it to the diagram type provider as described </strong> |
| <a href="tool-behavior-provider.htm"><strong>here</strong></a>.</p> |
| <p>There is one method of the tool behavior provider to overwrite: </p> |
| <p>The method |
| <a href="../../../javadoc/org/eclipse/graphiti/tb/IToolBehaviorProvider.html#getDoubleClickFeature(org.eclipse.graphiti.features.context.IDoubleClickContext)"> |
| getDoubleClickFeature</a> has to return the <a href="custom-feature.htm">custom |
| feature</a> to execute on double-click for the given context.</p> |
| <p>In this example we want to execute the <a href="custom-feature.htm">”Rename EClass” |
| feature</a> we implemented previously on double-click.</p> |
| <p>You can see the complete implementation of the double-click behavior here:</p> |
| <!-- Begin code ------------------------------------------------------------------------------- --> |
| <p> </p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code">@Override<br><span class="keyword">public</span> ICustomFeature |
| getDoubleClickFeature(IDoubleClickContext context) {<br> |
| ICustomFeature customFeature =<br> |
| <span class="keyword"> new</span> TutorialRenameEClassFeature(getFeatureProvider());<br> |
| <span class="comment">// canExecute() tests especially if the context contains |
| a EClass</span><br> <span class="keyword">if</span> (customFeature.canExecute(context)) |
| {<br> <span class="keyword"> return</span> |
| customFeature;<br> }<br> <br> |
| <span class="keyword"> return super</span>.getDoubleClickFeature(context);<br> |
| }<br></p> |
| </div> |
| </div> |
| <p> </p> |
| <!-- End code ------------------------------------------------------------------------------- --> |
| <h2>Test: Rename a EClass on Double-Click</h2> |
| <p>Now start the editor and create a new EClass. Double-click that EClass and the |
| rename dialog appears, which allows changing the class name.</p> |
| |
| </body> |
| |
| </html> |