1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.policies; |
5 | |
6 | import java.util.Iterator; |
7 | |
8 | import org.eclipse.emf.ecore.EAnnotation; |
9 | import org.eclipse.emf.ecore.EObject; |
10 | import org.eclipse.gef.commands.Command; |
11 | import org.eclipse.gef.commands.UnexecutableCommand; |
12 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
13 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
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.ReorientRelationshipRequest; |
18 | import org.eclipse.gmf.runtime.notation.Edge; |
19 | import org.eclipse.gmf.runtime.notation.View; |
20 | |
21 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
22 | import de.uka.ipd.sdq.pcm.core.composition.CompositionPackage; |
23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorCreateCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorReorientCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorTypeLinkCreateCommand; |
26 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.ProvidedDelegationConnectorCreateCommand; |
27 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.ProvidedDelegationConnectorReorientCommand; |
28 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.ProvidedDelegationConnectorTypeLinkCreateCommand; |
29 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyConnectorEditPart; |
30 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ProvidedDelegationConnectorEditPart; |
31 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
32 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
33 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
34 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
35 | |
36 | /** |
37 | * @generated |
38 | */ |
39 | public class OperationProvidedRoleItemSemanticEditPolicy extends |
40 | PalladioComponentModelBaseItemSemanticEditPolicy { |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | public OperationProvidedRoleItemSemanticEditPolicy() { |
46 | super(PalladioComponentModelElementTypes.OperationProvidedRole_3007); |
47 | } |
48 | |
49 | /** |
50 | * @generated |
51 | */ |
52 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
53 | View view = (View) getHost().getModel(); |
54 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
55 | getEditingDomain(), null); |
56 | cmd.setTransactionNestingEnabled(false); |
57 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
58 | Edge incomingLink = (Edge) it.next(); |
59 | if (PalladioComponentModelVisualIDRegistry |
60 | .getVisualID(incomingLink) == AssemblyConnectorEditPart.VISUAL_ID) { |
61 | DestroyElementRequest r = new DestroyElementRequest( |
62 | incomingLink.getElement(), false); |
63 | cmd.add(new DestroyElementCommand(r)); |
64 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
65 | continue; |
66 | } |
67 | if (PalladioComponentModelVisualIDRegistry |
68 | .getVisualID(incomingLink) == ProvidedDelegationConnectorEditPart.VISUAL_ID) { |
69 | DestroyElementRequest r = new DestroyElementRequest( |
70 | incomingLink.getElement(), false); |
71 | cmd.add(new DestroyElementCommand(r)); |
72 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
73 | continue; |
74 | } |
75 | } |
76 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
77 | Edge outgoingLink = (Edge) it.next(); |
78 | if (PalladioComponentModelVisualIDRegistry |
79 | .getVisualID(outgoingLink) == ProvidedDelegationConnectorEditPart.VISUAL_ID) { |
80 | DestroyElementRequest r = new DestroyElementRequest( |
81 | outgoingLink.getElement(), false); |
82 | cmd.add(new DestroyElementCommand(r)); |
83 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
84 | continue; |
85 | } |
86 | } |
87 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
88 | if (annotation == null) { |
89 | // there are indirectly referenced children, need extra commands: false |
90 | addDestroyShortcutsCommand(cmd, view); |
91 | // delete host element |
92 | cmd.add(new DestroyElementCommand(req)); |
93 | } else { |
94 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
95 | } |
96 | return getGEFWrapper(cmd.reduce()); |
97 | } |
98 | |
99 | /** |
100 | * Get the create relationship command or null / UnexecutableCommand instance |
101 | * if this is not an valid end for the connector creation. |
102 | * |
103 | * @generated not |
104 | */ |
105 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
106 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
107 | .getElementType()) { |
108 | return req.getTarget() == null ? null |
109 | : getCompleteCreateRelationshipCommandAssemblyConnector(req); |
110 | } |
111 | if (PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006 == req |
112 | .getElementType()) { |
113 | return req.getTarget() == null ? null |
114 | : getCompleteCreateRelationshipCommandProvidedDelegationConnector(req); |
115 | } |
116 | return super.getCreateRelationshipCommand(req); |
117 | } |
118 | |
119 | /** |
120 | * Get the complete create relationship command |
121 | * if the relationship is about an internal assembly connector. |
122 | * |
123 | * @param req The request object for this command request |
124 | * @return The prepared command. |
125 | * |
126 | * @generated not |
127 | */ |
128 | protected Command getCompleteCreateRelationshipCommandAssemblyConnector( |
129 | CreateRelationshipRequest req) { |
130 | EObject sourceEObject = req.getSource(); |
131 | EObject targetEObject = req.getTarget(); |
132 | if (false == sourceEObject instanceof OperationRequiredRole |
133 | || false == targetEObject instanceof OperationProvidedRole) { |
134 | return UnexecutableCommand.INSTANCE; |
135 | } |
136 | OperationRequiredRole source = (OperationRequiredRole) sourceEObject; |
137 | OperationProvidedRole target = (OperationProvidedRole) targetEObject; |
138 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
139 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
140 | req.getElementType()); |
141 | if (container == null) { |
142 | return UnexecutableCommand.INSTANCE; |
143 | } |
144 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
145 | .canCreateAssemblyConnector_4004(container, source, target)) { |
146 | return UnexecutableCommand.INSTANCE; |
147 | } |
148 | if (req.getContainmentFeature() == null) { |
149 | req.setContainmentFeature(CompositionPackage.eINSTANCE |
150 | .getComposedStructure_Connectors__ComposedStructure()); |
151 | } |
152 | req.setParameter("PROV_CHILD_CONTEXT", ((View) getHost().getParent() |
153 | .getModel()).getElement()); |
154 | return getGEFWrapper(new AssemblyConnectorTypeLinkCreateCommand(req, |
155 | container, source, target)); |
156 | } |
157 | |
158 | /** |
159 | * Get the complete create relationship command |
160 | * if the relationship is about a operation provided delegation connector. |
161 | * |
162 | * @param req The request object for this command request |
163 | * @return The prepared command. |
164 | * |
165 | * @generated not |
166 | */ |
167 | protected Command getCompleteCreateRelationshipCommandProvidedDelegationConnector( |
168 | CreateRelationshipRequest req) { |
169 | EObject sourceEObject = req.getSource(); |
170 | EObject targetEObject = req.getTarget(); |
171 | if (false == sourceEObject instanceof OperationProvidedRole |
172 | || false == targetEObject instanceof OperationProvidedRole) { |
173 | return UnexecutableCommand.INSTANCE; |
174 | } |
175 | OperationProvidedRole source = (OperationProvidedRole) sourceEObject; |
176 | OperationProvidedRole target = (OperationProvidedRole) targetEObject; |
177 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
178 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
179 | req.getElementType()); |
180 | if (container == null) { |
181 | return UnexecutableCommand.INSTANCE; |
182 | } |
183 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
184 | .canCreateProvidedDelegationConnector_4006(container, source, |
185 | target)) { |
186 | return UnexecutableCommand.INSTANCE; |
187 | } |
188 | if (req.getContainmentFeature() == null) { |
189 | req.setContainmentFeature(CompositionPackage.eINSTANCE |
190 | .getComposedStructure_Connectors__ComposedStructure()); |
191 | } |
192 | req.setParameter("CHILD_CONTEXT", ((View) getHost().getParent() |
193 | .getModel()).getElement()); |
194 | return getGEFWrapper(new ProvidedDelegationConnectorTypeLinkCreateCommand( |
195 | req, container, source, target)); |
196 | } |
197 | |
198 | /** |
199 | * @generated |
200 | */ |
201 | protected Command getStartCreateRelationshipCommand( |
202 | CreateRelationshipRequest req) { |
203 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
204 | .getElementType()) { |
205 | return null; |
206 | } |
207 | if (PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006 == req |
208 | .getElementType()) { |
209 | return getGEFWrapper(new ProvidedDelegationConnectorCreateCommand( |
210 | req, req.getSource(), req.getTarget())); |
211 | } |
212 | return null; |
213 | } |
214 | |
215 | /** |
216 | * @generated |
217 | */ |
218 | protected Command getCompleteCreateRelationshipCommand( |
219 | CreateRelationshipRequest req) { |
220 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
221 | .getElementType()) { |
222 | return getGEFWrapper(new AssemblyConnectorCreateCommand(req, req |
223 | .getSource(), req.getTarget())); |
224 | } |
225 | if (PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006 == req |
226 | .getElementType()) { |
227 | return getGEFWrapper(new ProvidedDelegationConnectorCreateCommand( |
228 | req, req.getSource(), req.getTarget())); |
229 | } |
230 | return null; |
231 | } |
232 | |
233 | /** |
234 | * Returns command to reorient EClass based link. New link target or source |
235 | * should be the domain model element associated with this node. |
236 | * |
237 | * @generated |
238 | */ |
239 | protected Command getReorientRelationshipCommand( |
240 | ReorientRelationshipRequest req) { |
241 | switch (getVisualID(req)) { |
242 | case AssemblyConnectorEditPart.VISUAL_ID: |
243 | return getGEFWrapper(new AssemblyConnectorReorientCommand(req)); |
244 | case ProvidedDelegationConnectorEditPart.VISUAL_ID: |
245 | return getGEFWrapper(new ProvidedDelegationConnectorReorientCommand( |
246 | req)); |
247 | } |
248 | return super.getReorientRelationshipCommand(req); |
249 | } |
250 | |
251 | } |