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