1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.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.CreateElementRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
18 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
19 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
20 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
21 | import org.eclipse.gmf.runtime.notation.Edge; |
22 | import org.eclipse.gmf.runtime.notation.Node; |
23 | import org.eclipse.gmf.runtime.notation.View; |
24 | |
25 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.ImplementationComponentTypeParentCompleteComponentTypesCreateCommand; |
26 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.ImplementationComponentTypeParentCompleteComponentTypesReorientCommand; |
27 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureProvidedRoleCreateCommand; |
28 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureProvidedRoleReorientCommand; |
29 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureRequiredRoleCreateCommand; |
30 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureRequiredRoleReorientCommand; |
31 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationProvidedRoleCreateCommand; |
32 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationProvidedRoleReorientCommand; |
33 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationRequiredRoleCreateCommand; |
34 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationRequiredRoleReorientCommand; |
35 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.ResourceDemandingSEFFCreateCommand; |
36 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SinkRoleCreateCommand; |
37 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SinkRoleReorientCommand; |
38 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SourceRoleCreateCommand; |
39 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SourceRoleReorientCommand; |
40 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.BasicComponentComponentParameterCompartmentEditPart; |
41 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.BasicComponentPassiveResourceCompartmentEditPart; |
42 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.BasicComponentSEFFCompartmentEditPart; |
43 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.ImplementationComponentTypeParentCompleteComponentTypesEditPart; |
44 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureProvidedRoleEditPart; |
45 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureRequiredRoleEditPart; |
46 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationProvidedRoleEditPart; |
47 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationRequiredRoleEditPart; |
48 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.PassiveResourceEditPart; |
49 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.ResourceDemandingSEFFEditPart; |
50 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SinkRoleEditPart; |
51 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SourceRoleEditPart; |
52 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.VariableUsageEditPart; |
53 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry; |
54 | import de.uka.ipd.sdq.pcm.gmf.repository.providers.PalladioComponentModelElementTypes; |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | public class BasicComponentItemSemanticEditPolicy extends |
60 | PalladioComponentModelBaseItemSemanticEditPolicy { |
61 | |
62 | /** |
63 | * @generated |
64 | */ |
65 | public BasicComponentItemSemanticEditPolicy() { |
66 | super(PalladioComponentModelElementTypes.BasicComponent_2102); |
67 | } |
68 | |
69 | /** |
70 | * @generated |
71 | */ |
72 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
73 | View view = (View) getHost().getModel(); |
74 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
75 | getEditingDomain(), null); |
76 | cmd.setTransactionNestingEnabled(false); |
77 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
78 | Edge outgoingLink = (Edge) it.next(); |
79 | if (PalladioComponentModelVisualIDRegistry |
80 | .getVisualID(outgoingLink) == OperationProvidedRoleEditPart.VISUAL_ID) { |
81 | DestroyElementRequest r = new DestroyElementRequest( |
82 | outgoingLink.getElement(), false); |
83 | cmd.add(new DestroyElementCommand(r)); |
84 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
85 | continue; |
86 | } |
87 | if (PalladioComponentModelVisualIDRegistry |
88 | .getVisualID(outgoingLink) == InfrastructureProvidedRoleEditPart.VISUAL_ID) { |
89 | DestroyElementRequest r = new DestroyElementRequest( |
90 | outgoingLink.getElement(), false); |
91 | cmd.add(new DestroyElementCommand(r)); |
92 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
93 | continue; |
94 | } |
95 | if (PalladioComponentModelVisualIDRegistry |
96 | .getVisualID(outgoingLink) == InfrastructureRequiredRoleEditPart.VISUAL_ID) { |
97 | DestroyElementRequest r = new DestroyElementRequest( |
98 | outgoingLink.getElement(), false); |
99 | cmd.add(new DestroyElementCommand(r)); |
100 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
101 | continue; |
102 | } |
103 | if (PalladioComponentModelVisualIDRegistry |
104 | .getVisualID(outgoingLink) == SinkRoleEditPart.VISUAL_ID) { |
105 | DestroyElementRequest r = new DestroyElementRequest( |
106 | outgoingLink.getElement(), false); |
107 | cmd.add(new DestroyElementCommand(r)); |
108 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
109 | continue; |
110 | } |
111 | if (PalladioComponentModelVisualIDRegistry |
112 | .getVisualID(outgoingLink) == OperationRequiredRoleEditPart.VISUAL_ID) { |
113 | DestroyElementRequest r = new DestroyElementRequest( |
114 | outgoingLink.getElement(), false); |
115 | cmd.add(new DestroyElementCommand(r)); |
116 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
117 | continue; |
118 | } |
119 | if (PalladioComponentModelVisualIDRegistry |
120 | .getVisualID(outgoingLink) == ImplementationComponentTypeParentCompleteComponentTypesEditPart.VISUAL_ID) { |
121 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
122 | outgoingLink.getSource().getElement(), null, |
123 | outgoingLink.getTarget().getElement(), false); |
124 | cmd.add(new DestroyReferenceCommand(r)); |
125 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
126 | continue; |
127 | } |
128 | if (PalladioComponentModelVisualIDRegistry |
129 | .getVisualID(outgoingLink) == SourceRoleEditPart.VISUAL_ID) { |
130 | DestroyElementRequest r = new DestroyElementRequest( |
131 | outgoingLink.getElement(), false); |
132 | cmd.add(new DestroyElementCommand(r)); |
133 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
134 | continue; |
135 | } |
136 | } |
137 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
138 | if (annotation == null) { |
139 | // there are indirectly referenced children, need extra commands: false |
140 | addDestroyChildNodesCommand(cmd); |
141 | addDestroyShortcutsCommand(cmd, view); |
142 | // delete host element |
143 | cmd.add(new DestroyElementCommand(req)); |
144 | } else { |
145 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
146 | } |
147 | return getGEFWrapper(cmd.reduce()); |
148 | } |
149 | |
150 | /** |
151 | * @generated |
152 | */ |
153 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
154 | View view = (View) getHost().getModel(); |
155 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
156 | Node node = (Node) nit.next(); |
157 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
158 | case BasicComponentSEFFCompartmentEditPart.VISUAL_ID: |
159 | for (Iterator cit = node.getChildren().iterator(); cit |
160 | .hasNext();) { |
161 | Node cnode = (Node) cit.next(); |
162 | switch (PalladioComponentModelVisualIDRegistry |
163 | .getVisualID(cnode)) { |
164 | case ResourceDemandingSEFFEditPart.VISUAL_ID: |
165 | cmd.add(new DestroyElementCommand( |
166 | new DestroyElementRequest(getEditingDomain(), |
167 | cnode.getElement(), false))); // directlyOwned: true |
168 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
169 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
170 | break; |
171 | } |
172 | } |
173 | break; |
174 | case BasicComponentPassiveResourceCompartmentEditPart.VISUAL_ID: |
175 | for (Iterator cit = node.getChildren().iterator(); cit |
176 | .hasNext();) { |
177 | Node cnode = (Node) cit.next(); |
178 | switch (PalladioComponentModelVisualIDRegistry |
179 | .getVisualID(cnode)) { |
180 | case PassiveResourceEditPart.VISUAL_ID: |
181 | cmd.add(new DestroyElementCommand( |
182 | new DestroyElementRequest(getEditingDomain(), |
183 | cnode.getElement(), false))); // directlyOwned: true |
184 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
185 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
186 | break; |
187 | } |
188 | } |
189 | break; |
190 | case BasicComponentComponentParameterCompartmentEditPart.VISUAL_ID: |
191 | for (Iterator cit = node.getChildren().iterator(); cit |
192 | .hasNext();) { |
193 | Node cnode = (Node) cit.next(); |
194 | switch (PalladioComponentModelVisualIDRegistry |
195 | .getVisualID(cnode)) { |
196 | case VariableUsageEditPart.VISUAL_ID: |
197 | cmd.add(new DestroyElementCommand( |
198 | new DestroyElementRequest(getEditingDomain(), |
199 | cnode.getElement(), false))); // directlyOwned: true |
200 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
201 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
202 | break; |
203 | } |
204 | } |
205 | break; |
206 | } |
207 | } |
208 | } |
209 | |
210 | /** |
211 | * @generated |
212 | */ |
213 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
214 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
215 | : getCompleteCreateRelationshipCommand(req); |
216 | return command != null ? command : super |
217 | .getCreateRelationshipCommand(req); |
218 | } |
219 | |
220 | /** |
221 | * @generated |
222 | */ |
223 | protected Command getStartCreateRelationshipCommand( |
224 | CreateRelationshipRequest req) { |
225 | if (PalladioComponentModelElementTypes.OperationProvidedRole_4105 == req |
226 | .getElementType()) { |
227 | return getGEFWrapper(new OperationProvidedRoleCreateCommand(req, |
228 | req.getSource(), req.getTarget())); |
229 | } |
230 | if (PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111 == req |
231 | .getElementType()) { |
232 | return getGEFWrapper(new InfrastructureProvidedRoleCreateCommand( |
233 | req, req.getSource(), req.getTarget())); |
234 | } |
235 | if (PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112 == req |
236 | .getElementType()) { |
237 | return getGEFWrapper(new InfrastructureRequiredRoleCreateCommand( |
238 | req, req.getSource(), req.getTarget())); |
239 | } |
240 | if (PalladioComponentModelElementTypes.SinkRole_4109 == req |
241 | .getElementType()) { |
242 | return getGEFWrapper(new SinkRoleCreateCommand(req, |
243 | req.getSource(), req.getTarget())); |
244 | } |
245 | if (PalladioComponentModelElementTypes.OperationRequiredRole_4106 == req |
246 | .getElementType()) { |
247 | return getGEFWrapper(new OperationRequiredRoleCreateCommand(req, |
248 | req.getSource(), req.getTarget())); |
249 | } |
250 | if (PalladioComponentModelElementTypes.ImplementationComponentTypeParentCompleteComponentTypes_4103 == req |
251 | .getElementType()) { |
252 | return getGEFWrapper(new ImplementationComponentTypeParentCompleteComponentTypesCreateCommand( |
253 | req, req.getSource(), req.getTarget())); |
254 | } |
255 | if (PalladioComponentModelElementTypes.SourceRole_4110 == req |
256 | .getElementType()) { |
257 | return getGEFWrapper(new SourceRoleCreateCommand(req, req |
258 | .getSource(), req.getTarget())); |
259 | } |
260 | return null; |
261 | } |
262 | |
263 | /** |
264 | * @generated |
265 | */ |
266 | protected Command getCompleteCreateRelationshipCommand( |
267 | CreateRelationshipRequest req) { |
268 | if (PalladioComponentModelElementTypes.OperationProvidedRole_4105 == req |
269 | .getElementType()) { |
270 | return null; |
271 | } |
272 | if (PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111 == req |
273 | .getElementType()) { |
274 | return null; |
275 | } |
276 | if (PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112 == req |
277 | .getElementType()) { |
278 | return null; |
279 | } |
280 | if (PalladioComponentModelElementTypes.SinkRole_4109 == req |
281 | .getElementType()) { |
282 | return null; |
283 | } |
284 | if (PalladioComponentModelElementTypes.OperationRequiredRole_4106 == req |
285 | .getElementType()) { |
286 | return null; |
287 | } |
288 | if (PalladioComponentModelElementTypes.ImplementationComponentTypeParentCompleteComponentTypes_4103 == req |
289 | .getElementType()) { |
290 | return null; |
291 | } |
292 | if (PalladioComponentModelElementTypes.SourceRole_4110 == req |
293 | .getElementType()) { |
294 | return null; |
295 | } |
296 | return null; |
297 | } |
298 | |
299 | /** |
300 | * Returns command to reorient EClass based link. New link target or source |
301 | * should be the domain model element associated with this node. |
302 | * |
303 | * @generated |
304 | */ |
305 | protected Command getReorientRelationshipCommand( |
306 | ReorientRelationshipRequest req) { |
307 | switch (getVisualID(req)) { |
308 | case OperationProvidedRoleEditPart.VISUAL_ID: |
309 | return getGEFWrapper(new OperationProvidedRoleReorientCommand(req)); |
310 | case InfrastructureProvidedRoleEditPart.VISUAL_ID: |
311 | return getGEFWrapper(new InfrastructureProvidedRoleReorientCommand( |
312 | req)); |
313 | case InfrastructureRequiredRoleEditPart.VISUAL_ID: |
314 | return getGEFWrapper(new InfrastructureRequiredRoleReorientCommand( |
315 | req)); |
316 | case SinkRoleEditPart.VISUAL_ID: |
317 | return getGEFWrapper(new SinkRoleReorientCommand(req)); |
318 | case OperationRequiredRoleEditPart.VISUAL_ID: |
319 | return getGEFWrapper(new OperationRequiredRoleReorientCommand(req)); |
320 | case SourceRoleEditPart.VISUAL_ID: |
321 | return getGEFWrapper(new SourceRoleReorientCommand(req)); |
322 | } |
323 | return super.getReorientRelationshipCommand(req); |
324 | } |
325 | |
326 | /** |
327 | * Returns command to reorient EReference based link. New link target or source |
328 | * should be the domain model element associated with this node. |
329 | * |
330 | * @generated |
331 | */ |
332 | protected Command getReorientReferenceRelationshipCommand( |
333 | ReorientReferenceRelationshipRequest req) { |
334 | switch (getVisualID(req)) { |
335 | case ImplementationComponentTypeParentCompleteComponentTypesEditPart.VISUAL_ID: |
336 | return getGEFWrapper(new ImplementationComponentTypeParentCompleteComponentTypesReorientCommand( |
337 | req)); |
338 | } |
339 | return super.getReorientReferenceRelationshipCommand(req); |
340 | } |
341 | |
342 | } |