1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
package org.argouml.uml.diagram.static_structure.ui; |
41 | |
|
42 | |
import java.awt.Rectangle; |
43 | |
import java.beans.PropertyVetoException; |
44 | |
import java.util.Collection; |
45 | |
|
46 | |
import javax.swing.Action; |
47 | |
|
48 | |
import org.apache.log4j.Logger; |
49 | |
import org.argouml.i18n.Translator; |
50 | |
import org.argouml.model.CoreFactory; |
51 | |
import org.argouml.model.Model; |
52 | |
import org.argouml.uml.CommentEdge; |
53 | |
import org.argouml.uml.diagram.ArgoDiagram; |
54 | |
import org.argouml.uml.diagram.DiagramEdgeSettings; |
55 | |
import org.argouml.uml.diagram.DiagramElement; |
56 | |
import org.argouml.uml.diagram.DiagramSettings; |
57 | |
import org.argouml.uml.diagram.deployment.ui.FigComponent; |
58 | |
import org.argouml.uml.diagram.deployment.ui.FigComponentInstance; |
59 | |
import org.argouml.uml.diagram.deployment.ui.FigMNode; |
60 | |
import org.argouml.uml.diagram.deployment.ui.FigNodeInstance; |
61 | |
import org.argouml.uml.diagram.deployment.ui.FigObject; |
62 | |
import org.argouml.uml.diagram.static_structure.ClassDiagramGraphModel; |
63 | |
import org.argouml.uml.diagram.ui.FigAbstraction; |
64 | |
import org.argouml.uml.diagram.ui.FigAssociation; |
65 | |
import org.argouml.uml.diagram.ui.FigAssociationClass; |
66 | |
import org.argouml.uml.diagram.ui.FigAssociationEnd; |
67 | |
import org.argouml.uml.diagram.ui.FigDependency; |
68 | |
import org.argouml.uml.diagram.ui.FigEdgeModelElement; |
69 | |
import org.argouml.uml.diagram.ui.FigGeneralization; |
70 | |
import org.argouml.uml.diagram.ui.FigNodeModelElement; |
71 | |
import org.argouml.uml.diagram.ui.FigPermission; |
72 | |
import org.argouml.uml.diagram.ui.FigUsage; |
73 | |
import org.argouml.uml.diagram.ui.ModeCreateDependency; |
74 | |
import org.argouml.uml.diagram.ui.ModeCreatePermission; |
75 | |
import org.argouml.uml.diagram.ui.ModeCreateUsage; |
76 | |
import org.argouml.uml.diagram.ui.UMLDiagram; |
77 | |
import org.argouml.uml.diagram.use_case.ui.FigActor; |
78 | |
import org.argouml.uml.diagram.use_case.ui.FigUseCase; |
79 | |
import org.argouml.uml.ui.foundation.core.ActionAddAttribute; |
80 | |
import org.argouml.uml.ui.foundation.core.ActionAddOperation; |
81 | |
import org.argouml.util.ToolBarUtility; |
82 | |
import org.tigris.gef.base.Layer; |
83 | |
import org.tigris.gef.base.LayerPerspective; |
84 | |
import org.tigris.gef.base.LayerPerspectiveMutable; |
85 | |
import org.tigris.gef.presentation.FigEdge; |
86 | |
import org.tigris.gef.presentation.FigNode; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | 900 | public class UMLClassDiagram extends UMLDiagram { |
94 | |
|
95 | |
private static final long serialVersionUID = -9192325790126361563L; |
96 | |
|
97 | 900 | private static final Logger LOG = Logger.getLogger(UMLClassDiagram.class); |
98 | |
|
99 | |
|
100 | |
|
101 | |
private Action actionAssociationClass; |
102 | |
private Action actionClass; |
103 | |
private Action actionInterface; |
104 | |
private Action actionDependency; |
105 | |
private Action actionPermission; |
106 | |
private Action actionUsage; |
107 | |
private Action actionLink; |
108 | |
private Action actionGeneralization; |
109 | |
private Action actionRealization; |
110 | |
private Action actionPackage; |
111 | |
private Action actionModel; |
112 | |
private Action actionSubsystem; |
113 | |
private Action actionAssociation; |
114 | |
private Action actionAssociationEnd; |
115 | |
private Action actionAggregation; |
116 | |
private Action actionComposition; |
117 | |
private Action actionUniAssociation; |
118 | |
private Action actionUniAggregation; |
119 | |
private Action actionUniComposition; |
120 | |
private Action actionDataType; |
121 | |
private Action actionEnumeration; |
122 | |
private Action actionStereotype; |
123 | |
private Action actionSignal; |
124 | |
private Action actionException; |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
@Deprecated |
132 | |
public UMLClassDiagram() { |
133 | 0 | super(new ClassDiagramGraphModel()); |
134 | 0 | } |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public UMLClassDiagram(String name, Object namespace) { |
145 | 0 | super(name, namespace, new ClassDiagramGraphModel()); |
146 | 0 | } |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public UMLClassDiagram(Object m) { |
155 | |
|
156 | 1028 | super("", m, new ClassDiagramGraphModel()); |
157 | 1028 | String name = getNewDiagramName(); |
158 | |
try { |
159 | 1028 | setName(name); |
160 | 0 | } catch (PropertyVetoException pve) { |
161 | 0 | LOG.warn("Generated diagram name '" + name |
162 | |
+ "' was vetoed by setName"); |
163 | 1028 | } |
164 | 1028 | } |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
public void setNamespace(Object ns) { |
170 | 1028 | if (!Model.getFacade().isANamespace(ns)) { |
171 | 0 | LOG.error("Illegal argument. " |
172 | |
+ "Object " + ns + " is not a namespace"); |
173 | 0 | throw new IllegalArgumentException("Illegal argument. " |
174 | |
+ "Object " + ns |
175 | |
+ " is not a namespace"); |
176 | |
} |
177 | 1028 | boolean init = (null == getNamespace()); |
178 | 1028 | super.setNamespace(ns); |
179 | 1028 | ClassDiagramGraphModel gm = (ClassDiagramGraphModel) getGraphModel(); |
180 | 1028 | gm.setHomeModel(ns); |
181 | 1028 | if (init) { |
182 | 1028 | LayerPerspective lay = |
183 | |
new LayerPerspectiveMutable(Model.getFacade().getName(ns), gm); |
184 | 1028 | ClassDiagramRenderer rend = new ClassDiagramRenderer(); |
185 | 1028 | lay.setGraphNodeRenderer(rend); |
186 | 1028 | lay.setGraphEdgeRenderer(rend); |
187 | 1028 | setLayer(lay); |
188 | |
} |
189 | 1028 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
protected Object[] getUmlActions() { |
195 | 1028 | Object[] actions = { |
196 | |
getPackageActions(), |
197 | |
getActionClass(), |
198 | |
null, |
199 | |
getAssociationActions(), |
200 | |
getAggregationActions(), |
201 | |
getCompositionActions(), |
202 | |
getActionAssociationEnd(), |
203 | |
getActionGeneralization(), |
204 | |
null, |
205 | |
getActionInterface(), |
206 | |
getActionRealization(), |
207 | |
null, |
208 | |
getDependencyActions(), |
209 | |
null, |
210 | |
ActionAddAttribute.getTargetFollower(), |
211 | |
ActionAddOperation.getTargetFollower(), |
212 | |
getActionAssociationClass(), |
213 | |
null, |
214 | |
getDataTypeActions(), |
215 | |
}; |
216 | |
|
217 | 1028 | return actions; |
218 | |
} |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
private Object[] getDataTypeActions() { |
224 | 1028 | Object[] actions = { |
225 | |
getActionDataType(), |
226 | |
getActionEnumeration(), |
227 | |
getActionStereotype(), |
228 | |
getActionSignal(), |
229 | |
getActionException(), |
230 | |
}; |
231 | 1028 | ToolBarUtility.manageDefault(actions, "diagram.class.datatype"); |
232 | 1028 | return actions; |
233 | |
} |
234 | |
|
235 | |
private Object getPackageActions() { |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
if (false) { |
243 | |
Object[] actions = { |
244 | |
getActionPackage(), |
245 | |
getActionModel(), |
246 | |
getActionSubsystem(), |
247 | |
}; |
248 | |
ToolBarUtility.manageDefault(actions, "diagram.class.package"); |
249 | |
return actions; |
250 | |
} else { |
251 | 1028 | return getActionPackage(); |
252 | |
} |
253 | |
} |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
private Object[] getDependencyActions() { |
260 | 1028 | Object[] actions = { |
261 | |
getActionDependency(), |
262 | |
getActionPermission(), |
263 | |
getActionUsage(), |
264 | |
}; |
265 | 1028 | ToolBarUtility.manageDefault(actions, "diagram.class.dependency"); |
266 | 1028 | return actions; |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
private Object[] getAssociationActions() { |
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | 1028 | Object[] actions = { |
280 | |
getActionAssociation(), |
281 | |
getActionUniAssociation(), |
282 | |
}; |
283 | 1028 | ToolBarUtility.manageDefault(actions, "diagram.class.association"); |
284 | 1028 | return actions; |
285 | |
} |
286 | |
|
287 | |
private Object[] getAggregationActions() { |
288 | 1028 | Object[] actions = { |
289 | |
getActionAggregation(), |
290 | |
getActionUniAggregation(), |
291 | |
}; |
292 | 1028 | ToolBarUtility.manageDefault(actions, "diagram.class.aggregation"); |
293 | 1028 | return actions; |
294 | |
} |
295 | |
|
296 | |
private Object[] getCompositionActions() { |
297 | 1028 | Object[] actions = { |
298 | |
getActionComposition(), |
299 | |
getActionUniComposition(), |
300 | |
}; |
301 | 1028 | ToolBarUtility.manageDefault(actions, "diagram.class.composition"); |
302 | 1028 | return actions; |
303 | |
} |
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
public String getLabelName() { |
309 | 1039 | return Translator.localize("label.class-diagram"); |
310 | |
} |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
protected Action getActionAggregation() { |
316 | 1028 | if (actionAggregation == null) { |
317 | 1028 | actionAggregation = |
318 | |
makeCreateAssociationAction( |
319 | |
Model.getAggregationKind().getAggregate(), |
320 | |
false, |
321 | |
"button.new-aggregation"); |
322 | |
} |
323 | 1028 | return actionAggregation; |
324 | |
} |
325 | |
|
326 | |
|
327 | |
|
328 | |
protected Action getActionAssociation() { |
329 | 1028 | if (actionAssociation == null) { |
330 | 1028 | actionAssociation = |
331 | |
makeCreateAssociationAction( |
332 | |
Model.getAggregationKind().getNone(), |
333 | |
false, "button.new-association"); |
334 | |
} |
335 | 1028 | return actionAssociation; |
336 | |
} |
337 | |
|
338 | |
|
339 | |
|
340 | |
protected Action getActionAssociationEnd() { |
341 | 1028 | if (actionAssociationEnd == null) { |
342 | 1028 | actionAssociationEnd = |
343 | |
makeCreateAssociationEndAction("button.new-association-end"); |
344 | |
} |
345 | 1028 | return actionAssociationEnd; |
346 | |
} |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
protected Action getActionClass() { |
352 | 1028 | if (actionClass == null) { |
353 | 1028 | actionClass = |
354 | |
makeCreateNodeAction(Model.getMetaTypes().getUMLClass(), |
355 | |
"button.new-class"); |
356 | |
} |
357 | |
|
358 | 1028 | return actionClass; |
359 | |
} |
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
protected Action getActionAssociationClass() { |
365 | 1028 | if (actionAssociationClass == null) { |
366 | 1028 | actionAssociationClass = |
367 | |
makeCreateAssociationClassAction( |
368 | |
"button.new-associationclass"); |
369 | |
} |
370 | 1028 | return actionAssociationClass; |
371 | |
} |
372 | |
|
373 | |
|
374 | |
|
375 | |
protected Action getActionComposition() { |
376 | 1028 | if (actionComposition == null) { |
377 | 1028 | actionComposition = |
378 | |
makeCreateAssociationAction( |
379 | |
Model.getAggregationKind().getComposite(), |
380 | |
false, "button.new-composition"); |
381 | |
} |
382 | 1028 | return actionComposition; |
383 | |
} |
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
protected Action getActionDependency() { |
389 | 1028 | if (actionDependency == null) { |
390 | 1028 | actionDependency = makeCreateDependencyAction( |
391 | |
ModeCreateDependency.class, |
392 | |
Model.getMetaTypes().getDependency(), |
393 | |
"button.new-dependency"); |
394 | |
} |
395 | 1028 | return actionDependency; |
396 | |
} |
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
protected Action getActionGeneralization() { |
402 | 1028 | if (actionGeneralization == null) { |
403 | 1028 | actionGeneralization = makeCreateGeneralizationAction(); |
404 | |
} |
405 | |
|
406 | 1028 | return actionGeneralization; |
407 | |
} |
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
protected Action getActionInterface() { |
413 | 1028 | if (actionInterface == null) { |
414 | 1028 | actionInterface = |
415 | |
makeCreateNodeAction( |
416 | |
Model.getMetaTypes().getInterface(), |
417 | |
"button.new-interface"); |
418 | |
} |
419 | 1028 | return actionInterface; |
420 | |
} |
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
protected Action getActionLink() { |
426 | 0 | if (actionLink == null) { |
427 | 0 | actionLink = |
428 | |
makeCreateEdgeAction(Model.getMetaTypes().getLink(), "Link"); |
429 | |
} |
430 | |
|
431 | 0 | return actionLink; |
432 | |
} |
433 | |
|
434 | |
|
435 | |
|
436 | |
protected Action getActionModel() { |
437 | 0 | if (actionModel == null) { |
438 | 0 | actionModel = |
439 | |
makeCreateNodeAction(Model.getMetaTypes().getModel(), "Model"); |
440 | |
} |
441 | |
|
442 | 0 | return actionModel; |
443 | |
} |
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
protected Action getActionPackage() { |
449 | 1028 | if (actionPackage == null) { |
450 | 1028 | actionPackage = |
451 | |
makeCreateNodeAction(Model.getMetaTypes().getPackage(), |
452 | |
"button.new-package"); |
453 | |
} |
454 | |
|
455 | 1028 | return actionPackage; |
456 | |
} |
457 | |
|
458 | |
|
459 | |
|
460 | |
protected Action getActionPermission() { |
461 | 1028 | if (actionPermission == null) { |
462 | 1028 | actionPermission = makeCreateDependencyAction( |
463 | |
ModeCreatePermission.class, |
464 | |
Model.getMetaTypes().getPackageImport(), |
465 | |
"button.new-permission"); |
466 | |
} |
467 | |
|
468 | 1028 | return actionPermission; |
469 | |
} |
470 | |
|
471 | |
|
472 | |
|
473 | |
|
474 | |
protected Action getActionRealization() { |
475 | 1028 | if (actionRealization == null) { |
476 | 1028 | actionRealization = |
477 | |
makeCreateEdgeAction( |
478 | |
Model.getMetaTypes().getAbstraction(), |
479 | |
"button.new-realization"); |
480 | |
} |
481 | |
|
482 | 1028 | return actionRealization; |
483 | |
} |
484 | |
|
485 | |
|
486 | |
|
487 | |
|
488 | |
protected Action getActionSubsystem() { |
489 | 0 | if (actionSubsystem == null) { |
490 | 0 | actionSubsystem = |
491 | |
makeCreateNodeAction( |
492 | |
Model.getMetaTypes().getSubsystem(), |
493 | |
"Subsystem"); |
494 | |
} |
495 | 0 | return actionSubsystem; |
496 | |
} |
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
protected Action getActionUniAggregation() { |
502 | 1028 | if (actionUniAggregation == null) { |
503 | 1028 | actionUniAggregation = |
504 | |
makeCreateAssociationAction( |
505 | |
Model.getAggregationKind().getAggregate(), |
506 | |
true, |
507 | |
"button.new-uniaggregation"); |
508 | |
} |
509 | 1028 | return actionUniAggregation; |
510 | |
} |
511 | |
|
512 | |
|
513 | |
|
514 | |
|
515 | |
protected Action getActionUniAssociation() { |
516 | 1028 | if (actionUniAssociation == null) { |
517 | 1028 | actionUniAssociation = |
518 | |
makeCreateAssociationAction( |
519 | |
Model.getAggregationKind().getNone(), |
520 | |
true, |
521 | |
"button.new-uniassociation"); |
522 | |
} |
523 | 1028 | return actionUniAssociation; |
524 | |
} |
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
protected Action getActionUniComposition() { |
530 | 1028 | if (actionUniComposition == null) { |
531 | 1028 | actionUniComposition = |
532 | |
makeCreateAssociationAction( |
533 | |
Model.getAggregationKind().getComposite(), |
534 | |
true, |
535 | |
"button.new-unicomposition"); |
536 | |
} |
537 | 1028 | return actionUniComposition; |
538 | |
} |
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
protected Action getActionUsage() { |
544 | 1028 | if (actionUsage == null) { |
545 | 1028 | actionUsage = makeCreateDependencyAction( |
546 | |
ModeCreateUsage.class, |
547 | |
Model.getMetaTypes().getUsage(), |
548 | |
"button.new-usage"); |
549 | |
} |
550 | 1028 | return actionUsage; |
551 | |
} |
552 | |
|
553 | |
|
554 | |
|
555 | |
|
556 | |
private Action getActionDataType() { |
557 | 1028 | if (actionDataType == null) { |
558 | 1028 | actionDataType = |
559 | |
makeCreateNodeAction(Model.getMetaTypes().getDataType(), |
560 | |
"button.new-datatype"); |
561 | |
} |
562 | 1028 | return actionDataType; |
563 | |
} |
564 | |
|
565 | |
|
566 | |
|
567 | |
|
568 | |
private Action getActionEnumeration() { |
569 | 1028 | if (actionEnumeration == null) { |
570 | 1028 | actionEnumeration = |
571 | |
makeCreateNodeAction(Model.getMetaTypes().getEnumeration(), |
572 | |
"button.new-enumeration"); |
573 | |
} |
574 | 1028 | return actionEnumeration; |
575 | |
} |
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
private Action getActionStereotype() { |
581 | 1028 | if (actionStereotype == null) { |
582 | 1028 | actionStereotype = |
583 | |
makeCreateNodeAction(Model.getMetaTypes().getStereotype(), |
584 | |
"button.new-stereotype"); |
585 | |
} |
586 | 1028 | return actionStereotype; |
587 | |
} |
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | |
private Action getActionSignal() { |
593 | 1028 | if (actionSignal == null) { |
594 | 1028 | actionSignal = |
595 | |
makeCreateNodeAction(Model.getMetaTypes().getSignal(), |
596 | |
"button.new-signal"); |
597 | |
} |
598 | 1028 | return actionSignal; |
599 | |
} |
600 | |
|
601 | |
|
602 | |
|
603 | |
|
604 | |
private Action getActionException() { |
605 | 1028 | if (actionException == null) { |
606 | 1028 | actionException = |
607 | |
makeCreateNodeAction(Model.getMetaTypes().getException(), |
608 | |
"button.new-exception"); |
609 | |
} |
610 | 1028 | return actionException; |
611 | |
} |
612 | |
|
613 | |
|
614 | |
|
615 | |
public boolean isRelocationAllowed(Object base) { |
616 | 0 | return Model.getFacade().isANamespace(base); |
617 | |
} |
618 | |
|
619 | |
public Collection getRelocationCandidates(Object root) { |
620 | 0 | return |
621 | |
Model.getModelManagementHelper().getAllModelElementsOfKindWithModel( |
622 | |
root, Model.getMetaTypes().getNamespace()); |
623 | |
} |
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
public boolean relocate(Object base) { |
629 | 0 | setNamespace(base); |
630 | 0 | damage(); |
631 | 0 | return true; |
632 | |
} |
633 | |
|
634 | |
public void encloserChanged(FigNode enclosed, FigNode oldEncloser, |
635 | |
FigNode newEncloser) { |
636 | |
|
637 | 0 | } |
638 | |
|
639 | |
@Override |
640 | |
public boolean doesAccept(Object objectToAccept) { |
641 | 0 | if (objectToAccept instanceof CommentEdge) { |
642 | 0 | return true; |
643 | 0 | } else if (Model.getFacade().isAClass(objectToAccept)) { |
644 | 0 | return true; |
645 | 0 | } else if (Model.getFacade().isAInterface(objectToAccept)) { |
646 | 0 | return true; |
647 | 0 | } else if (Model.getFacade().isAModel(objectToAccept)) { |
648 | 0 | return true; |
649 | 0 | } else if (Model.getFacade().isASubsystem(objectToAccept)) { |
650 | 0 | return true; |
651 | 0 | } else if (Model.getFacade().isAPackage(objectToAccept)) { |
652 | 0 | return true; |
653 | 0 | } else if (Model.getFacade().isAComment(objectToAccept)) { |
654 | 0 | return true; |
655 | 0 | } else if (Model.getFacade().isAAssociation(objectToAccept)) { |
656 | 0 | return true; |
657 | 0 | } else if (Model.getFacade().isAEnumeration(objectToAccept)) { |
658 | 0 | return true; |
659 | 0 | } else if (Model.getFacade().isADataType(objectToAccept)) { |
660 | 0 | return true; |
661 | 0 | } else if (Model.getFacade().isAStereotype(objectToAccept)) { |
662 | 0 | return true; |
663 | 0 | } else if (Model.getFacade().isAException(objectToAccept)) { |
664 | 0 | return true; |
665 | 0 | } else if (Model.getFacade().isASignal(objectToAccept)) { |
666 | 0 | return true; |
667 | 0 | } else if (Model.getFacade().isAActor(objectToAccept)) { |
668 | 0 | return true; |
669 | 0 | } else if (Model.getFacade().isAUseCase(objectToAccept)) { |
670 | 0 | return true; |
671 | 0 | } else if (Model.getFacade().isAObject(objectToAccept)) { |
672 | 0 | return true; |
673 | 0 | } else if (Model.getFacade().isANodeInstance(objectToAccept)) { |
674 | 0 | return true; |
675 | 0 | } else if (Model.getFacade().isAComponentInstance(objectToAccept)) { |
676 | 0 | return true; |
677 | 0 | } else if (Model.getFacade().isANode(objectToAccept)) { |
678 | 0 | return true; |
679 | 0 | } else if (Model.getFacade().isAComponent(objectToAccept)) { |
680 | 0 | return true; |
681 | 0 | } else if (Model.getFacade().isAAssociationEnd(objectToAccept)) { |
682 | 0 | return true; |
683 | 0 | } else if (Model.getFacade().isADependency(objectToAccept)) { |
684 | 0 | return true; |
685 | 0 | } else if (Model.getFacade().isAGeneralization(objectToAccept)) { |
686 | 0 | return true; |
687 | |
} |
688 | 0 | return false; |
689 | |
|
690 | |
} |
691 | |
|
692 | |
public DiagramElement createDiagramElement( |
693 | |
final Object modelElement, |
694 | |
final Rectangle bounds) { |
695 | |
|
696 | 0 | FigNodeModelElement figNode = null; |
697 | 0 | FigEdge figEdge = null; |
698 | |
|
699 | 0 | DiagramSettings settings = getDiagramSettings(); |
700 | |
|
701 | 0 | if (Model.getFacade().isAAssociationClass(modelElement)) { |
702 | 0 | Object[] associationEnds = |
703 | |
Model.getFacade().getConnections(modelElement).toArray(); |
704 | 0 | figEdge = new FigAssociationClass( |
705 | |
new DiagramEdgeSettings( |
706 | |
modelElement, |
707 | |
associationEnds[0], |
708 | |
associationEnds[1]), |
709 | |
settings); |
710 | 0 | FigNode sourceFig = |
711 | |
getFigNodeForAssociationEnd(associationEnds[0]); |
712 | 0 | FigNode destFig = |
713 | |
getFigNodeForAssociationEnd(associationEnds[1]); |
714 | 0 | figEdge.setSourceFigNode(sourceFig); |
715 | 0 | figEdge.setSourcePortFig(sourceFig); |
716 | 0 | figEdge.setDestFigNode(destFig); |
717 | 0 | figEdge.setDestPortFig(destFig); |
718 | 0 | } else if (Model.getFacade().isAAssociationEnd(modelElement)) { |
719 | 0 | figEdge = new FigAssociationEnd(modelElement, settings); |
720 | 0 | Model.getFacade().getAssociation(modelElement); |
721 | 0 | FigNode associationFN = |
722 | |
(FigNode) getLayer().presentationFor( |
723 | |
Model.getFacade().getAssociation(modelElement)); |
724 | 0 | FigNode classifierFN = |
725 | |
(FigNode) getLayer().presentationFor(Model.getFacade().getType(modelElement)); |
726 | |
|
727 | 0 | figEdge.setSourcePortFig(associationFN); |
728 | 0 | figEdge.setSourceFigNode(associationFN); |
729 | 0 | figEdge.setDestPortFig(classifierFN); |
730 | 0 | figEdge.setDestFigNode(classifierFN); |
731 | 0 | } else if (Model.getFacade().isAAssociation(modelElement) |
732 | |
&& !Model.getFacade().isANaryAssociation(modelElement)) { |
733 | 0 | Object[] associationEnds = |
734 | |
Model.getFacade().getConnections(modelElement).toArray(); |
735 | 0 | figEdge = new FigAssociation( |
736 | |
new DiagramEdgeSettings( |
737 | |
modelElement, |
738 | |
associationEnds[0], |
739 | |
associationEnds[1]), |
740 | |
settings); |
741 | 0 | FigNode sourceFig = |
742 | |
getFigNodeForAssociationEnd(associationEnds[0]); |
743 | 0 | FigNode destFig = |
744 | |
getFigNodeForAssociationEnd(associationEnds[1]); |
745 | 0 | figEdge.setSourceFigNode(sourceFig); |
746 | 0 | figEdge.setSourcePortFig(sourceFig); |
747 | 0 | figEdge.setDestFigNode(destFig); |
748 | 0 | figEdge.setDestPortFig(destFig); |
749 | 0 | } else if (Model.getFacade().isALink(modelElement)) { |
750 | 0 | figEdge = new FigLink(modelElement, settings); |
751 | 0 | Collection linkEndsColn = Model.getFacade().getConnections(modelElement); |
752 | |
|
753 | 0 | Object[] linkEnds = linkEndsColn.toArray(); |
754 | 0 | Object fromInst = Model.getFacade().getInstance(linkEnds[0]); |
755 | 0 | Object toInst = Model.getFacade().getInstance(linkEnds[1]); |
756 | |
|
757 | 0 | FigNode fromFN = (FigNode) getLayer().presentationFor(fromInst); |
758 | 0 | FigNode toFN = (FigNode) getLayer().presentationFor(toInst); |
759 | 0 | figEdge.setSourcePortFig(fromFN); |
760 | 0 | figEdge.setSourceFigNode(fromFN); |
761 | 0 | figEdge.setDestPortFig(toFN); |
762 | 0 | figEdge.setDestFigNode(toFN); |
763 | 0 | figEdge.getFig().setLayer(getLayer()); |
764 | 0 | } else if (Model.getFacade().isAGeneralization(modelElement)) { |
765 | 0 | figEdge = new FigGeneralization(modelElement, settings); |
766 | |
|
767 | 0 | Object supplier = |
768 | |
(Model.getFacade().getSpecific(modelElement)); |
769 | 0 | Object client = |
770 | |
(Model.getFacade().getGeneral(modelElement)); |
771 | |
|
772 | 0 | FigNode supFN = (FigNode) getLayer().presentationFor(supplier); |
773 | 0 | FigNode cliFN = (FigNode) getLayer().presentationFor(client); |
774 | |
|
775 | 0 | figEdge.setSourceFigNode(supFN); |
776 | 0 | figEdge.setSourcePortFig(supFN); |
777 | 0 | figEdge.setDestFigNode(cliFN); |
778 | 0 | figEdge.setDestPortFig(cliFN); |
779 | 0 | } else if (Model.getFacade().isADependency(modelElement)) { |
780 | |
|
781 | 0 | if (Model.getFacade().isAPackageImport(modelElement)) { |
782 | 0 | figEdge = new FigPermission(modelElement, settings); |
783 | 0 | } else if (Model.getFacade().isAUsage(modelElement)) { |
784 | 0 | figEdge = new FigUsage(modelElement, settings); |
785 | 0 | } else if (Model.getFacade().isAAbstraction(modelElement)) { |
786 | 0 | figEdge = new FigAbstraction(modelElement, settings); |
787 | |
} else { |
788 | |
|
789 | 0 | String name = ""; |
790 | 0 | for (Object stereotype : Model.getFacade().getStereotypes(modelElement)) { |
791 | 0 | name = Model.getFacade().getName(stereotype); |
792 | 0 | if (CoreFactory.REALIZE_STEREOTYPE.equals(name)) { |
793 | 0 | break; |
794 | |
} |
795 | |
} |
796 | 0 | if (CoreFactory.REALIZE_STEREOTYPE.equals(name)) { |
797 | |
|
798 | |
|
799 | |
|
800 | |
|
801 | 0 | figEdge = new FigAbstraction(modelElement, settings); |
802 | |
} else { |
803 | 0 | figEdge = new FigDependency(modelElement, settings); |
804 | |
} |
805 | |
} |
806 | 0 | Object supplier = |
807 | |
((Model.getFacade().getSuppliers(modelElement).toArray())[0]); |
808 | 0 | Object client = |
809 | |
((Model.getFacade().getClients(modelElement).toArray())[0]); |
810 | 0 | figEdge = new FigDependency(modelElement, settings); |
811 | 0 | FigNode supFN = (FigNode) getLayer().presentationFor(supplier); |
812 | 0 | FigNode cliFN = (FigNode) getLayer().presentationFor(client); |
813 | |
|
814 | 0 | figEdge.setSourcePortFig(cliFN); |
815 | 0 | figEdge.setSourceFigNode(cliFN); |
816 | 0 | figEdge.setDestPortFig(supFN); |
817 | 0 | figEdge.setDestFigNode(supFN); |
818 | 0 | figEdge.getFig().setLayer(getLayer()); |
819 | 0 | } else if (modelElement instanceof CommentEdge) { |
820 | 0 | CommentEdge ce = (CommentEdge) modelElement; |
821 | 0 | Object source = ce.getSource(); |
822 | 0 | Object dest = ce.getDestination(); |
823 | 0 | FigNode sourceFN = (FigNode) getLayer().presentationFor(source); |
824 | 0 | FigNode destFN = (FigNode) getLayer().presentationFor(dest); |
825 | 0 | figEdge = new FigEdgeNote(modelElement, settings); |
826 | 0 | figEdge.setSourcePortFig(sourceFN); |
827 | 0 | figEdge.setSourceFigNode(sourceFN); |
828 | 0 | figEdge.setDestPortFig(destFN); |
829 | 0 | figEdge.setDestFigNode(destFN); |
830 | 0 | figEdge.getFig().setLayer(getLayer()); |
831 | |
} |
832 | |
|
833 | 0 | if (figEdge != null) { |
834 | 0 | figEdge.computeRoute(); |
835 | 0 | return (DiagramElement) figEdge; |
836 | |
} |
837 | |
|
838 | 0 | if (Model.getFacade().isAAssociation(modelElement)) { |
839 | 0 | figNode = |
840 | |
createNaryAssociationNode(modelElement, bounds, settings); |
841 | 0 | } else if (Model.getFacade().isAStereotype(modelElement)) { |
842 | |
|
843 | 0 | figNode = new FigStereotypeDeclaration(modelElement, bounds, |
844 | |
settings); |
845 | 0 | } else if (Model.getFacade().isAClass(modelElement)) { |
846 | 0 | figNode = new FigClass(modelElement, bounds, settings); |
847 | 0 | } else if (Model.getFacade().isAInterface(modelElement)) { |
848 | 0 | figNode = new FigInterface(modelElement, bounds, settings); |
849 | 0 | } else if (Model.getFacade().isAModel(modelElement)) { |
850 | 0 | figNode = new FigModel(modelElement, bounds, settings); |
851 | 0 | } else if (Model.getFacade().isASubsystem(modelElement)) { |
852 | 0 | figNode = new FigSubsystem(modelElement, bounds, settings); |
853 | 0 | } else if (Model.getFacade().isAPackage(modelElement)) { |
854 | 0 | figNode = new FigPackage(modelElement, bounds, settings); |
855 | 0 | } else if (Model.getFacade().isAComment(modelElement)) { |
856 | 0 | figNode = new FigComment(modelElement, bounds, settings); |
857 | 0 | } else if (Model.getFacade().isAEnumeration(modelElement)) { |
858 | 0 | figNode = new FigEnumeration(modelElement, bounds, settings); |
859 | 0 | } else if (Model.getFacade().isADataType(modelElement)) { |
860 | 0 | figNode = new FigDataType(modelElement, bounds, settings); |
861 | 0 | } else if (Model.getFacade().isAException(modelElement)) { |
862 | 0 | figNode = new FigException(modelElement, bounds, settings); |
863 | 0 | } else if (Model.getFacade().isASignal(modelElement)) { |
864 | 0 | figNode = new FigSignal(modelElement, bounds, settings); |
865 | 0 | } else if (Model.getFacade().isAActor(modelElement)) { |
866 | 0 | figNode = new FigActor(modelElement, bounds, settings); |
867 | 0 | } else if (Model.getFacade().isAUseCase(modelElement)) { |
868 | 0 | figNode = new FigUseCase(modelElement, bounds, settings); |
869 | 0 | } else if (Model.getFacade().isAObject(modelElement)) { |
870 | 0 | figNode = new FigObject(modelElement, bounds, settings); |
871 | 0 | } else if (Model.getFacade().isANodeInstance(modelElement)) { |
872 | 0 | figNode = new FigNodeInstance(modelElement, bounds, settings); |
873 | 0 | } else if (Model.getFacade().isAComponentInstance(modelElement)) { |
874 | 0 | figNode = new FigComponentInstance(modelElement, bounds, settings); |
875 | 0 | } else if (Model.getFacade().isANode(modelElement)) { |
876 | 0 | figNode = new FigMNode(modelElement, bounds, settings); |
877 | 0 | } else if (Model.getFacade().isAComponent(modelElement)) { |
878 | 0 | figNode = new FigComponent(modelElement, bounds, settings); |
879 | |
} |
880 | 0 | if (figNode != null) { |
881 | 0 | LOG.debug("Model element " + modelElement + " converted to " |
882 | |
+ figNode); |
883 | |
} else { |
884 | 0 | LOG.debug("Dropped object NOT added " + figNode); |
885 | |
} |
886 | 0 | return figNode; |
887 | |
} |
888 | |
|
889 | |
protected FigNode getFigNodeForAssociationEnd( |
890 | |
final Object associationEnd) { |
891 | 0 | Object classifier = |
892 | |
Model.getFacade().getClassifier(associationEnd); |
893 | 0 | return getNodePresentationFor(getLayer(), classifier); |
894 | |
} |
895 | |
|
896 | |
|
897 | |
|
898 | |
|
899 | |
|
900 | |
|
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
private FigNode getNodePresentationFor(Layer lay, Object modelElement) { |
908 | 0 | assert modelElement != null : "A modelElement must be supplied"; |
909 | 0 | for (Object fig : lay.getContentsNoEdges()) { |
910 | |
|
911 | 0 | if (fig instanceof FigNode |
912 | |
&& modelElement.equals(((FigNode) fig).getOwner())) { |
913 | 0 | return ((FigNode) fig); |
914 | |
} |
915 | |
} |
916 | 0 | for (Object fig : lay.getContentsEdgesOnly()) { |
917 | 0 | if (fig instanceof FigEdgeModelElement |
918 | |
&& modelElement.equals(((FigEdgeModelElement) fig) |
919 | |
.getOwner())) { |
920 | 0 | return ((FigEdgeModelElement) fig).getEdgePort(); |
921 | |
} |
922 | |
} |
923 | 0 | return null; |
924 | |
} |
925 | |
|
926 | |
|
927 | |
} |