1 | /* |
2 | *Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.policies; |
5 | |
6 | import java.util.Collection; |
7 | import java.util.Collections; |
8 | import java.util.HashMap; |
9 | import java.util.Iterator; |
10 | import java.util.LinkedList; |
11 | import java.util.List; |
12 | import java.util.Map; |
13 | |
14 | import org.eclipse.core.runtime.IAdaptable; |
15 | import org.eclipse.emf.common.util.EList; |
16 | import org.eclipse.emf.ecore.EObject; |
17 | import org.eclipse.gef.EditPart; |
18 | import org.eclipse.gef.commands.Command; |
19 | import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; |
20 | import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand; |
21 | import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; |
22 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
23 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy; |
24 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest; |
25 | import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; |
26 | import org.eclipse.gmf.runtime.notation.Diagram; |
27 | import org.eclipse.gmf.runtime.notation.Edge; |
28 | import org.eclipse.gmf.runtime.notation.Node; |
29 | import org.eclipse.gmf.runtime.notation.View; |
30 | |
31 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyConnector; |
32 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
33 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyEventConnector; |
34 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyInfrastructureConnector; |
35 | import de.uka.ipd.sdq.pcm.core.composition.ProvidedDelegationConnector; |
36 | import de.uka.ipd.sdq.pcm.core.composition.RequiredDelegationConnector; |
37 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyConnectorEditPart; |
38 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyContextEditPart; |
39 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyEventConnectorEditPart; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyInfrastructureConnectorEditPart; |
41 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ComposedProvidingRequiringEntity2EditPart; |
42 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ComposedProvidingRequiringEntityEditPart; |
43 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.InfrastructureProvidedRoleEditPart; |
44 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.InfrastructureRequiredRoleEditPart; |
45 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationProvidedRole2EditPart; |
46 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationProvidedRoleEditPart; |
47 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationRequiredRole2EditPart; |
48 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationRequiredRoleEditPart; |
49 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ProvidedDelegationConnectorEditPart; |
50 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.RequiredDelegationConnectorEditPart; |
51 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.SinkRoleEditPart; |
52 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.SourceRoleEditPart; |
53 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelDiagramUpdater; |
54 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelLinkDescriptor; |
55 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelNodeDescriptor; |
56 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
57 | import de.uka.ipd.sdq.pcm.repository.Role; |
58 | |
59 | /** |
60 | * Edit policy for the element represented by the canvas. |
61 | * This is not the root element of the system model to be edited. |
62 | * |
63 | * @generated |
64 | */ |
65 | public class ComposedProvidingRequiringEntityCanonicalEditPolicy extends |
66 | CanonicalConnectionEditPolicy { |
67 | |
68 | /** |
69 | * Get the semantic children for the providing requiring entity. |
70 | * |
71 | * In the composite diagram, the root element is not represented |
72 | * by the canvas, but by the first included rectangle. |
73 | * To enable this, this edit policy needs to return the system |
74 | * and not the real children as done in the generated version of this |
75 | * method. |
76 | * |
77 | * @generated not |
78 | */ |
79 | protected List getSemanticChildrenList() { |
80 | List result = new LinkedList(); |
81 | EObject modelObject = ((View) getHost().getModel()).getElement(); |
82 | View viewObject = (View) getHost().getModel(); |
83 | result.add(modelObject); |
84 | return result; |
85 | } |
86 | |
87 | // TODO: Find out whether this method has been modified. |
88 | /** |
89 | */ |
90 | protected boolean shouldDeleteView(View view) { |
91 | if (view.getEAnnotation("Shortcut") != null) { //$NON-NLS-1$ |
92 | return view.isSetElement() |
93 | && (view.getElement() == null || view.getElement() |
94 | .eIsProxy()); |
95 | } |
96 | return false; |
97 | } |
98 | |
99 | /** |
100 | * @generated |
101 | */ |
102 | protected boolean isOrphaned(Collection semanticChildren, final View view) { |
103 | int visualID = PalladioComponentModelVisualIDRegistry.getVisualID(view); |
104 | switch (visualID) { |
105 | case ComposedProvidingRequiringEntity2EditPart.VISUAL_ID: |
106 | if (!semanticChildren.contains(view.getElement())) { |
107 | return true; |
108 | } |
109 | } |
110 | return false; |
111 | } |
112 | |
113 | /** |
114 | * @generated |
115 | */ |
116 | protected String getDefaultFactoryHint() { |
117 | return null; |
118 | } |
119 | |
120 | /** |
121 | * @generated |
122 | */ |
123 | protected List getSemanticConnectionsList() { |
124 | return Collections.EMPTY_LIST; |
125 | } |
126 | |
127 | /** |
128 | * @generated |
129 | */ |
130 | protected EObject getSourceElement(EObject relationship) { |
131 | return null; |
132 | } |
133 | |
134 | /** |
135 | * @generated |
136 | */ |
137 | protected EObject getTargetElement(EObject relationship) { |
138 | return null; |
139 | } |
140 | |
141 | /** |
142 | * @generated |
143 | */ |
144 | protected boolean shouldIncludeConnection(Edge connector, |
145 | Collection children) { |
146 | return false; |
147 | } |
148 | |
149 | /** |
150 | * @generated |
151 | */ |
152 | protected void refreshSemantic() { |
153 | List createdViews = new LinkedList(); |
154 | createdViews.addAll(refreshSemanticChildren()); |
155 | List createdConnectionViews = new LinkedList(); |
156 | createdConnectionViews.addAll(refreshSemanticConnections()); |
157 | createdConnectionViews.addAll(refreshConnections()); |
158 | |
159 | if (createdViews.size() > 1) { |
160 | // perform a layout of the container |
161 | DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host() |
162 | .getEditingDomain(), createdViews, host()); |
163 | executeCommand(new ICommandProxy(layoutCmd)); |
164 | } |
165 | |
166 | createdViews.addAll(createdConnectionViews); |
167 | makeViewsImmutable(createdViews); |
168 | } |
169 | |
170 | /** |
171 | * @generated |
172 | */ |
173 | private Collection refreshConnections() { |
174 | Map domain2NotationMap = new HashMap(); |
175 | Collection linkDescriptors = collectAllLinks(getDiagram(), |
176 | domain2NotationMap); |
177 | Collection existingLinks = new LinkedList(getDiagram().getEdges()); |
178 | for (Iterator linksIterator = existingLinks.iterator(); linksIterator |
179 | .hasNext();) { |
180 | Edge nextDiagramLink = (Edge) linksIterator.next(); |
181 | int diagramLinkVisualID = PalladioComponentModelVisualIDRegistry |
182 | .getVisualID(nextDiagramLink); |
183 | if (diagramLinkVisualID == -1) { |
184 | if (nextDiagramLink.getSource() != null |
185 | && nextDiagramLink.getTarget() != null) { |
186 | linksIterator.remove(); |
187 | } |
188 | continue; |
189 | } |
190 | EObject diagramLinkObject = nextDiagramLink.getElement(); |
191 | EObject diagramLinkSrc = nextDiagramLink.getSource().getElement(); |
192 | EObject diagramLinkDst = nextDiagramLink.getTarget().getElement(); |
193 | for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator |
194 | .hasNext();) { |
195 | PalladioComponentModelLinkDescriptor nextLinkDescriptor = (PalladioComponentModelLinkDescriptor) linkDescriptorsIterator |
196 | .next(); |
197 | if (diagramLinkObject == nextLinkDescriptor.getModelElement() |
198 | && diagramLinkSrc == nextLinkDescriptor.getSource() |
199 | && diagramLinkDst == nextLinkDescriptor |
200 | .getDestination() |
201 | && diagramLinkVisualID == nextLinkDescriptor |
202 | .getVisualID()) { |
203 | linksIterator.remove(); |
204 | linkDescriptorsIterator.remove(); |
205 | break; |
206 | } |
207 | } |
208 | } |
209 | deleteViews(existingLinks.iterator()); |
210 | return createConnections(linkDescriptors, domain2NotationMap); |
211 | } |
212 | |
213 | /** |
214 | * @generated |
215 | */ |
216 | private Collection collectAllLinks(View view, Map domain2NotationMap) { |
217 | if (!ComposedProvidingRequiringEntityEditPart.MODEL_ID |
218 | .equals(PalladioComponentModelVisualIDRegistry.getModelID(view))) { |
219 | return Collections.EMPTY_LIST; |
220 | } |
221 | Collection result = new LinkedList(); |
222 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) { |
223 | case ComposedProvidingRequiringEntityEditPart.VISUAL_ID: { |
224 | if (!domain2NotationMap.containsKey(view.getElement())) { |
225 | result |
226 | .addAll(PalladioComponentModelDiagramUpdater |
227 | .getComposedProvidingRequiringEntity_1000ContainedLinks(view)); |
228 | } |
229 | if (!domain2NotationMap.containsKey(view.getElement()) |
230 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
231 | domain2NotationMap.put(view.getElement(), view); |
232 | } |
233 | break; |
234 | } |
235 | case ComposedProvidingRequiringEntity2EditPart.VISUAL_ID: { |
236 | if (!domain2NotationMap.containsKey(view.getElement())) { |
237 | result |
238 | .addAll(PalladioComponentModelDiagramUpdater |
239 | .getComposedProvidingRequiringEntity_2002ContainedLinks(view)); |
240 | } |
241 | if (!domain2NotationMap.containsKey(view.getElement()) |
242 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
243 | domain2NotationMap.put(view.getElement(), view); |
244 | } |
245 | break; |
246 | } |
247 | case AssemblyContextEditPart.VISUAL_ID: { |
248 | if (!domain2NotationMap.containsKey(view.getElement())) { |
249 | result.addAll(PalladioComponentModelDiagramUpdater |
250 | .getAssemblyContext_3006ContainedLinks(view)); |
251 | } |
252 | if (!domain2NotationMap.containsKey(view.getElement()) |
253 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
254 | domain2NotationMap.put(view.getElement(), view); |
255 | } |
256 | break; |
257 | } |
258 | case OperationProvidedRoleEditPart.VISUAL_ID: { |
259 | if (!domain2NotationMap.containsKey(view.getElement())) { |
260 | result.addAll(PalladioComponentModelDiagramUpdater |
261 | .getOperationProvidedRole_3007ContainedLinks(view)); |
262 | } |
263 | if (!domain2NotationMap.containsKey(view.getElement()) |
264 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
265 | domain2NotationMap.put(view.getElement(), view); |
266 | } |
267 | break; |
268 | } |
269 | case OperationRequiredRoleEditPart.VISUAL_ID: { |
270 | if (!domain2NotationMap.containsKey(view.getElement())) { |
271 | result.addAll(PalladioComponentModelDiagramUpdater |
272 | .getOperationRequiredRole_3008ContainedLinks(view)); |
273 | } |
274 | if (!domain2NotationMap.containsKey(view.getElement()) |
275 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
276 | domain2NotationMap.put(view.getElement(), view); |
277 | } |
278 | break; |
279 | } |
280 | case SourceRoleEditPart.VISUAL_ID: { |
281 | if (!domain2NotationMap.containsKey(view.getElement())) { |
282 | result.addAll(PalladioComponentModelDiagramUpdater |
283 | .getSourceRole_3013ContainedLinks(view)); |
284 | } |
285 | if (!domain2NotationMap.containsKey(view.getElement()) |
286 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
287 | domain2NotationMap.put(view.getElement(), view); |
288 | } |
289 | break; |
290 | } |
291 | case SinkRoleEditPart.VISUAL_ID: { |
292 | if (!domain2NotationMap.containsKey(view.getElement())) { |
293 | result.addAll(PalladioComponentModelDiagramUpdater |
294 | .getSinkRole_3014ContainedLinks(view)); |
295 | } |
296 | if (!domain2NotationMap.containsKey(view.getElement()) |
297 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
298 | domain2NotationMap.put(view.getElement(), view); |
299 | } |
300 | break; |
301 | } |
302 | case InfrastructureProvidedRoleEditPart.VISUAL_ID: { |
303 | if (!domain2NotationMap.containsKey(view.getElement())) { |
304 | result |
305 | .addAll(PalladioComponentModelDiagramUpdater |
306 | .getInfrastructureProvidedRole_3015ContainedLinks(view)); |
307 | } |
308 | if (!domain2NotationMap.containsKey(view.getElement()) |
309 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
310 | domain2NotationMap.put(view.getElement(), view); |
311 | } |
312 | break; |
313 | } |
314 | case InfrastructureRequiredRoleEditPart.VISUAL_ID: { |
315 | if (!domain2NotationMap.containsKey(view.getElement())) { |
316 | result |
317 | .addAll(PalladioComponentModelDiagramUpdater |
318 | .getInfrastructureRequiredRole_3016ContainedLinks(view)); |
319 | } |
320 | if (!domain2NotationMap.containsKey(view.getElement()) |
321 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
322 | domain2NotationMap.put(view.getElement(), view); |
323 | } |
324 | break; |
325 | } |
326 | case OperationProvidedRole2EditPart.VISUAL_ID: { |
327 | if (!domain2NotationMap.containsKey(view.getElement())) { |
328 | result.addAll(PalladioComponentModelDiagramUpdater |
329 | .getOperationProvidedRole_3011ContainedLinks(view)); |
330 | } |
331 | if (!domain2NotationMap.containsKey(view.getElement()) |
332 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
333 | domain2NotationMap.put(view.getElement(), view); |
334 | } |
335 | break; |
336 | } |
337 | case OperationRequiredRole2EditPart.VISUAL_ID: { |
338 | if (!domain2NotationMap.containsKey(view.getElement())) { |
339 | result.addAll(PalladioComponentModelDiagramUpdater |
340 | .getOperationRequiredRole_3012ContainedLinks(view)); |
341 | } |
342 | if (!domain2NotationMap.containsKey(view.getElement()) |
343 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
344 | domain2NotationMap.put(view.getElement(), view); |
345 | } |
346 | break; |
347 | } |
348 | case AssemblyConnectorEditPart.VISUAL_ID: { |
349 | if (!domain2NotationMap.containsKey(view.getElement())) { |
350 | result.addAll(PalladioComponentModelDiagramUpdater |
351 | .getAssemblyConnector_4004ContainedLinks(view)); |
352 | } |
353 | if (!domain2NotationMap.containsKey(view.getElement()) |
354 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
355 | domain2NotationMap.put(view.getElement(), view); |
356 | } |
357 | break; |
358 | } |
359 | case AssemblyEventConnectorEditPart.VISUAL_ID: { |
360 | if (!domain2NotationMap.containsKey(view.getElement())) { |
361 | result.addAll(PalladioComponentModelDiagramUpdater |
362 | .getAssemblyEventConnector_4007ContainedLinks(view)); |
363 | } |
364 | if (!domain2NotationMap.containsKey(view.getElement()) |
365 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
366 | domain2NotationMap.put(view.getElement(), view); |
367 | } |
368 | break; |
369 | } |
370 | case RequiredDelegationConnectorEditPart.VISUAL_ID: { |
371 | if (!domain2NotationMap.containsKey(view.getElement())) { |
372 | result |
373 | .addAll(PalladioComponentModelDiagramUpdater |
374 | .getRequiredDelegationConnector_4005ContainedLinks(view)); |
375 | } |
376 | if (!domain2NotationMap.containsKey(view.getElement()) |
377 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
378 | domain2NotationMap.put(view.getElement(), view); |
379 | } |
380 | break; |
381 | } |
382 | case ProvidedDelegationConnectorEditPart.VISUAL_ID: { |
383 | if (!domain2NotationMap.containsKey(view.getElement())) { |
384 | result |
385 | .addAll(PalladioComponentModelDiagramUpdater |
386 | .getProvidedDelegationConnector_4006ContainedLinks(view)); |
387 | } |
388 | if (!domain2NotationMap.containsKey(view.getElement()) |
389 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
390 | domain2NotationMap.put(view.getElement(), view); |
391 | } |
392 | break; |
393 | } |
394 | case AssemblyInfrastructureConnectorEditPart.VISUAL_ID: { |
395 | if (!domain2NotationMap.containsKey(view.getElement())) { |
396 | result |
397 | .addAll(PalladioComponentModelDiagramUpdater |
398 | .getAssemblyInfrastructureConnector_4008ContainedLinks(view)); |
399 | } |
400 | if (!domain2NotationMap.containsKey(view.getElement()) |
401 | || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
402 | domain2NotationMap.put(view.getElement(), view); |
403 | } |
404 | break; |
405 | } |
406 | } |
407 | for (Iterator children = view.getChildren().iterator(); children |
408 | .hasNext();) { |
409 | result.addAll(collectAllLinks((View) children.next(), |
410 | domain2NotationMap)); |
411 | } |
412 | for (Iterator edges = view.getSourceEdges().iterator(); edges.hasNext();) { |
413 | result.addAll(collectAllLinks((View) edges.next(), |
414 | domain2NotationMap)); |
415 | } |
416 | return result; |
417 | } |
418 | |
419 | // newly created, may cause problems! |
420 | // well, it actually did cause problems and it will again in the future. so here follows the warning: :P |
421 | // --------------------------------------------------------------------------------------------------------------------- |
422 | // WARNING: THIS WILL BREAK EASYLY BY ADDING OR MODIFYING NEW CONNECTORS OR IF THE VISUAL ID OF COMPARTEMENTS CHANGES!!! |
423 | // --------------------------------------------------------------------------------------------------------------------- |
424 | /** |
425 | * This method is responsible for creating the links between the connectors/roles. |
426 | * The default behavior has been augmented so not only the role will be considered but the context, too. |
427 | * Modifications became necessary as multiple instances of one or more components in a composite component |
428 | * would otherwise lead to false connections in the graphical editors only regarding one element as source |
429 | * and one as destination. The second parameter of type Map doesn't need to be specified, as it will not be |
430 | * used, it's still there only for compatibility. |
431 | * |
432 | * @param linkDescriptors - collection of linkDescriptors |
433 | * @param domain2NotationMap - will not be considered, thus can be any value |
434 | * |
435 | * @return list of adapters |
436 | * |
437 | * This method has been manually modified. |
438 | * |
439 | * @generated NOT |
440 | */ |
441 | private Collection createConnections(Collection linkDescriptors, |
442 | Map domain2NotationMap) { |
443 | List adapters = new LinkedList(); |
444 | for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator |
445 | .hasNext();) { |
446 | final PalladioComponentModelLinkDescriptor nextLinkDescriptor = (PalladioComponentModelLinkDescriptor) linkDescriptorsIterator |
447 | .next(); |
448 | |
449 | // begin of modified code |
450 | EditPart sourceEditPart = null; |
451 | EditPart targetEditPart = null; |
452 | |
453 | if (nextLinkDescriptor.getModelElement() instanceof AssemblyConnector) { |
454 | AssemblyConnector ctx = (AssemblyConnector) nextLinkDescriptor |
455 | .getModelElement(); |
456 | sourceEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
457 | .getSource(), ctx |
458 | .getRequiringAssemblyContext_AssemblyConnector()); |
459 | targetEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
460 | .getDestination(), ctx |
461 | .getProvidingAssemblyContext_AssemblyConnector()); |
462 | } else if (nextLinkDescriptor.getModelElement() instanceof AssemblyEventConnector) { |
463 | AssemblyEventConnector ctx = (AssemblyEventConnector) nextLinkDescriptor |
464 | .getModelElement(); |
465 | sourceEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
466 | .getSource(), ctx |
467 | .getSourceAssemblyContext__AssemblyEventConnector()); |
468 | targetEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
469 | .getDestination(), ctx |
470 | .getSinkAssemblyContext__AssemblyEventConnector()); |
471 | } else if (nextLinkDescriptor.getModelElement() instanceof AssemblyInfrastructureConnector) { |
472 | AssemblyInfrastructureConnector ctx = (AssemblyInfrastructureConnector) nextLinkDescriptor |
473 | .getModelElement(); |
474 | sourceEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
475 | .getSource(), ctx |
476 | .getRequiringAssemblyContext__AssemblyInfrastructureConnector()); |
477 | targetEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
478 | .getDestination(), ctx |
479 | .getProvidingAssemblyContext__AssemblyInfrastructureConnector()); |
480 | } else if (nextLinkDescriptor.getModelElement() instanceof ProvidedDelegationConnector) { |
481 | ProvidedDelegationConnector ctx = (ProvidedDelegationConnector) nextLinkDescriptor |
482 | .getModelElement(); |
483 | sourceEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
484 | .getSource(), null); |
485 | targetEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
486 | .getDestination(), ctx |
487 | .getAssemblyContext_ProvidedDelegationConnector()); |
488 | } else if (nextLinkDescriptor.getModelElement() instanceof RequiredDelegationConnector) { |
489 | RequiredDelegationConnector ctx = (RequiredDelegationConnector) nextLinkDescriptor |
490 | .getModelElement(); |
491 | sourceEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
492 | .getSource(), ctx |
493 | .getAssemblyContext_RequiredDelegationConnector()); |
494 | targetEditPart = myGetEditPartFor((Role) nextLinkDescriptor |
495 | .getDestination(), null); |
496 | } |
497 | // end of modified code |
498 | if (sourceEditPart == null || targetEditPart == null) { |
499 | continue; |
500 | } |
501 | CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor( |
502 | nextLinkDescriptor.getSemanticAdapter(), String |
503 | .valueOf(nextLinkDescriptor.getVisualID()), |
504 | ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()) |
505 | .getDiagramPreferencesHint()); |
506 | CreateConnectionViewRequest ccr = new CreateConnectionViewRequest( |
507 | descriptor); |
508 | ccr.setType(RequestConstants.REQ_CONNECTION_START); |
509 | ccr.setSourceEditPart(sourceEditPart); |
510 | sourceEditPart.getCommand(ccr); |
511 | ccr.setTargetEditPart(targetEditPart); |
512 | ccr.setType(RequestConstants.REQ_CONNECTION_END); |
513 | Command cmd = targetEditPart.getCommand(ccr); |
514 | if (cmd != null && cmd.canExecute()) { |
515 | executeCommand(cmd); |
516 | IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject(); |
517 | if (viewAdapter != null) { |
518 | adapters.add(viewAdapter); |
519 | } |
520 | } |
521 | } |
522 | return adapters; |
523 | } |
524 | |
525 | /** |
526 | * @generated |
527 | */ |
528 | private EditPart getEditPart(EObject domainModelElement, |
529 | Map domain2NotationMap) { |
530 | View view = (View) domain2NotationMap.get(domainModelElement); |
531 | if (view != null) { |
532 | return (EditPart) getHost().getViewer().getEditPartRegistry().get( |
533 | view); |
534 | } |
535 | return null; |
536 | } |
537 | |
538 | /** |
539 | * Returns the EditPart for a given combination of Role and AssemblyContext. |
540 | * This is crucial for correctly displaying links if there are multiple instances |
541 | * of the same component in an assemblyContext, hence multiple times the same role (with identical ID). |
542 | * This method has been most likely manually added. |
543 | * |
544 | * @param modelElement - Role to be searched |
545 | * @param ctx - AssemblyContext to be searched |
546 | * @return EditPart that belongs to the Role in the AssemblyContext if existent, null otherwise |
547 | * |
548 | * @generated not |
549 | */ |
550 | private EditPart myGetEditPartFor(Role modelElement, AssemblyContext ctx) { |
551 | View view = null; |
552 | Diagram dia = getDiagram(); |
553 | Node pseudoNode = (Node) dia.getChildren().get(0); |
554 | if (ctx == null) { |
555 | for (Object n : pseudoNode.getChildren()) { |
556 | if (n instanceof Node) { |
557 | Node node = (Node) n; |
558 | if (!node.getType().equals("7002") |
559 | && node.getElement() == modelElement) |
560 | view = node; |
561 | } |
562 | } |
563 | } else { |
564 | Node compartment = getCompartmentNode(pseudoNode.getChildren()); |
565 | for (Object n : compartment.getChildren()) { |
566 | if (n instanceof Node) { |
567 | Node node = (Node) n; |
568 | if (node.getElement() == ctx) { |
569 | view = getRoleChild(node, modelElement); |
570 | } |
571 | } |
572 | } |
573 | } |
574 | if (view != null) { |
575 | return (EditPart) getHost().getViewer().getEditPartRegistry().get( |
576 | view); |
577 | } |
578 | return null; |
579 | } |
580 | |
581 | /** |
582 | * Returns the the child node of myNode, thats element attribute references modelElement. |
583 | * This method was manually added. |
584 | * |
585 | * @param myNode - parent node whose children will be checked |
586 | * @param modelElement - role for which to search |
587 | * @return node - the child node of myNode, thats element attribute references the role modelElement, |
588 | * if existent, null otherwise |
589 | * |
590 | * @generated NOT |
591 | */ |
592 | private View getRoleChild(Node myNode, Role modelElement) { |
593 | for (Object n : myNode.getChildren()) { |
594 | if (n instanceof Node) { |
595 | Node node = (Node) n; |
596 | if (node.getElement() == modelElement) { |
597 | return node; |
598 | } |
599 | } |
600 | } |
601 | return null; |
602 | } |
603 | |
604 | /** |
605 | * Returns one CompartmentNode out of a list of nodes if there is at least one included. |
606 | * This method was manually added. |
607 | * |
608 | * @param children - List of children to be checked |
609 | * @return node - one compartementNode if there is a node of that type, null otherwise |
610 | * |
611 | * @generated NOT |
612 | */ |
613 | private Node getCompartmentNode(EList nodeList) { |
614 | for (Object n : nodeList) { |
615 | if (n instanceof Node) { |
616 | Node node = (Node) n; |
617 | if (node.getType().equals("7002")) |
618 | return node; |
619 | |
620 | } |
621 | } |
622 | return null; |
623 | } |
624 | |
625 | /** |
626 | * @generated |
627 | */ |
628 | private Diagram getDiagram() { |
629 | return ((View) getHost().getModel()).getDiagram(); |
630 | } |
631 | |
632 | } |