1 | /* |
2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.edit.policies; |
5 | |
6 | import java.util.Iterator; |
7 | |
8 | import org.eclipse.emf.ecore.EAnnotation; |
9 | import org.eclipse.gef.commands.Command; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand; |
11 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
12 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
16 | import org.eclipse.gmf.runtime.notation.Node; |
17 | import org.eclipse.gmf.runtime.notation.View; |
18 | |
19 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.ResourceDemandingBehaviour4CreateCommand; |
20 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.ResourceDemandingBehaviour4EditPart; |
21 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
22 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
23 | |
24 | /** |
25 | * @generated |
26 | */ |
27 | public class GuardedBranchTransitionItemSemanticEditPolicy extends |
28 | PalladioComponentModelBaseItemSemanticEditPolicy { |
29 | |
30 | /** |
31 | * @generated |
32 | */ |
33 | public GuardedBranchTransitionItemSemanticEditPolicy() { |
34 | super(PalladioComponentModelElementTypes.GuardedBranchTransition_3017); |
35 | } |
36 | |
37 | /** |
38 | * @generated |
39 | */ |
40 | protected Command getCreateCommand(CreateElementRequest req) { |
41 | if (PalladioComponentModelElementTypes.ResourceDemandingBehaviour_3018 == req |
42 | .getElementType()) { |
43 | return getGEFWrapper(new ResourceDemandingBehaviour4CreateCommand( |
44 | req)); |
45 | } |
46 | return super.getCreateCommand(req); |
47 | } |
48 | |
49 | /** |
50 | * @generated |
51 | */ |
52 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
53 | View view = (View) getHost().getModel(); |
54 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
55 | getEditingDomain(), null); |
56 | cmd.setTransactionNestingEnabled(false); |
57 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
58 | if (annotation == null) { |
59 | // there are indirectly referenced children, need extra commands: false |
60 | addDestroyChildNodesCommand(cmd); |
61 | addDestroyShortcutsCommand(cmd, view); |
62 | // delete host element |
63 | cmd.add(new DestroyElementCommand(req)); |
64 | } else { |
65 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
66 | } |
67 | return getGEFWrapper(cmd.reduce()); |
68 | } |
69 | |
70 | /** |
71 | * @generated |
72 | */ |
73 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
74 | View view = (View) getHost().getModel(); |
75 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
76 | Node node = (Node) nit.next(); |
77 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
78 | case ResourceDemandingBehaviour4EditPart.VISUAL_ID: |
79 | cmd.add(new DestroyElementCommand(new DestroyElementRequest( |
80 | getEditingDomain(), node.getElement(), false))); // directlyOwned: true |
81 | // don't need explicit deletion of node as parent's view deletion would clean child views as well |
82 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), node)); |
83 | break; |
84 | } |
85 | } |
86 | } |
87 | |
88 | } |