blob: 26c0b799441f9c0ac1129bfed9d34fe936bfe5ba [file] [log] [blame]
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Connection visualization</title>
<link href="../book.css" rel="Stylesheet" type="text/css">
<link href="../code.css" rel="Stylesheet" type="text/css">
</head>
<body>
<h1>Connection Visualization</h1>
<p>This chapter describes advanced connection visualization possibilities.</p>
<h2>Connection Decorators</h2>
<p>The framework supports two different connection decorators:</p>
<p><em>Static decorators</em> (inactive pictogram elements) are usually used for
connection ends.</p>
<p>
<img alt="" height="202" src="visio/connection-decorator-static.png" width="501"></p>
<p><strong>Figure: Static connection decorators</strong></p>
<p>&nbsp;</p>
<p><em>Dynamic decorators</em> (active pictogram elements) are usually of type text;
these decorators can be moved via drag &amp; drop; they can be placed anywhere in the
diagram.</p>
<p>&nbsp;</p>
<p>
<img alt="" height="211" src="visio/connection-decorator-dynamic.png" width="501"></p>
<p><strong>Figure: Dynamic connection decorators</strong></p>
<p>&nbsp;</p>
<p>To create such connection decorators we have to do the following in the graphics
model:</p>
<ul>
<li>create a connection decorator</li>
<li>add a valid graphics algorithm to the connection decorator</li>
<li>add this connection decorator to a connection</li>
<li>optional: link connection decorator with the business object</li>
</ul>
<p>There are some technical limitations for static decorators: they are only supported
for graphics algorithm of type polyline or polygon (otherwise they can not be rotated)
and they can only be placed at the beginning or at the end of a connection.</p>
<p>In this example we want create two static connection decorators as shown above
and one dynamic connection decorator which displays the name of the association.
For simplification those static connection decorators will be created without consideration
of the real values in the business model (types of association ends).</p>
<p>The decorators will be added in the <a href="add-connection-feature.htm">add
connection feature</a>. The following changes must be done in this feature. First
add some helper methods to the add connection feature which create the graphics
algorithms for the static decorators:</p>
<p>&nbsp;</p>
<div class="literallayout">
<div class="incode">
<p class="code"><span class="keyword">private </span>Polyline createArrow(GraphicsAlgorithmContainer
gaContainer) {<br>&nbsp;&nbsp;&nbsp; IGaService gaService = Graphiti.getGaService();<br>&nbsp;&nbsp;&nbsp;
Polyline polyline =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gaService.createPolyline(gaContainer,
<span class="keyword">new int</span>[] { -15, 10, 0, 0, -15,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-10 });<br>&nbsp;&nbsp;&nbsp; polyline.setForeground(manageColor(IColorConstant.<span class="string"><em>BLACK</em></span>));<br>&nbsp;&nbsp;&nbsp;
polyline.setLineWidth(2);<br>&nbsp;&nbsp;&nbsp; return polyline;<br>}
</p>
</div>
</div>
<p>&nbsp;</p>
<p>Then create the connection decorators at the end of the add method of the add
connection feature, as explained in the following code snippet:</p>
<p>&nbsp;</p>
<div class="literallayout">
<div class="incode">
<p class="code"><span class="keyword">&nbsp;public </span>PictogramElement
add(IAddContext context) {<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;
<span class="comment">// ... EXISTING CODING ...</span><br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;
<span class="comment">// add dynamic text decorator for the association
name </span><br>&nbsp;&nbsp;&nbsp;&nbsp; ConnectionDecorator textDecorator
=<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; peCreateService.createConnectionDecorator(connection,
<span class="keyword">true</span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0.5, <span class="keyword">true</span>);<br>&nbsp;&nbsp;&nbsp;&nbsp; Text
text = gaService.createDefaultText(textDecorator);<br>&nbsp;&nbsp;&nbsp;&nbsp;
text.setForeground(manageColor(IColorConstant.<span class="string"><em>BLACK</em></span>));<br>&nbsp;&nbsp;&nbsp;&nbsp;
gaService.setLocation(text, 10, 0);<br>&nbsp;&nbsp;&nbsp;&nbsp;
<span class="comment">// set reference name in the text decorator</span><br>
´&nbsp;&nbsp;&nbsp; EReference eReference = (EReference) context.getNewObject();<br>&nbsp;&nbsp;&nbsp;&nbsp;
text.setValue(eReference.getName());<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;
<span class="comment">// add static graphical decorator (composition and
navigable)</span><br>&nbsp;&nbsp;&nbsp;&nbsp; ConnectionDecorator cd;<br>&nbsp;&nbsp;&nbsp;&nbsp;
cd = peCreateService<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
.createConnectionDecorator(connection, <span class="keyword">false</span>,
1.0, <span class="keyword">true</span>);<br>&nbsp;&nbsp;&nbsp;&nbsp; createArrow(cd);<br>&nbsp;&nbsp;&nbsp;&nbsp;
<span class="keyword">return </span>connection;<br>&nbsp;}</p>
</div>
</div>
<p>&nbsp;</p>
<h2>Test: Display and Move Connection Decorators</h2>
<p>Start the editor again and test these new connection decorators:</p>
<ol>
<li>create or open a diagram</li>
<li>create a new EReference between two EClasses; you can see the three decorators
on the EReference</li>
<li>move the EClasses; you can see that the static decorator (arrow) rotate
automatically</li>
<li>move the dynamic decorator (text) via drag &amp; drop</li>
</ol>
</body>
</html>