blob: cdb06502bf99d1c78d3b551d37bbbeee3013c548 [file] [log] [blame]
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>Providing resize functionality</title>
<link rel=Stylesheet type="text/css" media=all href="../book.css">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";
color:windowtext;}
h1
{margin-top:12.0pt;
margin-right:0cm;
margin-bottom:3.0pt;
margin-left:0cm;
page-break-after:avoid;
font-size:16.0pt;
font-weight:bold;}
h2
{margin-top:12.0pt;
margin-right:0cm;
margin-bottom:3.0pt;
margin-left:0cm;
page-break-after:avoid;
font-size:14.0pt;
font-weight:bold;
font-style:italic;}
h3
{margin-top:12.0pt;
margin-right:0cm;
margin-bottom:3.0pt;
margin-left:0cm;
page-break-after:avoid;
font-size:13.0pt;
font-weight:bold;}
h4
{margin-top:11.25pt;
margin-right:0cm;
margin-bottom:1.7pt;
margin-left:0cm;
font-size:12.0pt;
font-weight:bold;
font-style:italic;}
h5
{margin-right:0cm;
margin-left:0cm;
font-size:10.0pt;
font-weight:bold;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p
{font-size:12.0pt;}
pre
{margin-top:0cm;
margin-bottom:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:Tahoma;}
p.code, li.code, div.code
{font-size:12.0pt;}
p.note, li.note, div.note
{font-size:13.0pt;}
span.code1
{font-style:italic;}
@page Section1
{size:595.45pt 841.7pt;
margin:72.0pt 89.85pt 72.0pt 89.85pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body bgcolor=white lang=DE link=blue vlink=purple style='margin-bottom:12.0pt'>
<div class=Section1>
<h1><a name="_Toc179099521"><span lang=EN-GB>Providing Resize Functionality</span></a></h1>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;&nbsp;</span></p>
<h2><span lang=EN-GB>Creating a Resize Feature</span></h2>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>In our current editor
the resize functionality is already provided by the framework. Nevertheless
this tutorial should explain how the resize behavior can be customized.
Therefore we constructed the following example behavior:</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>Resizing EClasses
should be restricted to EClasses whose name is longer than one character
(just an example without logical reason).</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>Remember, that we
already <a href="move-feature.htm">provided move functionality</a>, which
restricted the move of EClasses whose name is longer than one character. Now
we want to additionally restrict the resize. </span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>A resize feature has to
implement the interface </span><span class=code1><span lang=EN-US
style='color:black'><a
href="../../../javadoc/org/eclipse/graphiti/features/IResizeShapeFeature.html"><span
style='font-style:normal'>IResizeShapeFeature</span></a></span></span><span
lang=EN-GB style='color:black'>. Instead of implementing this directly you
should extend one of the available base classes.</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>In this example we
extend the base class<span class=code1> </span></span><span class=code1><span
lang=EN-US style='color:black'><a
href="../../../javadoc/org/eclipse/graphiti/features/impl/DefaultResizeShapeFeature.html"><span
style='font-style:normal'>DefaultResizeShapeFeature</span></a></span></span><span
lang=EN-GB style='color:black'>. </span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>There are two methods
to overwrite: </span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>The method <a
href="../../../javadoc/org/eclipse/graphiti/func/IResizeShape.html#canResizeShape(org.eclipse.graphiti.features.context.IResizeShapeContext)">canResizeShape</a>
has to check if this feature can do the resize corresponding to the given
context. </span><span lang=EN-US style='color:black'>In this case the location
information contained in the context consists of the shape to be resized.</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>The method </span><span
class=code1><span lang=EN-US style='color:black'><a
href="../../../javadoc/org/eclipse/graphiti/func/IResizeShape.html#resizeShape(org.eclipse.graphiti.features.context.IResizeShapeContext)"><span
style='font-style:normal'>resizeShape</span></a></span></span><span lang=EN-GB
style='color:black'> does the final resize. </span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>You can see the
complete implementation of the resize feature here:</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907
style='width:18.0cm;border-collapse:collapse'>
<tr>
<td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt;
padding:0cm 5.4pt 0cm 5.4pt'>
<p class=MsoNormal style='text-autospace:none'><b><span lang=EN-GB
style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>&nbsp;</span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>package</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
org.eclipse.graphiti.examples.tutorial.features;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
<p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>class</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
TutorialResizeEClassFeature </span><b><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:#7F0055'>extends</span></b><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>
DefaultResizeShapeFeature {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
TutorialResizeEClassFeature(IFeatureProvider fp) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>super</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>(fp);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    }</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
canResizeShape(IResizeShapeContext context) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
canResize = </span><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Courier New";color:#7F0055'>super</span></b><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>.canResizeShape(context);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
perform further check only if move allowed by default feature</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
(canResize) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
don't allow resize if the class name has the length of 1</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>            Shape
shape = context.getShape();</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>           
Object bo = getBusinessObjectForPictogramElement(shape);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
(bo </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#7F0055'>instanceof</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:black'> EClass) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>               
EClass c = (EClass) bo;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>               
</span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#7F0055'>if</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:black'> (c.getName() != </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>null</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
&amp;&amp; c.getName().length() == 1) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>                   
</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>canResize
= </span><b><span style='font-size:10.0pt;font-family:"Courier New";
color:#7F0055'>false</span></b><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>;</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>                }</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>            }</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>        }</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>        </span><b><span
style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
style='font-size:10.0pt;font-family:"Courier New";color:black'> canResize;</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>    }</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>}</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
</td>
</tr>
</table>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>Additionally the
feature provider has to deliver our newly created feature (overwrite the method
</span><span class=code1><span lang=EN-US style='color:black'><a
href="../../../javadoc/org/eclipse/graphiti/features/IFeatureProvider.html#getResizeShapeFeature(org.eclipse.graphiti.features.context.IResizeShapeContext)"><span
style='font-style:normal'>getResizeShapeFeature</span></a></span></span><span
class=code1><span lang=EN-US style='color:black;font-style:normal'>).</span></span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>This implementation can
be seen here:</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907
style='width:18.0cm;border-collapse:collapse'>
<tr>
<td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt;
padding:0cm 5.4pt 0cm 5.4pt'>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-GB
style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>&nbsp;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
IResizeShapeFeature getResizeShapeFeature(</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>            IResizeShapeContext
context) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        Shape
shape = context.getShape();</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        Object
bo = getBusinessObjectForPictogramElement(shape);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
(bo </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#7F0055'>instanceof</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:black'> EClass) {</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>new</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
TutorialResizeEClassFeature(</span><b><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:#7F0055'>this</span></b><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>}</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>        </span><b><span
style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>super</span></b><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>.getResizeShapeFeature(context);</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>    }</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
</td>
</tr>
</table>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<h2><span lang=EN-US>Test: Resize EClass Is Restricted</span></h2>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>Now start the editor again
and test it: Just create a EClass whose name is only one character long. This EClass can no longer be resized, because on selection the resize-handles do
not appear any more. For EClasses whose name has more than one character the
resize should still work.</span></p>
</div>
<hr>
<a href="http://www.eclipse.org/legal/epl-v10.html" shape="rect">Copyright (c) SAP AG 2005, 2010.</a>
</body>
</html>