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.use_case.ui; |
41 | |
|
42 | |
import java.awt.Point; |
43 | |
import java.awt.Rectangle; |
44 | |
import java.beans.PropertyVetoException; |
45 | |
import java.util.Collection; |
46 | |
import java.util.HashSet; |
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.ui.CmdCreateNode; |
54 | |
import org.argouml.uml.diagram.DiagramElement; |
55 | |
import org.argouml.uml.diagram.DiagramSettings; |
56 | |
import org.argouml.uml.diagram.static_structure.ui.FigComment; |
57 | |
import org.argouml.uml.diagram.static_structure.ui.FigPackage; |
58 | |
import org.argouml.uml.diagram.ui.ActionAddExtensionPoint; |
59 | |
import org.argouml.uml.diagram.ui.ActionSetAddAssociationMode; |
60 | |
import org.argouml.uml.diagram.ui.ActionSetMode; |
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.uml.diagram.use_case.UseCaseDiagramGraphModel; |
65 | |
import org.argouml.util.ToolBarUtility; |
66 | |
import org.tigris.gef.base.LayerPerspective; |
67 | |
import org.tigris.gef.base.LayerPerspectiveMutable; |
68 | |
import org.tigris.gef.base.ModeCreatePolyEdge; |
69 | |
import org.tigris.gef.presentation.FigNode; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public class UMLUseCaseDiagram extends UMLDiagram { |
81 | |
|
82 | 900 | private static final Logger LOG = Logger.getLogger(UMLUseCaseDiagram.class); |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
private Action actionActor; |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
private Action actionUseCase; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
private Action actionAssociation; |
101 | |
private Action actionAggregation; |
102 | |
private Action actionComposition; |
103 | |
private Action actionUniAssociation; |
104 | |
private Action actionUniAggregation; |
105 | |
private Action actionUniComposition; |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
private Action actionGeneralize; |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
private Action actionExtend; |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
private Action actionInclude; |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
private Action actionDependency; |
130 | |
|
131 | |
private Action actionExtensionPoint; |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
@Deprecated |
147 | |
public UMLUseCaseDiagram() { |
148 | 973 | super(new UseCaseDiagramGraphModel()); |
149 | |
try { |
150 | 973 | setName(getNewDiagramName()); |
151 | 973 | } catch (PropertyVetoException pve) { } |
152 | 973 | } |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public UMLUseCaseDiagram(Object m) { |
166 | 973 | this(); |
167 | 973 | if (!Model.getFacade().isANamespace(m)) { |
168 | 0 | throw new IllegalArgumentException(); |
169 | |
} |
170 | 973 | setNamespace(m); |
171 | 973 | } |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public UMLUseCaseDiagram(String name, Object namespace) { |
180 | 0 | this(namespace); |
181 | 0 | if (!Model.getFacade().isANamespace(namespace)) { |
182 | 0 | throw new IllegalArgumentException(); |
183 | |
} |
184 | |
try { |
185 | 0 | setName(name); |
186 | 0 | } catch (PropertyVetoException v) { } |
187 | 0 | } |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
@Override |
213 | |
public void setNamespace(Object handle) { |
214 | 973 | if (!Model.getFacade().isANamespace(handle)) { |
215 | 0 | LOG.error( |
216 | |
"Illegal argument. Object " + handle + " is not a namespace"); |
217 | 0 | throw new IllegalArgumentException( |
218 | |
"Illegal argument. Object " + handle + " is not a namespace"); |
219 | |
} |
220 | 973 | Object m = handle; |
221 | 973 | super.setNamespace(m); |
222 | |
|
223 | 973 | UseCaseDiagramGraphModel gm = |
224 | |
(UseCaseDiagramGraphModel) getGraphModel(); |
225 | 973 | gm.setHomeModel(m); |
226 | 973 | LayerPerspective lay = |
227 | |
new LayerPerspectiveMutable(Model.getFacade().getName(m), gm); |
228 | 973 | UseCaseDiagramRenderer rend = new UseCaseDiagramRenderer(); |
229 | 973 | lay.setGraphNodeRenderer(rend); |
230 | 973 | lay.setGraphEdgeRenderer(rend); |
231 | 973 | setLayer(lay); |
232 | |
|
233 | |
|
234 | |
|
235 | 973 | } |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
protected Object[] getUmlActions() { |
241 | 54 | Object[] actions = |
242 | |
{ |
243 | |
getActionActor(), |
244 | |
getActionUseCase(), |
245 | |
null, |
246 | |
getAssociationActions(), |
247 | |
getActionDependency(), |
248 | |
getActionGeneralize(), |
249 | |
getActionExtend(), |
250 | |
getActionInclude(), |
251 | |
null, |
252 | |
getActionExtensionPoint(), |
253 | |
}; |
254 | 54 | return actions; |
255 | |
} |
256 | |
|
257 | |
private Object[] getAssociationActions() { |
258 | 54 | Object[][] actions = { |
259 | |
{getActionAssociation(), getActionUniAssociation() }, |
260 | |
{getActionAggregation(), getActionUniAggregation() }, |
261 | |
{getActionComposition(), getActionUniComposition() }, |
262 | |
}; |
263 | 54 | ToolBarUtility.manageDefault(actions, "diagram.usecase.association"); |
264 | 54 | return actions; |
265 | |
} |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
public String getLabelName() { |
271 | 984 | return Translator.localize("label.usecase-diagram"); |
272 | |
} |
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
protected Action getActionActor() { |
278 | 54 | if (actionActor == null) { |
279 | 54 | actionActor = new RadioAction(new CmdCreateNode( |
280 | |
Model.getMetaTypes().getActor(), "button.new-actor")); |
281 | |
} |
282 | 54 | return actionActor; |
283 | |
} |
284 | |
|
285 | |
|
286 | |
|
287 | |
protected Action getActionAggregation() { |
288 | 54 | if (actionAggregation == null) { |
289 | 54 | actionAggregation = new RadioAction( |
290 | |
new ActionSetAddAssociationMode( |
291 | |
Model.getAggregationKind().getAggregate(), |
292 | |
false, |
293 | |
"button.new-aggregation")); |
294 | |
} |
295 | 54 | return actionAggregation; |
296 | |
} |
297 | |
|
298 | |
|
299 | |
|
300 | |
protected Action getActionAssociation() { |
301 | 54 | if (actionAssociation == null) { |
302 | 54 | actionAssociation = new RadioAction( |
303 | |
new ActionSetAddAssociationMode( |
304 | |
Model.getAggregationKind().getNone(), |
305 | |
false, |
306 | |
"button.new-association")); |
307 | |
} |
308 | 54 | return actionAssociation; |
309 | |
} |
310 | |
|
311 | |
|
312 | |
|
313 | |
protected Action getActionComposition() { |
314 | 54 | if (actionComposition == null) { |
315 | 54 | actionComposition = new RadioAction( |
316 | |
new ActionSetAddAssociationMode( |
317 | |
Model.getAggregationKind().getComposite(), |
318 | |
false, |
319 | |
"button.new-composition")); |
320 | |
} |
321 | 54 | return actionComposition; |
322 | |
} |
323 | |
|
324 | |
|
325 | |
|
326 | |
protected Action getActionDependency() { |
327 | 54 | if (actionDependency == null) { |
328 | 54 | actionDependency = new RadioAction( |
329 | |
new ActionSetMode( |
330 | |
ModeCreatePolyEdge.class, |
331 | |
"edgeClass", |
332 | |
Model.getMetaTypes().getDependency(), |
333 | |
"button.new-dependency")); |
334 | |
} |
335 | 54 | return actionDependency; |
336 | |
} |
337 | |
|
338 | |
|
339 | |
|
340 | |
protected Action getActionExtend() { |
341 | 54 | if (actionExtend == null) { |
342 | 54 | actionExtend = new RadioAction( |
343 | |
new ActionSetMode( |
344 | |
ModeCreatePolyEdge.class, |
345 | |
"edgeClass", |
346 | |
Model.getMetaTypes().getExtend(), |
347 | |
"button.new-extend")); |
348 | |
} |
349 | 54 | return actionExtend; |
350 | |
} |
351 | |
|
352 | |
|
353 | |
|
354 | |
protected Action getActionGeneralize() { |
355 | 54 | if (actionGeneralize == null) { |
356 | 54 | actionGeneralize = new RadioAction( |
357 | |
new ActionSetMode( |
358 | |
ModeCreatePolyEdge.class, |
359 | |
"edgeClass", |
360 | |
Model.getMetaTypes().getGeneralization(), |
361 | |
"button.new-generalization")); |
362 | |
} |
363 | 54 | return actionGeneralize; |
364 | |
} |
365 | |
|
366 | |
|
367 | |
|
368 | |
protected Action getActionInclude() { |
369 | 54 | if (actionInclude == null) { |
370 | 54 | actionInclude = new RadioAction( |
371 | |
new ActionSetMode( |
372 | |
ModeCreatePolyEdge.class, |
373 | |
"edgeClass", |
374 | |
Model.getMetaTypes().getInclude(), |
375 | |
"button.new-include")); |
376 | |
} |
377 | 54 | return actionInclude; |
378 | |
} |
379 | |
|
380 | |
|
381 | |
|
382 | |
protected Action getActionUniAggregation() { |
383 | 54 | if (actionUniAggregation == null) { |
384 | 54 | actionUniAggregation = new RadioAction( |
385 | |
new ActionSetAddAssociationMode( |
386 | |
Model.getAggregationKind().getAggregate(), |
387 | |
true, |
388 | |
"button.new-uniaggregation")); |
389 | |
} |
390 | 54 | return actionUniAggregation; |
391 | |
} |
392 | |
|
393 | |
|
394 | |
|
395 | |
protected Action getActionUniAssociation() { |
396 | 54 | if (actionUniAssociation == null) { |
397 | 54 | actionUniAssociation = new RadioAction( |
398 | |
new ActionSetAddAssociationMode( |
399 | |
Model.getAggregationKind().getNone(), |
400 | |
true, |
401 | |
"button.new-uniassociation")); |
402 | |
} |
403 | 54 | return actionUniAssociation; |
404 | |
} |
405 | |
|
406 | |
|
407 | |
|
408 | |
protected Action getActionUniComposition() { |
409 | 54 | if (actionUniComposition == null) { |
410 | 54 | actionUniComposition = new RadioAction( |
411 | |
new ActionSetAddAssociationMode( |
412 | |
Model.getAggregationKind().getComposite(), |
413 | |
true, |
414 | |
"button.new-unicomposition")); |
415 | |
} |
416 | 54 | return actionUniComposition; |
417 | |
} |
418 | |
|
419 | |
|
420 | |
|
421 | |
protected Action getActionUseCase() { |
422 | 54 | if (actionUseCase == null) { |
423 | 54 | actionUseCase = new RadioAction(new CmdCreateNode( |
424 | |
Model.getMetaTypes().getUseCase(), "button.new-usecase")); |
425 | |
} |
426 | 54 | return actionUseCase; |
427 | |
} |
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
protected Action getActionExtensionPoint() { |
433 | 54 | if (actionExtensionPoint == null) { |
434 | 54 | actionExtensionPoint = ActionAddExtensionPoint.singleton(); |
435 | |
} |
436 | 54 | return actionExtensionPoint; |
437 | |
} |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
public boolean isRelocationAllowed(Object base) { |
443 | 0 | return Model.getFacade().isAPackage(base) |
444 | |
|| Model.getFacade().isAClassifier(base); |
445 | |
} |
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
public boolean relocate(Object base) { |
451 | 0 | setNamespace(base); |
452 | 0 | damage(); |
453 | 0 | return true; |
454 | |
} |
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
@SuppressWarnings("unchecked") |
460 | |
public Collection getRelocationCandidates(Object root) { |
461 | 0 | Collection c = new HashSet(); |
462 | 0 | c.add(Model.getModelManagementHelper() |
463 | |
.getAllModelElementsOfKindWithModel(root, |
464 | |
Model.getMetaTypes().getPackage())); |
465 | 0 | c.add(Model.getModelManagementHelper() |
466 | |
.getAllModelElementsOfKindWithModel(root, |
467 | |
Model.getMetaTypes().getClassifier())); |
468 | 0 | return c; |
469 | |
} |
470 | |
|
471 | |
public void encloserChanged(FigNode enclosed, |
472 | |
FigNode oldEncloser, FigNode newEncloser) { |
473 | |
|
474 | 0 | } |
475 | |
|
476 | |
@Override |
477 | |
public boolean doesAccept(Object objectToAccept) { |
478 | 0 | if (Model.getFacade().isAActor(objectToAccept)) { |
479 | 0 | return true; |
480 | 0 | } else if (Model.getFacade().isAUseCase(objectToAccept)) { |
481 | 0 | return true; |
482 | 0 | } else if (Model.getFacade().isAComment(objectToAccept)) { |
483 | 0 | return true; |
484 | 0 | } else if (Model.getFacade().isAPackage(objectToAccept)) { |
485 | |
|
486 | 0 | if (Model.getFacade().isAModel(objectToAccept)) { |
487 | 0 | return false; |
488 | 0 | } else if (Model.getFacade().isASubsystem(objectToAccept)) { |
489 | 0 | return false; |
490 | |
} |
491 | 0 | return true; |
492 | |
} |
493 | 0 | return false; |
494 | |
|
495 | |
} |
496 | |
|
497 | |
@Override |
498 | |
public DiagramElement drop(Object droppedObject, Point location) { |
499 | 0 | DiagramElement figNode = null; |
500 | |
|
501 | |
|
502 | 0 | Rectangle bounds = null; |
503 | 0 | if (location != null) { |
504 | 0 | bounds = new Rectangle(location.x, location.y, 0, 0); |
505 | |
} |
506 | |
|
507 | 0 | return createDiagramElement(droppedObject, bounds); |
508 | |
} |
509 | |
|
510 | |
public DiagramElement createDiagramElement( |
511 | |
final Object modelElement, |
512 | |
final Rectangle bounds) { |
513 | |
|
514 | 0 | FigNodeModelElement figNode = null; |
515 | |
|
516 | 0 | DiagramSettings settings = getDiagramSettings(); |
517 | |
|
518 | 0 | if (Model.getFacade().isAActor(modelElement)) { |
519 | 0 | figNode = new FigActor(modelElement, bounds, settings); |
520 | 0 | } else if (Model.getFacade().isAUseCase(modelElement)) { |
521 | 0 | figNode = new FigUseCase(modelElement, bounds, settings); |
522 | 0 | } else if (Model.getFacade().isAComment(modelElement)) { |
523 | 0 | figNode = new FigComment(modelElement, bounds, settings); |
524 | 0 | } else if (Model.getFacade().isAPackage(modelElement)) { |
525 | 0 | if (!Model.getFacade().isAModel(modelElement) |
526 | |
&& !Model.getFacade().isASubsystem(modelElement)) { |
527 | |
|
528 | |
|
529 | |
|
530 | 0 | figNode = new FigPackage(modelElement, bounds, settings); |
531 | |
} |
532 | |
} |
533 | 0 | if (figNode != null) { |
534 | 0 | LOG.debug("Model element " + modelElement + " converted to " |
535 | |
+ figNode); |
536 | |
} else { |
537 | 0 | LOG.debug("Dropped object NOT added " + figNode); |
538 | |
} |
539 | 0 | return figNode; |
540 | |
} |
541 | |
} |