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.commands.DestroyReferenceCommand; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
18 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
19 | import org.eclipse.gmf.runtime.notation.Edge; |
20 | import org.eclipse.gmf.runtime.notation.Node; |
21 | import org.eclipse.gmf.runtime.notation.View; |
22 | |
23 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionCreateCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionReorientCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.AbstractActionSuccessor_AbstractActionEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.SetVariableActionVariableSetterEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.VariableUsage3EditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
29 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | public class SetVariableAction2ItemSemanticEditPolicy extends |
35 | PalladioComponentModelBaseItemSemanticEditPolicy { |
36 | |
37 | /** |
38 | * @generated |
39 | */ |
40 | public SetVariableAction2ItemSemanticEditPolicy() { |
41 | super(PalladioComponentModelElementTypes.SetVariableAction_3024); |
42 | } |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
48 | View view = (View) getHost().getModel(); |
49 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
50 | getEditingDomain(), null); |
51 | cmd.setTransactionNestingEnabled(false); |
52 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
53 | Edge incomingLink = (Edge) it.next(); |
54 | if (PalladioComponentModelVisualIDRegistry |
55 | .getVisualID(incomingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
56 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
57 | incomingLink.getSource().getElement(), null, |
58 | incomingLink.getTarget().getElement(), false); |
59 | cmd.add(new DestroyReferenceCommand(r)); |
60 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
61 | continue; |
62 | } |
63 | } |
64 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
65 | Edge outgoingLink = (Edge) it.next(); |
66 | if (PalladioComponentModelVisualIDRegistry |
67 | .getVisualID(outgoingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
68 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
69 | outgoingLink.getSource().getElement(), null, |
70 | outgoingLink.getTarget().getElement(), false); |
71 | cmd.add(new DestroyReferenceCommand(r)); |
72 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
73 | continue; |
74 | } |
75 | } |
76 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
77 | if (annotation == null) { |
78 | // there are indirectly referenced children, need extra commands: false |
79 | addDestroyChildNodesCommand(cmd); |
80 | addDestroyShortcutsCommand(cmd, view); |
81 | // delete host element |
82 | cmd.add(new DestroyElementCommand(req)); |
83 | } else { |
84 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
85 | } |
86 | return getGEFWrapper(cmd.reduce()); |
87 | } |
88 | |
89 | /** |
90 | * @generated |
91 | */ |
92 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
93 | View view = (View) getHost().getModel(); |
94 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
95 | Node node = (Node) nit.next(); |
96 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
97 | case SetVariableActionVariableSetterEditPart.VISUAL_ID: |
98 | for (Iterator cit = node.getChildren().iterator(); cit |
99 | .hasNext();) { |
100 | Node cnode = (Node) cit.next(); |
101 | switch (PalladioComponentModelVisualIDRegistry |
102 | .getVisualID(cnode)) { |
103 | case VariableUsage3EditPart.VISUAL_ID: |
104 | cmd.add(new DestroyElementCommand( |
105 | new DestroyElementRequest(getEditingDomain(), |
106 | cnode.getElement(), false))); // directlyOwned: true |
107 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
108 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
109 | break; |
110 | } |
111 | } |
112 | break; |
113 | } |
114 | } |
115 | } |
116 | |
117 | /** |
118 | * @generated |
119 | */ |
120 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
121 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
122 | : getCompleteCreateRelationshipCommand(req); |
123 | return command != null ? command : super |
124 | .getCreateRelationshipCommand(req); |
125 | } |
126 | |
127 | /** |
128 | * @generated |
129 | */ |
130 | protected Command getStartCreateRelationshipCommand( |
131 | CreateRelationshipRequest req) { |
132 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
133 | .getElementType()) { |
134 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
135 | req, req.getSource(), req.getTarget())); |
136 | } |
137 | return null; |
138 | } |
139 | |
140 | /** |
141 | * @generated |
142 | */ |
143 | protected Command getCompleteCreateRelationshipCommand( |
144 | CreateRelationshipRequest req) { |
145 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
146 | .getElementType()) { |
147 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
148 | req, req.getSource(), req.getTarget())); |
149 | } |
150 | return null; |
151 | } |
152 | |
153 | /** |
154 | * Returns command to reorient EReference based link. New link target or source |
155 | * should be the domain model element associated with this node. |
156 | * |
157 | * @generated |
158 | */ |
159 | protected Command getReorientReferenceRelationshipCommand( |
160 | ReorientReferenceRelationshipRequest req) { |
161 | switch (getVisualID(req)) { |
162 | case AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID: |
163 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionReorientCommand( |
164 | req)); |
165 | } |
166 | return super.getReorientReferenceRelationshipCommand(req); |
167 | } |
168 | |
169 | } |