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 | |
package org.argouml.uml.diagram.collaboration.ui; |
40 | |
|
41 | |
import java.awt.Point; |
42 | |
import java.awt.Rectangle; |
43 | |
import java.beans.PropertyVetoException; |
44 | |
import java.util.Collection; |
45 | |
import java.util.HashSet; |
46 | |
import java.util.Iterator; |
47 | |
|
48 | |
import javax.swing.Action; |
49 | |
|
50 | |
import org.apache.log4j.Logger; |
51 | |
import org.argouml.i18n.Translator; |
52 | |
import org.argouml.model.Model; |
53 | |
import org.argouml.uml.diagram.DiagramElement; |
54 | |
import org.argouml.uml.diagram.DiagramSettings; |
55 | |
import org.argouml.uml.diagram.collaboration.CollabDiagramGraphModel; |
56 | |
import org.argouml.uml.diagram.static_structure.ui.FigComment; |
57 | |
import org.argouml.uml.diagram.ui.ActionAddAssociationRole; |
58 | |
import org.argouml.uml.diagram.ui.ActionAddMessage; |
59 | |
import org.argouml.uml.diagram.ui.ActionSetMode; |
60 | |
import org.argouml.uml.diagram.ui.FigMessage; |
61 | |
import org.argouml.uml.diagram.ui.FigNodeModelElement; |
62 | |
import org.argouml.uml.diagram.ui.RadioAction; |
63 | |
import org.argouml.uml.diagram.ui.UMLDiagram; |
64 | |
import org.argouml.util.ToolBarUtility; |
65 | |
import org.tigris.gef.base.Editor; |
66 | |
import org.tigris.gef.base.Globals; |
67 | |
import org.tigris.gef.base.Layer; |
68 | |
import org.tigris.gef.base.LayerPerspective; |
69 | |
import org.tigris.gef.base.LayerPerspectiveMutable; |
70 | |
import org.tigris.gef.base.ModeCreatePolyEdge; |
71 | |
import org.tigris.gef.graph.GraphModel; |
72 | |
import org.tigris.gef.presentation.Fig; |
73 | |
import org.tigris.gef.presentation.FigNode; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public class UMLCollaborationDiagram extends UMLDiagram { |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 19 | private static final Logger LOG = |
90 | |
Logger.getLogger(UMLCollaborationDiagram.class); |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
private Action actionClassifierRole; |
96 | |
private Action actionGeneralize; |
97 | |
|
98 | |
private Action actionAssociation; |
99 | |
private Action actionAggregation; |
100 | |
private Action actionComposition; |
101 | |
private Action actionUniAssociation; |
102 | |
private Action actionUniAggregation; |
103 | |
private Action actionUniComposition; |
104 | |
|
105 | |
private Action actionDepend; |
106 | |
private Action actionMessage; |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
@Deprecated |
118 | 19 | public UMLCollaborationDiagram() { |
119 | |
try { |
120 | 19 | setName(getNewDiagramName()); |
121 | 19 | } catch (PropertyVetoException pve) { } |
122 | |
|
123 | 19 | setGraphModel(createGraphModel()); |
124 | 19 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
@Deprecated |
134 | |
public UMLCollaborationDiagram(Object collaboration) { |
135 | 19 | this(); |
136 | 19 | setNamespace(collaboration); |
137 | 19 | } |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public int getNumMessages() { |
143 | 0 | Layer lay = getLayer(); |
144 | 0 | Collection figs = lay.getContents(); |
145 | 0 | int res = 0; |
146 | 0 | Iterator it = figs.iterator(); |
147 | 0 | while (it.hasNext()) { |
148 | 0 | Fig f = (Fig) it.next(); |
149 | 0 | if (Model.getFacade().isAMessage(f.getOwner())) { |
150 | 0 | res++; |
151 | |
} |
152 | 0 | } |
153 | 0 | return res; |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void setNamespace(Object handle) { |
173 | 19 | if (!Model.getFacade().isANamespace(handle)) { |
174 | 0 | LOG.error( |
175 | |
"Illegal argument. Object " + handle + " is not a namespace"); |
176 | 0 | throw new IllegalArgumentException( |
177 | |
"Illegal argument. Object " + handle + " is not a namespace"); |
178 | |
} |
179 | 19 | super.setNamespace(handle); |
180 | 19 | CollabDiagramGraphModel gm = createGraphModel(); |
181 | 19 | gm.setCollaboration(handle); |
182 | 19 | LayerPerspective lay = |
183 | |
new LayerPerspectiveMutable(Model.getFacade().getName(handle), gm); |
184 | 19 | CollabDiagramRenderer rend = new CollabDiagramRenderer(); |
185 | 19 | lay.setGraphNodeRenderer(rend); |
186 | 19 | lay.setGraphEdgeRenderer(rend); |
187 | 19 | setLayer(lay); |
188 | 19 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
private CollabDiagramGraphModel createGraphModel() { |
194 | 38 | if ((getGraphModel() instanceof CollabDiagramGraphModel)) { |
195 | 19 | return (CollabDiagramGraphModel) getGraphModel(); |
196 | |
} else { |
197 | 19 | return new CollabDiagramGraphModel(); |
198 | |
} |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
protected Object[] getUmlActions() { |
207 | 19 | Object[] actions = { |
208 | |
getActionClassifierRole(), |
209 | |
null, |
210 | |
getAssociationActions(), |
211 | |
getActionGeneralize(), |
212 | |
getActionDepend(), |
213 | |
null, |
214 | |
getActionMessage(), |
215 | |
}; |
216 | 19 | return actions; |
217 | |
} |
218 | |
|
219 | |
private Object[] getAssociationActions() { |
220 | 19 | Object[][] actions = { |
221 | |
{getActionAssociation(), getActionUniAssociation() }, |
222 | |
{getActionAggregation(), getActionUniAggregation() }, |
223 | |
{getActionComposition(), getActionUniComposition() }, |
224 | |
}; |
225 | 19 | ToolBarUtility.manageDefault(actions, |
226 | |
"diagram.collaboration.association"); |
227 | 19 | return actions; |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public void postLoad() { |
237 | |
|
238 | 0 | super.postLoad(); |
239 | |
|
240 | 0 | if (getNamespace() == null) { |
241 | 0 | throw new IllegalStateException( |
242 | |
"The namespace of the collaboration diagram is not set"); |
243 | |
} |
244 | |
|
245 | |
Collection messages; |
246 | |
Iterator msgIterator; |
247 | 0 | Collection ownedElements = |
248 | |
Model.getFacade().getOwnedElements(getNamespace()); |
249 | 0 | Iterator oeIterator = ownedElements.iterator(); |
250 | 0 | Layer lay = getLayer(); |
251 | 0 | while (oeIterator.hasNext()) { |
252 | 0 | Object me = oeIterator.next(); |
253 | 0 | if (Model.getFacade().isAAssociationRole(me)) { |
254 | 0 | messages = Model.getFacade().getMessages(me); |
255 | 0 | msgIterator = messages.iterator(); |
256 | 0 | while (msgIterator.hasNext()) { |
257 | 0 | Object message = msgIterator.next(); |
258 | 0 | FigMessage figMessage = |
259 | |
(FigMessage) lay.presentationFor(message); |
260 | 0 | if (figMessage != null) { |
261 | 0 | figMessage.addPathItemToFigAssociationRole(lay); |
262 | |
} |
263 | 0 | } |
264 | |
} |
265 | 0 | } |
266 | 0 | } |
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
public String getLabelName() { |
272 | 19 | return Translator.localize("label.collaboration-diagram"); |
273 | |
} |
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
private Action getActionClassifierRole() { |
279 | 19 | if (actionClassifierRole == null) { |
280 | 19 | actionClassifierRole = |
281 | |
new RadioAction(new ActionAddClassifierRole()); |
282 | |
} |
283 | 19 | return actionClassifierRole; |
284 | |
} |
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
protected Action getActionAssociation() { |
290 | 19 | if (actionAssociation == null) { |
291 | 19 | actionAssociation = |
292 | |
new RadioAction( |
293 | |
new ActionAddAssociationRole( |
294 | |
Model.getAggregationKind().getNone(), |
295 | |
false, |
296 | |
"button.new-associationrole", |
297 | |
"Association")); |
298 | |
} |
299 | 19 | return actionAssociation; |
300 | |
} |
301 | |
|
302 | |
|
303 | |
|
304 | |
protected Action getActionComposition() { |
305 | 19 | if (actionComposition == null) { |
306 | 19 | actionComposition = |
307 | |
new RadioAction( |
308 | |
new ActionAddAssociationRole( |
309 | |
Model.getAggregationKind().getComposite(), |
310 | |
false, |
311 | |
"button.new-composition")); |
312 | |
} |
313 | 19 | return actionComposition; |
314 | |
} |
315 | |
|
316 | |
|
317 | |
|
318 | |
protected Action getActionDepend() { |
319 | 19 | if (actionDepend == null) { |
320 | 19 | actionDepend = |
321 | |
new RadioAction( |
322 | |
new ActionSetMode( |
323 | |
ModeCreatePolyEdge.class, |
324 | |
"edgeClass", |
325 | |
Model.getMetaTypes().getDependency(), |
326 | |
"button.new-dependency")); |
327 | |
} |
328 | 19 | return actionDepend; |
329 | |
} |
330 | |
|
331 | |
|
332 | |
|
333 | |
protected Action getActionGeneralize() { |
334 | 19 | if (actionGeneralize == null) { |
335 | 19 | actionGeneralize = |
336 | |
new RadioAction( |
337 | |
new ActionSetMode( |
338 | |
ModeCreatePolyEdge.class, |
339 | |
"edgeClass", |
340 | |
Model.getMetaTypes().getGeneralization(), |
341 | |
"button.new-generalization")); |
342 | |
} |
343 | 19 | return actionGeneralize; |
344 | |
} |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
protected Action getActionUniAggregation() { |
350 | 19 | if (actionUniAggregation == null) { |
351 | 19 | actionUniAggregation = |
352 | |
new RadioAction( |
353 | |
new ActionAddAssociationRole( |
354 | |
Model.getAggregationKind().getAggregate(), |
355 | |
true, |
356 | |
"button.new-uniaggregation")); |
357 | |
} |
358 | 19 | return actionUniAggregation; |
359 | |
} |
360 | |
|
361 | |
|
362 | |
|
363 | |
protected Action getActionUniAssociation() { |
364 | 19 | if (actionUniAssociation == null) { |
365 | 19 | actionUniAssociation = |
366 | |
new RadioAction( |
367 | |
new ActionAddAssociationRole( |
368 | |
Model.getAggregationKind().getNone(), |
369 | |
true, |
370 | |
"button.new-uniassociation")); |
371 | |
} |
372 | 19 | return actionUniAssociation; |
373 | |
} |
374 | |
|
375 | |
|
376 | |
|
377 | |
protected Action getActionUniComposition() { |
378 | 19 | if (actionUniComposition == null) { |
379 | 19 | actionUniComposition = |
380 | |
new RadioAction( |
381 | |
new ActionAddAssociationRole( |
382 | |
Model.getAggregationKind().getComposite(), |
383 | |
true, |
384 | |
"button.new-unicomposition")); |
385 | |
} |
386 | 19 | return actionUniComposition; |
387 | |
} |
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
private Action getActionAggregation() { |
393 | 19 | if (actionAggregation == null) { |
394 | 19 | actionAggregation = |
395 | |
new RadioAction( |
396 | |
new ActionAddAssociationRole( |
397 | |
Model.getAggregationKind().getAggregate(), |
398 | |
false, |
399 | |
"button.new-aggregation")); |
400 | |
} |
401 | 19 | return actionAggregation; |
402 | |
} |
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
private Action getActionMessage() { |
408 | 19 | if (actionMessage == null) { |
409 | 19 | actionMessage = ActionAddMessage.getTargetFollower(); |
410 | |
} |
411 | 19 | return actionMessage; |
412 | |
} |
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
public boolean isRelocationAllowed(Object base) { |
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | 0 | return false; |
426 | |
} |
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
public boolean relocate(Object base) { |
432 | 0 | return false; |
433 | |
} |
434 | |
|
435 | |
@SuppressWarnings("unchecked") |
436 | |
public Collection getRelocationCandidates(Object root) { |
437 | |
|
438 | |
|
439 | 0 | Collection c = new HashSet(); |
440 | 0 | c.add(getOwner()); |
441 | 0 | return c; |
442 | |
} |
443 | |
|
444 | |
public void encloserChanged(FigNode enclosed, |
445 | |
FigNode oldEncloser, FigNode newEncloser) { |
446 | |
|
447 | 0 | } |
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
@Override |
458 | |
public boolean doesAccept(Object objectToAccept) { |
459 | 0 | if (Model.getFacade().isAClassifierRole(objectToAccept)) { |
460 | 0 | return true; |
461 | 0 | } else if (Model.getFacade().isAMessage(objectToAccept)) { |
462 | 0 | return true; |
463 | 0 | } else if (Model.getFacade().isAComment(objectToAccept)) { |
464 | 0 | return true; |
465 | 0 | } else if (Model.getFacade().isAClassifier(objectToAccept)) { |
466 | 0 | return true; |
467 | |
} |
468 | 0 | return false; |
469 | |
} |
470 | |
|
471 | |
|
472 | |
|
473 | |
|
474 | |
|
475 | |
|
476 | |
private Object makeNewCR(Object base) { |
477 | 0 | Object node = null; |
478 | 0 | Editor ce = Globals.curEditor(); |
479 | 0 | GraphModel gm = ce.getGraphModel(); |
480 | 0 | if (gm instanceof CollabDiagramGraphModel) { |
481 | 0 | Object collaboration = |
482 | |
((CollabDiagramGraphModel) gm).getHomeModel(); |
483 | 0 | node = |
484 | |
Model.getCollaborationsFactory().buildClassifierRole( |
485 | |
collaboration); |
486 | |
} |
487 | 0 | Model.getCollaborationsHelper().addBase(node, base); |
488 | |
|
489 | 0 | return node; |
490 | |
} |
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | |
|
497 | |
|
498 | |
|
499 | |
private FigClassifierRole makeNewFigCR(Object classifierRole, |
500 | |
Point location) { |
501 | 0 | if (classifierRole != null) { |
502 | 0 | FigClassifierRole newCR = new FigClassifierRole(classifierRole, |
503 | |
new Rectangle(location), getDiagramSettings()); |
504 | |
|
505 | 0 | getGraphModel().getNodes().add(newCR.getOwner()); |
506 | |
|
507 | 0 | return newCR; |
508 | |
} |
509 | 0 | return null; |
510 | |
} |
511 | |
|
512 | |
@Override |
513 | |
public DiagramElement drop(Object droppedObject, Point location) { |
514 | 0 | DiagramElement figNode = null; |
515 | 0 | GraphModel gm = getGraphModel(); |
516 | 0 | Layer lay = Globals.curEditor().getLayerManager().getActiveLayer(); |
517 | |
|
518 | |
|
519 | 0 | Rectangle bounds = null; |
520 | 0 | if (location != null) { |
521 | 0 | bounds = new Rectangle(location.x, location.y, 0, 0); |
522 | |
} |
523 | 0 | DiagramSettings settings = getDiagramSettings(); |
524 | |
|
525 | 0 | if (Model.getFacade().isAClassifierRole(droppedObject)) { |
526 | 0 | figNode = new FigClassifierRole(droppedObject, bounds, settings); |
527 | 0 | } else if (Model.getFacade().isAMessage(droppedObject)) { |
528 | 0 | figNode = new FigMessage(droppedObject, bounds, settings); |
529 | 0 | } else if (Model.getFacade().isAComment(droppedObject)) { |
530 | 0 | figNode = new FigComment(droppedObject, bounds, settings); |
531 | 0 | } else if (Model.getFacade().isAClassifierRole(droppedObject)) { |
532 | 0 | figNode = makeNewFigCR(droppedObject, location); |
533 | 0 | } else if (Model.getFacade().isAClassifier(droppedObject)) { |
534 | 0 | figNode = makeNewFigCR(makeNewCR(droppedObject), location); |
535 | |
} |
536 | 0 | if (figNode != null) { |
537 | 0 | LOG.debug("Dropped object " + droppedObject + " converted to " |
538 | |
+ figNode); |
539 | |
} else { |
540 | 0 | LOG.debug("Dropped object NOT added " + droppedObject); |
541 | |
} |
542 | 0 | return figNode; |
543 | |
} |
544 | |
|
545 | |
|
546 | |
public DiagramElement createDiagramElement( |
547 | |
final Object modelElement, |
548 | |
final Rectangle bounds) { |
549 | |
|
550 | 0 | FigNodeModelElement figNode = null; |
551 | |
|
552 | 0 | DiagramSettings settings = getDiagramSettings(); |
553 | |
|
554 | 0 | if (Model.getFacade().isAClassifierRole(modelElement)) { |
555 | 0 | figNode = new FigClassifierRole(modelElement, bounds, settings); |
556 | 0 | } else if (Model.getFacade().isAMessage(modelElement)) { |
557 | 0 | figNode = new FigMessage(modelElement, bounds, settings); |
558 | 0 | } else if (Model.getFacade().isAComment(modelElement)) { |
559 | 0 | figNode = new FigComment(modelElement, bounds, settings); |
560 | 0 | } else if (Model.getFacade().isAClassifierRole(modelElement)) { |
561 | 0 | figNode = |
562 | |
makeNewFigCR(modelElement, bounds.getLocation()); |
563 | 0 | } else if (Model.getFacade().isAClassifier(modelElement)) { |
564 | 0 | figNode = |
565 | |
makeNewFigCR(makeNewCR(modelElement), bounds.getLocation()); |
566 | |
} |
567 | |
|
568 | 0 | if (figNode != null) { |
569 | 0 | LOG.debug("Model element " + modelElement + " converted to " |
570 | |
+ figNode); |
571 | |
} else { |
572 | 0 | LOG.debug("Dropped object NOT added " + figNode); |
573 | |
} |
574 | 0 | return figNode; |
575 | |
} |
576 | |
|
577 | |
@Override |
578 | |
public String getInstructions(Object droppedObject) { |
579 | 0 | if (Model.getFacade().isAClassifierRole(droppedObject)) { |
580 | 0 | return super.getInstructions(droppedObject); |
581 | 0 | } else if (Model.getFacade().isAClassifier(droppedObject)) { |
582 | 0 | return Translator.localize( |
583 | |
"misc.message.click-on-diagram-to-add-as-cr", |
584 | |
new Object[] {Model.getFacade().toString(droppedObject)}); |
585 | |
} |
586 | 0 | return super.getInstructions(droppedObject); |
587 | |
} |
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | |
private static final long serialVersionUID = 8081715986963837750L; |
593 | |
} |