blob: 818219b2ec4ffa23e18292eadd5a7f98e2f05f7d [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<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>
<ul>
<li>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.</li>
</ul>
<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>&nbsp;</p>
<div class="literallayout">
<div class="incode">
<p class="code">@Override<br><span class="keyword">public</span> ICustomFeature
getDoubleClickFeature(IDoubleClickContext context) {<br>&nbsp;&nbsp;&nbsp;
ICustomFeature customFeature =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="keyword">&nbsp;new</span> TutorialRenameEClassFeature(getFeatureProvider());<br>&nbsp;&nbsp;&nbsp;
<span class="comment">// canExecute() tests especially if the context contains
a EClass</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">if</span> (customFeature.canExecute(context))
{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">&nbsp;return</span>
customFeature;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;<br>&nbsp;&nbsp;
<span class="keyword">&nbsp;return super</span>.getDoubleClickFeature(context);<br>
}<br></p>
</div>
</div>
<p>&nbsp;</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>
<p>&nbsp;</p>
</body>
</html>