blob: e60cec2c2fd77f0f4e5793924dd394365b412829 [file] [log] [blame]
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered)">
<title>Connection anchors</title>
<link rel=Stylesheet type="text/css" media=all href="../book.css">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Cambria;
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
h1
{mso-style-link:"\00DCberschrift 1 Zchn";
margin-top:12.0pt;
margin-right:0cm;
margin-bottom:3.0pt;
margin-left:0cm;
page-break-after:avoid;
font-size:16.0pt;
font-family:"Times New Roman","serif";
font-weight:bold;}
h2
{mso-style-link:"\00DCberschrift 2 Zchn";
margin-top:12.0pt;
margin-right:0cm;
margin-bottom:3.0pt;
margin-left:0cm;
page-break-after:avoid;
font-size:14.0pt;
font-family:"Times New Roman","serif";
font-weight:bold;
font-style:italic;}
h3
{mso-style-link:"\00DCberschrift 3 Zchn";
margin-top:12.0pt;
margin-right:0cm;
margin-bottom:3.0pt;
margin-left:0cm;
page-break-after:avoid;
font-size:13.0pt;
font-family:"Times New Roman","serif";
font-weight:bold;}
h4
{mso-style-link:"\00DCberschrift 4 Zchn";
margin-top:11.25pt;
margin-right:0cm;
margin-bottom:1.7pt;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";
font-weight:bold;
font-style:italic;}
h5
{mso-style-link:"\00DCberschrift 5 Zchn";
margin-right:0cm;
margin-left:0cm;
font-size:10.0pt;
font-family:"Times New Roman","serif";
font-weight:bold;}
p.MsoCaption, li.MsoCaption, div.MsoCaption
{margin-top:6.0pt;
margin-right:0cm;
margin-bottom:24.0pt;
margin-left:0cm;
text-align:justify;
font-size:10.0pt;
font-family:"Times New Roman","serif";
font-weight:bold;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p
{margin-top:5.65pt;
margin-right:0cm;
margin-bottom:5.65pt;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
pre
{mso-style-link:"HTML Vorformatiert Zchn";
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:3.4pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-link:"Sprechblasentext Zchn";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.berschrift1Zchn
{mso-style-name:"\00DCberschrift 1 Zchn";
mso-style-link:"\00DCberschrift 1";
font-family:"Cambria","serif";
color:#365F91;
font-weight:bold;}
span.berschrift2Zchn
{mso-style-name:"\00DCberschrift 2 Zchn";
mso-style-link:"\00DCberschrift 2";
font-family:"Cambria","serif";
color:#4F81BD;
font-weight:bold;}
span.berschrift3Zchn
{mso-style-name:"\00DCberschrift 3 Zchn";
mso-style-link:"\00DCberschrift 3";
font-family:"Cambria","serif";
color:#4F81BD;
font-weight:bold;}
span.berschrift4Zchn
{mso-style-name:"\00DCberschrift 4 Zchn";
mso-style-link:"\00DCberschrift 4";
font-family:"Cambria","serif";
color:#4F81BD;
font-weight:bold;
font-style:italic;}
span.berschrift5Zchn
{mso-style-name:"\00DCberschrift 5 Zchn";
mso-style-link:"\00DCberschrift 5";
font-family:"Cambria","serif";
color:#243F60;}
span.HTMLVorformatiertZchn
{mso-style-name:"HTML Vorformatiert Zchn";
mso-style-link:"HTML Vorformatiert";
font-family:Consolas;}
span.SprechblasentextZchn
{mso-style-name:"Sprechblasentext Zchn";
mso-style-link:Sprechblasentext;
font-family:"Tahoma","sans-serif";}
p.code, li.code, div.code
{mso-style-name:code;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:15.0pt;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
p.note, li.note, div.note
{mso-style-name:note;
margin-top:19.5pt;
margin-right:0cm;
margin-bottom:19.5pt;
margin-left:30.0pt;
font-size:13.0pt;
font-family:"Times New Roman","serif";
font-style:italic;}
p.msochpdefault, li.msochpdefault, div.msochpdefault
{mso-style-name:msochpdefault;
margin-top:5.65pt;
margin-right:0cm;
margin-bottom:5.65pt;
margin-left:0cm;
font-size:10.0pt;
font-family:"Times New Roman","serif";}
p.Uuml, li.Uuml, div.Uuml
{mso-style-name:"&Uuml\,'berschrift 1'";
mso-style-link:"&Uuml5\,'berschrift 5 Zchn1'";
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif"; margin-left:0cm; margin-right:0cm; margin-top:0cm}
span.Uuml1
{mso-style-name:"&Uuml1\,'berschrift 1 Zchn1'";
mso-style-link:"&Uuml\,'berschrift 1'";
font-family:"Cambria","serif";
color:#365F91;
font-weight:bold}
span.Uuml2
{mso-style-name:"&Uuml2\,'berschrift 2 Zchn1'";
mso-style-link:"&Uuml\,'berschrift 1'";
font-family:"Cambria","serif";
color:#4F81BD;
font-weight:bold}
span.Uuml3
{mso-style-name:"&Uuml3\,'berschrift 3 Zchn1'";
mso-style-link:"&Uuml\,'berschrift 1'";
font-family:"Cambria","serif";
color:#4F81BD;
font-weight:bold}
span.Uuml4
{mso-style-name:"&Uuml4\,'berschrift 4 Zchn1'";
mso-style-link:"&Uuml\,'berschrift 1'";
font-family:"Cambria","serif";
color:#4F81BD;
font-weight:bold;
font-style:italic}
span.Uuml5
{mso-style-name:"&Uuml5\,'berschrift 5 Zchn1'";
mso-style-link:"&Uuml\,'berschrift 1'";
font-family:"Cambria","serif";
color:#243F60}
span.code1
{mso-style-name:code1;
font-style:italic;}
span.code0
{mso-style-name:code0;
font-style:italic;}
.MsoChpDefault
{font-size:10.0pt;}
@page WordSection1
{size:595.45pt 841.7pt;
margin:72.0pt 89.85pt 72.0pt 89.85pt;}
div.WordSection1
{page:WordSection1;}
-->
</style>
</head>
<body bgcolor=white lang=DE link=blue vlink=purple style='margin-bottom:12.0pt'>
<div class=WordSection1>
<h1><span lang=EN-GB>Connection Anchors</span></h1>
<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
<h2><span lang=EN-US>Different Types of Connection Anchors</span></h2>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>Currently the following
different types of connection anchors are supported:</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><b><span lang=EN-US style='color:black'>Chop Box Anchor</span></b></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>It can be created
calling <a
href="../../../javadoc/org/eclipse/graphiti/services/IPeCreateService.html#createChopboxAnchor(org.eclipse.graphiti.mm.pictograms.AnchorContainer)">createChopboxAnchor</a>.
A chop box anchor is located virtually in the center of the parent. However,
the connection line does not end at the center of the parent but already at the
intersection-point with the parent boundaries. This means especially, that the
intersection-point is re-calculated not only when the parents size or location
changes, but also when the direction of the connection changes.</span></p>
<p class=MsoNormal><span style='color:black'><img border=0 width=164
height=104 src="visio/anchor-chopbox.gif"></span></p>
<p class=MsoCaption><span class=code1><span lang=EN-US style='font-style:normal'>Figure:
Chop box anchor (always pointing to the center)</span></span></p>
<p class=MsoNormal><b><span lang=EN-US style='color:black'>Box Relative Anchor</span></b></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>It can be created
calling <a
href="../../../javadoc/org/eclipse/graphiti/services/IPeCreateService.html#createBoxRelativeAnchor(org.eclipse.graphiti.mm.pictograms.AnchorContainer)">createBoxRelativeAnchor</a>.
A box relative anchor is located relative to the size and location of the
parent. The x/y-coordinates are defined as percentage values between 0.0 and
1.0. This allows for example to locate an anchor always at the middle-right
border of the parent (x=1.0, y=0.5). The location of the anchor is
re-calculated whenever the parents size or location changes.</span></p>
<p class=MsoNormal><span style='color:black'><img border=0 width=165 height=95
src="visio/anchor-boxrelative.gif"></span></p>
<p class=MsoCaption><span class=code1><span lang=EN-US style='font-style:normal'>Figure:
Box relative anchor (on middle-right border)</span></span></p>
<p class=MsoNormal><b><span lang=EN-US style='color:black'>Fix Point Anchor</span></b></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>It can be created
calling <a
href="../../../javadoc/org/eclipse/graphiti/services/IPeCreateService.html#createFixPointAnchor(org.eclipse.graphiti.mm.pictograms.AnchorContainer)">createFixPointAnchor</a>.
A fix point anchor is located at fix x/y-coordinates (relative to the parent).</span></p>
<p class=MsoNormal><span lang=EN-US>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US>&nbsp;</span></p>
<h2><span lang=EN-US>Connection Anchor Points Explained</span></h2>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>Every connection has
two connection anchors which provide the points where the connection
starts/ends. Additionally the connection can have multiple bend-points in
between.</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>An anchor has two
points: the &#8220;reference-point&#8221; is the logical end-point of the
connection and the &#8220;location&#8221; is the visible end-point of the
connection.</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>The following sketch
explains those points for a chop box anchor.</span></p>
<p class=MsoNormal><span lang=EN-US>&nbsp;</span></p>
<p class=MsoNormal><img border=0 width=444 height=154
src="visio/anchor-points.gif"></p>
<p class=MsoCaption><span class=code1><span lang=EN-US style='font-style:normal'>Figure:
Points of a chop box anchor</span></span></p>
<p class=MsoNormal><span lang=EN-US>The reference-point (R) of the chop box
anchor is the middle of the figure, because this is the point where the
connection logically ends. The reference-point changes if the figure changes,
but it does not change depending on the connection.</span></p>
<p class=MsoNormal><span lang=EN-US>We define the point (O) as the other point
where the connection logically ends. If the connection has bend-points, then
(O) is the bend-point (B) next to the anchor, otherwise (O) is the
reference-point (R) of the other connection anchor. This means, that logically
the connection is a line from (R) to (O).</span></p>
<p class=MsoNormal><span lang=EN-US>But a line drawn from (R) to (O) would
overlap the figure. To avoid this overlap the location (L) of an anchor is
calculated from (R) and (O) as the visible end-point of the connection. In case
of the chop box anchor (L) is the intersection between the line (R - O) and the
border of the figure.</span></p>
<p class=MsoNormal><span lang=EN-US>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US>The same algorithm is applied for all other
anchor types, although often the calculation is much simpler. For example in a
fix point anchor the reference-point (R) is the point the anchor was
initialized with and the location (L) is identical to (R).</span></p>
<p class=MsoNormal><span lang=EN-US>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US>&nbsp;</span></p>
<h2><span lang=EN-US>Creating Connections with Drag &amp; Drop from Anchors</span></h2>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>If the user shall be
able to create connections directly via drag &amp; drop from an anchor without
the connection-tool, this can be implemented by so called drag &amp; drop
features. This does not work for chop box anchors, because they have no visible
anchor which can be dragged.</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'>To offer drag &amp;
drop functionality from anchors we have to overwrite the <a
href="../../../javadoc/org/eclipse/graphiti/features/IFeatureProvider.html#getDragAndDropFeatures(org.eclipse.graphiti.features.context.IPictogramElementContext)">getDragAndDropFeatures</a>.</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>If this method returns
exactly one feature it will be executed directly on drop (if applicable). If
you provide more than one feature the user will be presented a popup menu on
drop showing all applicable features (applicable means <a
href="../../../javadoc/org/eclipse/graphiti/features/IFeature.html#canExecute(org.eclipse.graphiti.features.context.IContext)">canExecute</a>
returns true). The user can select the desired feature which will be executed
then.</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'>In this example we
first add a box relative anchor on the middle-right border of a EClass. Then we
support drag &amp; drop from that anchor to another EClass, which will create a
new connection.</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'>First the box relative
anchors have to be created at end of the add method of the</span><span
lang=EN-GB> </span><span class=code1><span lang=EN-US style='color:black'>TutorialAddEClassFeature</span></span><span
class=code1><span lang=EN-US style='color:black;font-style:normal'>, as
explained in the following code snippet. Note, that the previously created chop
box anchor (see <a href="create-connection-feature.htm">create connection
feature</a>) remains, so that the EClass has then two anchors:</span></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=680
style='width:18.0cm;border-collapse:collapse'>
<tr>
<td width=680 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'>&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </span><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Courier New";color:#7F0055'>public</span></b><span lang=EN-US> </span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>PictogramElement
add(IAddContext 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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#3F7F5F'>// ... EXISTING CODING ...</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
add a chopbox anchor to the 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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;peCreateService<u>.</u>createChopboxAnchor(containerShape);</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
create an additional box relative anchor at middle-right</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>final</span></b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> BoxRelativeAnchor
</span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#0000C0'>boxAnchor</span><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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; peCreateService.createBoxRelativeAnchor(containerShape);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;boxAnchor.setRelativeWidth(1.0);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;boxAnchor.setRelativeHeight(0.5);</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
anchor references visible rectangle instead of invisible rectangle</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;boxAnchor<u>.</u>setReferencedGraphicsAlgorithm(roundedRectangle);</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
assign a graphics algorithm for the box relative anchor</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Rectangle
</span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#0000C0'>rectangle</span><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:black'> = gaService.createRectangle(</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>boxAnchor</span><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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;rectangle<u>.</u>setFilled(</span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>true</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"'>&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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
anchor is located on the right border of the visible rectangle</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
and touches the border of the invisible rectangle</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><b><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>int</span></b><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:#0000C0'>w</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> =
6;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;gaService.setLocationAndSize<u>(</u>rectangle,
-2 * w, -w, 2 * w, 2 * w);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;rectangle<u>.</u>setForeground<u>(</u>manageColor(CLASS_FOREGROUND));</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;rectangle.setBackground(manageColor(CLASS_BACKGROUND));</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
call the layout 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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;layoutPictogramElement(containerShape);</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#7F0055'>return</span></b><span lang=EN-US> </span><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>containerShape;</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </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'>&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-US style='color:black'>Additionally the
feature provider has to deliver the drag &amp; drop features (overwrite the
method <a
href="../../../javadoc/org/eclipse/graphiti/features/IFeatureProvider.html#getDragAndDropFeatures(org.eclipse.graphiti.features.context.IPictogramElementContext)">getDragAndDropFeatures</a><span
class=code1>)</span>.</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>In this very simple
implementation all create connection features are returned independent of the
given context:</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=680
style='width:18.0cm;border-collapse:collapse'>
<tr>
<td width=680 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-US
style='color:black'>&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'>&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </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'>&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </span><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Courier New";color:#7F0055'>public</span></b><span lang=EN-US> </span><span
lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>IFeature[]
getDragAndDropFeatures(IPictogramElementContext 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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
color:#3F7F5F'>// simply return all create connection features</span></p>
<p class=MsoNormal style='text-autospace:none'><span lang=EN-US
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
lang=EN-US> </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'>getCreateConnectionFeatures();</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp; }</span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";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;<b>Note</b>: A
more sophisticated solution with an anchor on a EClass with an <b>extended
rendering area</b> is shown in chapter <a href="selection-behavior.htm">
selection behavior</a>.</span></p>
<h2><span lang=EN-GB>Test: Create a Connection with Drag &amp; Drop from Anchor</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'>Start the editor again
and create two new EClasses (existing EClasses don&#8217;t work, because they
have no anchor at the middle-right border).</span></p>
<p class=MsoNormal><span lang=EN-GB style='color:black'>Then</span><span
lang=EN-GB> </span><span lang=EN-US style='color:black'>drag the anchor at the
middle-right border of the first EClass and drop it onto the second EClass.
This will create a new connection between those two EClasses.</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
<div class=MsoNormal align=center style='text-align:center'>
<hr size=2 width="100%" align=center>
</div>
<p class=MsoNormal><a href="http://www.eclipse.org/legal/epl-v10.html"
shape=rect>Copyright (c) SAP AG 2005, 2010.</a> </p>
</div>
</body>
</html>