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