blob: 88970d187789178a78c099894e7fd8d6164fa6d3 [file] [log] [blame]
mwenzb5dc2f92010-06-16 13:24:52 +00001<html>
2
3<head>
4<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
5<meta name=Generator content="Microsoft Word 11 (filtered)">
6<title>Providing direct editing functionality</title>
7<link rel=Stylesheet type="text/css" media=all href="../book.css">
8<style>
9<!--
10 /* Font Definitions */
11 @font-face
12 {font-family:Tahoma;
13 panose-1:2 11 6 4 3 5 4 4 2 4;}
14 /* Style Definitions */
15 p.MsoNormal, li.MsoNormal, div.MsoNormal
16 {margin:0cm;
17 margin-bottom:.0001pt;
18 font-size:12.0pt;
19 font-family:"Times New Roman";
20 color:windowtext;}
21h1
22 {margin-top:12.0pt;
23 margin-right:0cm;
24 margin-bottom:3.0pt;
25 margin-left:0cm;
26 page-break-after:avoid;
27 font-size:16.0pt;
28 font-weight:bold;}
29h2
30 {margin-top:12.0pt;
31 margin-right:0cm;
32 margin-bottom:3.0pt;
33 margin-left:0cm;
34 page-break-after:avoid;
35 font-size:14.0pt;
36 font-weight:bold;
37 font-style:italic;}
38h3
39 {margin-top:12.0pt;
40 margin-right:0cm;
41 margin-bottom:3.0pt;
42 margin-left:0cm;
43 page-break-after:avoid;
44 font-size:13.0pt;
45 font-weight:bold;}
46h4
47 {margin-top:11.25pt;
48 margin-right:0cm;
49 margin-bottom:1.7pt;
50 margin-left:0cm;
51 font-size:12.0pt;
52 font-weight:bold;
53 font-style:italic;}
54h5
55 {margin-right:0cm;
56 margin-left:0cm;
57 font-size:10.0pt;
58 font-weight:bold;}
59h6
60 {margin-right:0cm;
61 margin-left:0cm;
62 font-size:7.5pt;
63 font-weight:bold;}
64p.MsoCaption, li.MsoCaption, div.MsoCaption
65 {margin-top:6.0pt;
66 margin-right:0cm;
67 margin-bottom:24.0pt;
68 margin-left:0cm;
69 text-align:justify;
70 font-size:10.0pt;
71 font-weight:bold;}
72a:link, span.MsoHyperlink
73 {color:blue;
74 text-decoration:underline;}
75a:visited, span.MsoHyperlinkFollowed
76 {color:purple;
77 text-decoration:underline;}
78p
79 {margin-top:5.65pt;
80 margin-right:0cm;
81 margin-bottom:5.65pt;
82 margin-left:0cm;
83 font-size:12.0pt;}
84pre
85 {margin-top:0cm;
86 margin-right:0cm;
87 margin-bottom:0cm;
88 margin-left:3.4pt;
89 margin-bottom:.0001pt;
90 font-size:11.0pt;}
91p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
92 {margin:0cm;
93 margin-bottom:.0001pt;
94 font-size:8.0pt;
95 font-family:Tahoma;}
96p.code, li.code, div.code
97 {margin-top:0cm;
98 margin-right:0cm;
99 margin-bottom:0cm;
100 margin-left:15.0pt;
101 margin-bottom:.0001pt;
102 font-size:12.0pt;}
103p.note, li.note, div.note
104 {margin-top:19.5pt;
105 margin-right:0cm;
106 margin-bottom:19.5pt;
107 margin-left:30.0pt;
108 font-size:13.0pt;
109 font-style:italic;}
110span.code1
111 {font-style:italic;}
112span.code0
113 {font-style:italic;}
114@page Section1
115 {size:595.45pt 841.7pt;
116 margin:72.0pt 89.85pt 72.0pt 89.85pt;}
117div.Section1
118 {page:Section1;}
119 /* List Definitions */
120 ol
121 {margin-bottom:0cm;}
122ul
123 {margin-bottom:0cm;}
124-->
125</style>
126
127</head>
128
129<body bgcolor=white lang=DE link=blue vlink=purple style='margin-bottom:12.0pt'>
130
131<div class=Section1>
132
133<h1><a name="_Toc179099521"><span lang=EN-GB>Providing Direct Editing
134Functionality</span></a></h1>
135
136<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
137
138<p class=MsoNormal><span lang=EN-GB style='color:black'>Direct editing means
139the possibility to change values directly in the graphical editor. Technically
140the user clicks on a pictogram-element and an editor is shown, where the user
141can change the values of this pictogram element.&nbsp;&nbsp; </span></p>
142
143<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
144
145<p class=MsoNormal><span lang=EN-GB style='color:black'>A typical use case is,
146that the user clicks on a text (either in a shape or a connection decorator)
147and then the text is overlaid with a text-edit-field, where the user can change
148the text value. To the user this actually looks as if the text is replaced with
149the text-edit-field.</span></p>
150
151<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
152
153<p class=MsoNormal><span lang=EN-GB style='color:black'>
154<img width=199
155height=201 src="visio/direct-editing.png"></span></p>
156
157<p class=MsoCaption><span lang=EN-US>Figure: Direct editing of a text</span></p>
158
159<p class=MsoNormal><span lang=EN-US style='color:black'>&nbsp;</span></p>
160
161<h2><span lang=EN-GB>Creating a Direct Editing Feature</span></h2>
162
163<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
164
165<p class=MsoNormal><span lang=EN-GB style='color:black'>In this example we want
166to enable the users to edit the name of a EClass directly in the diagram.
167Therefore we have to create a direct editing feature and make it available in
168the feature provider.</span></p>
169
170<p class=MsoNormal><span lang=EN-GB style='color:black'>A direct editing
171feature has to implement the interface </span><span class=code1><span
172lang=EN-US style='color:black'><a
jpasch89c98532010-09-10 12:26:47 +0000173href="../../../javadoc/org/eclipse/graphiti/features/IDirectEditingFeature.html"><span
mwenzb5dc2f92010-06-16 13:24:52 +0000174style='font-style:normal'>IDirectEditingFeature</span></a>.</span></span><span
175lang=EN-GB style='color:black'> Instead of implementing it directly it should
176extend one of the available base classes. In this example we extend the base
177class<span class=code1> </span></span><span class=code1><span lang=EN-US
178style='color:black'><a
jpasch89c98532010-09-10 12:26:47 +0000179href="../../../javadoc/org/eclipse/graphiti/features/impl/AbstractDirectEditingFeature.html"><span
mwenzb5dc2f92010-06-16 13:24:52 +0000180style='font-style:normal'>AbstractDirectEditingFeature</span></a></span></span><span
181lang=EN-GB style='color:black'>.</span></p>
182
183<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
184
185<p class=MsoNormal><span lang=EN-GB style='color:black'>In this case we have to
186implement/overwrite several methods:</span></p>
187
188<p class=MsoNormal><span lang=EN-GB style='color:black'>The method <a
jpasch89c98532010-09-10 12:26:47 +0000189href="../../../javadoc/org/eclipse/graphiti/func/IDirectEditing.html#getEditingType()">getEditingType</a>
mwenzb5dc2f92010-06-16 13:24:52 +0000190has to return the editor type which shall be used to edit the value, in this
191example a text editor.</span></p>
192
193<p class=MsoNormal><span lang=EN-GB style='color:black'>The method </span><span
194class=code1><span lang=EN-US style='color:black;font-style:normal'><a
jpasch89c98532010-09-10 12:26:47 +0000195href="../../../javadoc/org/eclipse/graphiti/func/IDirectEditing.html#canDirectEdit(org.eclipse.graphiti.features.context.IDirectEditingContext)">canDirectEdit</a></span></span><span
mwenzb5dc2f92010-06-16 13:24:52 +0000196lang=EN-US style='color:black'> </span><span lang=EN-GB style='color:black'>has
197to check the given context and therefore it decides if direct editing is
198supported.</span></p>
199
200<p class=MsoNormal><span lang=EN-GB style='color:black'>The method <a
jpasch89c98532010-09-10 12:26:47 +0000201href="../../../javadoc/org/eclipse/graphiti/func/IDirectEditing.html#getInitialValue(org.eclipse.graphiti.features.context.IDirectEditingContext)">getInitialValue</a>
mwenzb5dc2f92010-06-16 13:24:52 +0000202has to return the initial value with which the editor is initialized, which is
203usually the currently displayed value.</span></p>
204
205<p class=MsoNormal><span lang=EN-GB style='color:black'>The method <a
jpasch89c98532010-09-10 12:26:47 +0000206href="../../../javadoc/org/eclipse/graphiti/func/IDirectEditing.html#checkValueValid(java.lang.String, org.eclipse.graphiti.features.context.IDirectEditingContext)">checkValueValid</a>
mwenzb5dc2f92010-06-16 13:24:52 +0000207performs a check of the current editor value on each value change.</span></p>
208
209<p class=MsoNormal><span lang=EN-GB style='color:black'>The method <a
jpaschc5948572010-09-22 12:19:02 +0000210href="../../../javadoc/org/eclipse/graphiti/func/IDirectEditing.html#setValue(java.lang.String, org.eclipse.graphiti.features.context.IDirectEditingContext)">setValue</a>
mwenzb5dc2f92010-06-16 13:24:52 +0000211has to set the edited value to the model at the end of the editing process.</span></p>
212
213<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
214
215<p class=MsoNormal><span lang=EN-GB style='color:black'>You can see the
216complete implementation of the direct editing feature here:</span></p>
217
218<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
219
220<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907
221 style='width:18.0cm;border-collapse:collapse'>
222 <tr>
223 <td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt;
224 padding:0cm 5.4pt 0cm 5.4pt'>
225 <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-GB
226 style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>&nbsp;</span></b></p>
227 <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US
228 style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>package</span></b><span
229 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
230 org.eclipse.graphiti.examples.tutorial.features;</span></p>
231 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
232 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
233 <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US
234 style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
235 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
236 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>class</span></b><span
237 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
238 TutorialDirectEditEClassFeature </span><b><span lang=EN-US style='font-size:
239 10.0pt;font-family:"Courier New";color:#7F0055'>extends</span></b></p>
240 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
241 style='font-size:10.0pt;font-family:"Courier New";color:black'>    AbstractDirectEditingFeature
242 {</span></p>
243 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
244 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
245 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
246 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
247 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
248 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
249 TutorialDirectEditEClassFeature(IFeatureProvider fp) {</span></p>
250 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
251 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
252 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>super</span></b><span
253 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>(fp);</span></p>
254 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
255 style='font-size:10.0pt;font-family:"Courier New";color:black'>    }</span></p>
256 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
257 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
258 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
259 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
260 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
261 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
262 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>int</span></b><span
263 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
264 getEditingType() {</span></p>
265 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
266 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
267 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
268 there are several possible editor-types supported:</span></p>
269 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
270 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
271 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
272 text-field, checkbox, color-chooser, combobox, ...</span></p>
273 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
274 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
275 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
276 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><i><span
277 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>TYPE_TEXT</span></i><span
278 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></p>
279 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
280 style='font-size:10.0pt;font-family:"Courier New";color:black'>    }</span></p>
281 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
282 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
283 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
284 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><span
285 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p>
286 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
287 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
288 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
289 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
290 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span
291 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
292 canDirectEdit(IDirectEditingContext context) {</span></p>
293 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
294 style='font-size:10.0pt;font-family:"Courier New";color:black'>        PictogramElement
295 pe = context.getPictogramElement();</span></p>
296 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
297 style='font-size:10.0pt;font-family:"Courier New";color:black'>        Object
298 bo = getBusinessObjectForPictogramElement(pe);</span></p>
299 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
300 style='font-size:10.0pt;font-family:"Courier New";color:black'>        GraphicsAlgorithm
301 ga = context.getGraphicsAlgorithm();</span></p>
302 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
303 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
304 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
305 support direct editing, if it is a EClass, and the user clicked</span></p>
306 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
307 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
308 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
309 directly on the text and not somewhere else in the rectangle</span></p>
310 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
311 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
312 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
313 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
314 (bo </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
315 color:#7F0055'>instanceof</span></b><span lang=EN-US style='font-size:10.0pt;
316 font-family:"Courier New";color:black'> EClass &amp;&amp; ga </span><b><span
317 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>instanceof</span></b><span
318 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
319 Text) {</span></p>
320 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
321 style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
322 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
323 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
324 </span><font color="#800080">
325 <span
326 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";font-weight:700'>
327 true</span></font><span
328 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></p>
329 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
330 style='font-size:10.0pt;font-family:"Courier New";color:black'>        }</span></p>
331 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
332 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
333 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
334 direct editing not supported in all other cases</span></p>
335 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
336 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
337 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
338 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
339 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>false</span></b><span
340 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></p>
341 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
342 style='font-size:10.0pt;font-family:"Courier New";color:black'>    }</span></p>
343 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
344 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
345 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
346 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
347 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
348 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
349 String getInitialValue(IDirectEditingContext context) {</span></p>
350 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
351 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
352 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
353 return the current name of the EClass</span></p>
354 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
355 style='font-size:10.0pt;font-family:"Courier New";color:black'>        PictogramElement
356 pe = context.getPictogramElement();</span></p>
357 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
358 style='font-size:10.0pt;font-family:"Courier New";color:black'>       
359 EClass eClass = (EClass) getBusinessObjectForPictogramElement(pe);</span></p>
360 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
361 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
362 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
363 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
364 eClass.getName();</span></p>
365 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
366 style='font-size:10.0pt;font-family:"Courier New";color:black'>    }</span></p>
367 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
368 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
369 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
370 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><span
371 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p>
372 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
373 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
374 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
375 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
376 String checkValueValid(String value, IDirectEditingContext context) {</span></p>
377 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
378 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
379 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
380 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
381 (value.length() &lt; 1)</span></p>
382 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
383 style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
384 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
385 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span
386 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>&quot;Please
387 enter any text as class name.&quot;</span><span lang=EN-US style='font-size:
388 10.0pt;font-family:"Courier New";color:black'>;</span></p>
389 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
390 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
391 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
392 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
393 (value.contains(</span><span lang=EN-US style='font-size:10.0pt;font-family:
394 "Courier New";color:#2A00FF'>&quot; &quot;</span><span lang=EN-US
395 style='font-size:10.0pt;font-family:"Courier New";color:black'>))</span></p>
396 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
397 style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
398 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
399 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span
400 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>&quot;Spaces
401 are not allowed in class names.&quot;</span><span lang=EN-US
402 style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></p>
403 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
404 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
405 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
406 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
407 (value.contains(</span><span lang=EN-US style='font-size:10.0pt;font-family:
408 "Courier New";color:#2A00FF'>&quot;\n&quot;</span><span lang=EN-US
409 style='font-size:10.0pt;font-family:"Courier New";color:black'>))</span></p>
410 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
411 style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
412 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
413 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span
414 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>&quot;Line
415 breakes are not allowed in class names.&quot;</span><span lang=EN-US
416 style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></p>
417 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
418 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
419 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
420 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
421 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
422 null means, that the value is valid</span></p>
423 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
424 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
425 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
426 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
427 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>null</span></b><span
428 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></p>
429 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
430 style='font-size:10.0pt;font-family:"Courier New";color:black'>    }</span></p>
431 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
432 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
433 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
434 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
435 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
436 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
437 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>void</span></b><span
438 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
439 setValue(String value, IDirectEditingContext context) {</span></p>
440 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
441 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
442 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
443 set the new name for the MOF class</span></p>
444 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
445 style='font-size:10.0pt;font-family:"Courier New";color:black'>        PictogramElement
446 pe = context.getPictogramElement();</span></p>
447 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
448 style='font-size:10.0pt;font-family:"Courier New";color:black'>        EClass
449 eClass = (EClass) getBusinessObjectForPictogramElement(pe);</span></p>
450 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
451 style='font-size:10.0pt;font-family:"Courier New";color:black'>        eClass.setName(value);</span></p>
452 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
453 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
454 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
455 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
456 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
457 Explicitly update the shape to display the new value in the diagram</span></p>
458 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
459 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
460 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
jpasch6301b3d2010-09-14 11:51:34 +0000461 Note, that this might not be necessary in future versions of Graphiti</span></p>
mwenzb5dc2f92010-06-16 13:24:52 +0000462 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
463 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
464 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
465 (currently in discussion)</span></p>
466 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
467 style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></p>
468 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
469 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
470 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
471 we know, that pe is the Shape of the Text, so its container is the</span></p>
472 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
473 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
474 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>//
475 main shape of the EClass</span></p>
476 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
477 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
478 style='font-size:10.0pt;font-family:"Courier New";color:black'>updatePictogramElement(((Shape)
479 pe).getContainer());</span></p>
480 <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
481 font-family:"Courier New";color:black'>    }</span></p>
482 <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
483 font-family:"Courier New";color:black'>}</span></p>
484 <p class=MsoNormal style='text-autospace:none'><span style='color:black'>&nbsp;</span></p>
485 </td>
486 </tr>
487</table>
488
489<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
490
491<p class=MsoNormal><span lang=EN-GB style='color:black'>Additionally the
492feature provider has to deliver our newly created feature (overwrite the method
493<a
jpasch89c98532010-09-10 12:26:47 +0000494href="../../../javadoc/org/eclipse/graphiti/features/IFeatureProvider.html#getDirectEditingFeature(org.eclipse.graphiti.features.context.IDirectEditingContext)">getDirectEditingFeature</a>).
mwenzb5dc2f92010-06-16 13:24:52 +0000495</span></p>
496
497<p class=MsoNormal><span lang=EN-GB style='color:black'>This implementation can
498be seen here: </span></p>
499
500<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
501
502<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907
503 style='width:18.0cm;border-collapse:collapse'>
504 <tr>
505 <td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt;
506 padding:0cm 5.4pt 0cm 5.4pt'>
507 <p class=MsoNormal style='text-autospace:none'><span lang=EN-GB
508 style='font-size:10.0pt;font-family:"Courier New";color:#646464'>&nbsp;</span></p>
509 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
510 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><span
511 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p>
512 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
513 style='font-size:10.0pt;font-family:"Courier New";color:black'>    </span><b><span
514 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span
515 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
516 IDirectEditingFeature getDirectEditingFeature(</span></p>
517 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
518 style='font-size:10.0pt;font-family:"Courier New";color:black'>       
519 IDirectEditingContext context) {</span></p>
520 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
521 style='font-size:10.0pt;font-family:"Courier New";color:black'>        PictogramElement
522 pe = context.getPictogramElement();</span></p>
523 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
524 style='font-size:10.0pt;font-family:"Courier New";color:black'>        Object
525 bo = getBusinessObjectForPictogramElement(pe);</span></p>
526 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
527 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><b><span
528 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span
529 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
530 (bo </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";
531 color:#7F0055'>instanceof</span></b><span lang=EN-US style='font-size:10.0pt;
532 font-family:"Courier New";color:black'> EClass) {</span></p>
533 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
534 style='font-size:10.0pt;font-family:"Courier New";color:black'>            </span><b><span
535 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
536 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
537 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>new</span></b><span
538 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>
539 TutorialDirectEditEClassFeature(</span><b><span lang=EN-US style='font-size:
540 10.0pt;font-family:"Courier New";color:#7F0055'>this</span></b><span
541 lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>);</span></p>
542 <p class=MsoNormal style='text-autospace:none'><span lang=EN-US
543 style='font-size:10.0pt;font-family:"Courier New";color:black'>        </span><span
544 style='font-size:10.0pt;font-family:"Courier New";color:black'>}</span></p>
545 <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
546 font-family:"Courier New";color:black'>        </span><b><span
547 style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span
548 style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span
549 style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>super</span></b><span
550 style='font-size:10.0pt;font-family:"Courier New";color:black'>.getDirectEditingFeature(context);</span></p>
551 <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
552 font-family:"Courier New";color:black'>    }</span></p>
553 <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
554 font-family:"Courier New";color:black'>&nbsp;</span></p>
555 </td>
556 </tr>
557</table>
558
559<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
560
561<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
562
563<h2><span lang=EN-GB>Test: Edit the Name of a Class Directly In the Diagram</span></h2>
564
565<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
566
567<p class=MsoNormal><span lang=EN-GB style='color:black'>Now start the editor
568and test this new direct editing feature:</span></p>
569
570<ol style='margin-top:0cm' start=1 type=1>
571 <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>Create
572 or open a&nbsp; diagram and create an EClass “Address”</span></li>
573 <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>Click
574 on the class name and the value “Address” should become editable in the
575 text-editor</span></li>
576 <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>Change
577 the value to “Customer Address”. Now the editor should be highlighted and
578 an error-message (“no space allowed”) should be displayed in the
579 status-bar.</span></li>
580 <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>Change
581 the value to “CustomerAddress”. The highlight and error-message should
582 disappear. </span></li>
583 <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>Press
584 return or make the editor loose focus otherwise to overtake the edited
585 value, or press ESC to cancel the editing.</span></li>
586</ol>
587
588<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
589
590<p class=MsoNormal><span lang=EN-GB style='color:black'>&nbsp;</span></p>
591
592</div>
593<hr>
594 <a href="http://www.eclipse.org/legal/epl-v10.html" shape="rect">Copyright (c) SAP AG 2005, 2010.</a>
595
596</body>
597
598</html>