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