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