1 | /* |
2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.edit.policies; |
5 | |
6 | import java.util.Collections; |
7 | import java.util.Iterator; |
8 | import java.util.Map; |
9 | |
10 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
11 | import org.eclipse.gef.Request; |
12 | import org.eclipse.gef.commands.Command; |
13 | import org.eclipse.gef.commands.UnexecutableCommand; |
14 | import org.eclipse.gef.requests.ReconnectRequest; |
15 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
16 | import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand; |
17 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
18 | import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy; |
19 | import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; |
20 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
21 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.SemanticEditPolicy; |
22 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
23 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
24 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
25 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
26 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
27 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
28 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
29 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest; |
30 | import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest; |
31 | import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest; |
32 | import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; |
33 | import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest; |
34 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
35 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
36 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
37 | import org.eclipse.gmf.runtime.notation.View; |
38 | |
39 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.helpers.PalladioComponentModelBaseEditHelper; |
40 | import de.uka.ipd.sdq.pcm.gmf.seff.expressions.PalladioComponentModelAbstractExpression; |
41 | import de.uka.ipd.sdq.pcm.gmf.seff.expressions.PalladioComponentModelOCLFactory; |
42 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelSeffDiagramEditorPlugin; |
43 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
44 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
45 | import de.uka.ipd.sdq.pcm.seff.AbstractAction; |
46 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
47 | |
48 | /** |
49 | * @generated |
50 | */ |
51 | public class PalladioComponentModelBaseItemSemanticEditPolicy extends |
52 | SemanticEditPolicy { |
53 | |
54 | /** |
55 | * Extended request data key to hold editpart visual id. |
56 | * |
57 | * @generated |
58 | */ |
59 | public static final String VISUAL_ID_KEY = "visual_id"; //$NON-NLS-1$ |
60 | |
61 | /** |
62 | * @generated |
63 | */ |
64 | private final IElementType myElementType; |
65 | |
66 | /** |
67 | * @generated |
68 | */ |
69 | protected PalladioComponentModelBaseItemSemanticEditPolicy( |
70 | IElementType elementType) { |
71 | myElementType = elementType; |
72 | } |
73 | |
74 | /** |
75 | * Add visual id of edited editpart to extended data of the request |
76 | * so command switch can decide what kind of diagram element is being edited. |
77 | * It is done in those cases when it's not possible to deduce diagram |
78 | * element kind from domain element. |
79 | * |
80 | * @generated |
81 | */ |
82 | public Command getCommand(Request request) { |
83 | if (request instanceof ReconnectRequest) { |
84 | Object view = ((ReconnectRequest) request).getConnectionEditPart() |
85 | .getModel(); |
86 | if (view instanceof View) { |
87 | Integer id = new Integer(PalladioComponentModelVisualIDRegistry |
88 | .getVisualID((View) view)); |
89 | request.getExtendedData().put(VISUAL_ID_KEY, id); |
90 | } |
91 | } |
92 | return super.getCommand(request); |
93 | } |
94 | |
95 | /** |
96 | * Returns visual id from request parameters. |
97 | * |
98 | * @generated |
99 | */ |
100 | protected int getVisualID(IEditCommandRequest request) { |
101 | Object id = request.getParameter(VISUAL_ID_KEY); |
102 | return id instanceof Integer ? ((Integer) id).intValue() : -1; |
103 | } |
104 | |
105 | /** |
106 | * @generated |
107 | */ |
108 | protected Command getSemanticCommand(IEditCommandRequest request) { |
109 | IEditCommandRequest completedRequest = completeRequest(request); |
110 | Command semanticCommand = getSemanticCommandSwitch(completedRequest); |
111 | semanticCommand = getEditHelperCommand(completedRequest, |
112 | semanticCommand); |
113 | if (completedRequest instanceof DestroyRequest) { |
114 | DestroyRequest destroyRequest = (DestroyRequest) completedRequest; |
115 | return shouldProceed(destroyRequest) ? addDeleteViewCommand( |
116 | semanticCommand, destroyRequest) : null; |
117 | } |
118 | return semanticCommand; |
119 | } |
120 | |
121 | /** |
122 | * @generated |
123 | */ |
124 | protected Command addDeleteViewCommand(Command mainCommand, |
125 | DestroyRequest completedRequest) { |
126 | Command deleteViewCommand = getGEFWrapper(new DeleteCommand( |
127 | getEditingDomain(), (View) getHost().getModel())); |
128 | return mainCommand == null ? deleteViewCommand : mainCommand |
129 | .chain(deleteViewCommand); |
130 | } |
131 | |
132 | /** |
133 | * @generated |
134 | */ |
135 | private Command getEditHelperCommand(IEditCommandRequest request, |
136 | Command editPolicyCommand) { |
137 | if (editPolicyCommand != null) { |
138 | ICommand command = editPolicyCommand instanceof ICommandProxy ? ((ICommandProxy) editPolicyCommand) |
139 | .getICommand() |
140 | : new CommandProxy(editPolicyCommand); |
141 | request.setParameter( |
142 | PalladioComponentModelBaseEditHelper.EDIT_POLICY_COMMAND, |
143 | command); |
144 | } |
145 | IElementType requestContextElementType = getContextElementType(request); |
146 | request.setParameter( |
147 | PalladioComponentModelBaseEditHelper.CONTEXT_ELEMENT_TYPE, |
148 | requestContextElementType); |
149 | ICommand command = requestContextElementType.getEditCommand(request); |
150 | request.setParameter( |
151 | PalladioComponentModelBaseEditHelper.EDIT_POLICY_COMMAND, null); |
152 | request |
153 | .setParameter( |
154 | PalladioComponentModelBaseEditHelper.CONTEXT_ELEMENT_TYPE, |
155 | null); |
156 | if (command != null) { |
157 | if (!(command instanceof CompositeTransactionalCommand)) { |
158 | command = new CompositeTransactionalCommand(getEditingDomain(), |
159 | command.getLabel()).compose(command); |
160 | } |
161 | return new ICommandProxy(command); |
162 | } |
163 | return editPolicyCommand; |
164 | } |
165 | |
166 | /** |
167 | * @generated |
168 | */ |
169 | private IElementType getContextElementType(IEditCommandRequest request) { |
170 | IElementType requestContextElementType = PalladioComponentModelElementTypes |
171 | .getElementType(getVisualID(request)); |
172 | return requestContextElementType != null ? requestContextElementType |
173 | : myElementType; |
174 | } |
175 | |
176 | /** |
177 | * @generated |
178 | */ |
179 | protected Command getSemanticCommandSwitch(IEditCommandRequest req) { |
180 | if (req instanceof CreateRelationshipRequest) { |
181 | return getCreateRelationshipCommand((CreateRelationshipRequest) req); |
182 | } else if (req instanceof CreateElementRequest) { |
183 | return getCreateCommand((CreateElementRequest) req); |
184 | } else if (req instanceof ConfigureRequest) { |
185 | return getConfigureCommand((ConfigureRequest) req); |
186 | } else if (req instanceof DestroyElementRequest) { |
187 | return getDestroyElementCommand((DestroyElementRequest) req); |
188 | } else if (req instanceof DestroyReferenceRequest) { |
189 | return getDestroyReferenceCommand((DestroyReferenceRequest) req); |
190 | } else if (req instanceof DuplicateElementsRequest) { |
191 | return getDuplicateCommand((DuplicateElementsRequest) req); |
192 | } else if (req instanceof GetEditContextRequest) { |
193 | return getEditContextCommand((GetEditContextRequest) req); |
194 | } else if (req instanceof MoveRequest) { |
195 | return getMoveCommand((MoveRequest) req); |
196 | } else if (req instanceof ReorientReferenceRelationshipRequest) { |
197 | return getReorientReferenceRelationshipCommand((ReorientReferenceRelationshipRequest) req); |
198 | } else if (req instanceof ReorientRelationshipRequest) { |
199 | return getReorientRelationshipCommand((ReorientRelationshipRequest) req); |
200 | } else if (req instanceof SetRequest) { |
201 | return getSetCommand((SetRequest) req); |
202 | } |
203 | return null; |
204 | } |
205 | |
206 | /** |
207 | * @generated |
208 | */ |
209 | protected Command getConfigureCommand(ConfigureRequest req) { |
210 | return null; |
211 | } |
212 | |
213 | /** |
214 | * @generated |
215 | */ |
216 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
217 | return null; |
218 | } |
219 | |
220 | /** |
221 | * @generated |
222 | */ |
223 | protected Command getCreateCommand(CreateElementRequest req) { |
224 | return null; |
225 | } |
226 | |
227 | /** |
228 | * @generated |
229 | */ |
230 | protected Command getSetCommand(SetRequest req) { |
231 | return null; |
232 | } |
233 | |
234 | /** |
235 | * @generated |
236 | */ |
237 | protected Command getEditContextCommand(GetEditContextRequest req) { |
238 | return null; |
239 | } |
240 | |
241 | /** |
242 | * @generated |
243 | */ |
244 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
245 | return null; |
246 | } |
247 | |
248 | /** |
249 | * @generated |
250 | */ |
251 | protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) { |
252 | return null; |
253 | } |
254 | |
255 | /** |
256 | * @generated |
257 | */ |
258 | protected Command getDuplicateCommand(DuplicateElementsRequest req) { |
259 | return null; |
260 | } |
261 | |
262 | /** |
263 | * @generated |
264 | */ |
265 | protected Command getMoveCommand(MoveRequest req) { |
266 | return null; |
267 | } |
268 | |
269 | /** |
270 | * @generated |
271 | */ |
272 | protected Command getReorientReferenceRelationshipCommand( |
273 | ReorientReferenceRelationshipRequest req) { |
274 | return UnexecutableCommand.INSTANCE; |
275 | } |
276 | |
277 | /** |
278 | * @generated |
279 | */ |
280 | protected Command getReorientRelationshipCommand( |
281 | ReorientRelationshipRequest req) { |
282 | return UnexecutableCommand.INSTANCE; |
283 | } |
284 | |
285 | /** |
286 | * @generated |
287 | */ |
288 | protected final Command getGEFWrapper(ICommand cmd) { |
289 | return new ICommandProxy(cmd); |
290 | } |
291 | |
292 | /** |
293 | * Returns editing domain from the host edit part. |
294 | * |
295 | * @generated |
296 | */ |
297 | protected TransactionalEditingDomain getEditingDomain() { |
298 | return ((IGraphicalEditPart) getHost()).getEditingDomain(); |
299 | } |
300 | |
301 | /** |
302 | * Clean all shortcuts to the host element from the same diagram |
303 | * @generated |
304 | */ |
305 | protected void addDestroyShortcutsCommand(ICompositeCommand cmd, View view) { |
306 | assert view.getEAnnotation("Shortcut") == null; //$NON-NLS-1$ |
307 | for (Iterator it = view.getDiagram().getChildren().iterator(); it |
308 | .hasNext();) { |
309 | View nextView = (View) it.next(); |
310 | if (nextView.getEAnnotation("Shortcut") == null || !nextView.isSetElement() || nextView.getElement() != view.getElement()) { //$NON-NLS-1$ |
311 | continue; |
312 | } |
313 | cmd.add(new DeleteCommand(getEditingDomain(), nextView)); |
314 | } |
315 | } |
316 | |
317 | /** |
318 | * @generated |
319 | */ |
320 | public static class LinkConstraints { |
321 | |
322 | /** |
323 | * @generated |
324 | */ |
325 | private static final String OPPOSITE_END_VAR = "oppositeEnd"; //$NON-NLS-1$ |
326 | /** |
327 | * @generated |
328 | */ |
329 | private static PalladioComponentModelAbstractExpression AbstractActionSuccessor_AbstractAction_4001_SourceExpression; |
330 | /** |
331 | * @generated |
332 | */ |
333 | private static PalladioComponentModelAbstractExpression AbstractActionSuccessor_AbstractAction_4001_TargetExpression; |
334 | |
335 | /** |
336 | * @generated |
337 | */ |
338 | private static PalladioComponentModelAbstractExpression RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_SourceExpression; |
339 | /** |
340 | * @generated |
341 | */ |
342 | private static PalladioComponentModelAbstractExpression RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_TargetExpression; |
343 | |
344 | /** |
345 | * @generated |
346 | */ |
347 | public static boolean canCreateAbstractActionSuccessor_AbstractAction_4001( |
348 | AbstractAction source, AbstractAction target) { |
349 | if (source != null) { |
350 | if (source.getSuccessor_AbstractAction() != null) { |
351 | return false; |
352 | } |
353 | } |
354 | if (target != null |
355 | && (target.getPredecessor_AbstractAction() != null)) { |
356 | return false; |
357 | } |
358 | |
359 | return canExistAbstractActionSuccessor_AbstractAction_4001(source, |
360 | target); |
361 | } |
362 | |
363 | /** |
364 | * @generated |
365 | */ |
366 | public static boolean canCreateRecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004( |
367 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour source, |
368 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour target) { |
369 | if (source != null) { |
370 | if (source |
371 | .getFailureHandlingAlternatives__RecoveryActionBehaviour() |
372 | .contains(target)) { |
373 | return false; |
374 | } |
375 | } |
376 | |
377 | return canExistRecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004( |
378 | source, target); |
379 | } |
380 | |
381 | /** |
382 | * @generated |
383 | */ |
384 | public static boolean canExistAbstractActionSuccessor_AbstractAction_4001( |
385 | AbstractAction source, AbstractAction target) { |
386 | try { |
387 | if (source == null) { |
388 | return true; |
389 | } |
390 | if (AbstractActionSuccessor_AbstractAction_4001_SourceExpression == null) { |
391 | Map env = Collections.singletonMap(OPPOSITE_END_VAR, |
392 | SeffPackage.eINSTANCE.getAbstractAction()); |
393 | AbstractActionSuccessor_AbstractAction_4001_SourceExpression = PalladioComponentModelOCLFactory |
394 | .getExpression( |
395 | "not self.oclIsTypeOf(StopAction)", SeffPackage.eINSTANCE.getAbstractAction(), env); //$NON-NLS-1$ |
396 | } |
397 | Object sourceVal = AbstractActionSuccessor_AbstractAction_4001_SourceExpression |
398 | .evaluate(source, Collections.singletonMap( |
399 | OPPOSITE_END_VAR, target)); |
400 | if (false == sourceVal instanceof Boolean |
401 | || !((Boolean) sourceVal).booleanValue()) { |
402 | return false; |
403 | } // else fall-through |
404 | if (target == null) { |
405 | return true; |
406 | } |
407 | if (AbstractActionSuccessor_AbstractAction_4001_TargetExpression == null) { |
408 | Map env = Collections.singletonMap(OPPOSITE_END_VAR, |
409 | SeffPackage.eINSTANCE.getAbstractAction()); |
410 | AbstractActionSuccessor_AbstractAction_4001_TargetExpression = PalladioComponentModelOCLFactory |
411 | .getExpression( |
412 | "self.predecessor_AbstractAction = null and not self.oclIsTypeOf(StartAction)", SeffPackage.eINSTANCE.getAbstractAction(), env); //$NON-NLS-1$ |
413 | } |
414 | Object targetVal = AbstractActionSuccessor_AbstractAction_4001_TargetExpression |
415 | .evaluate(target, Collections.singletonMap( |
416 | OPPOSITE_END_VAR, source)); |
417 | if (false == targetVal instanceof Boolean |
418 | || !((Boolean) targetVal).booleanValue()) { |
419 | return false; |
420 | } // else fall-through |
421 | return true; |
422 | } catch (Exception e) { |
423 | PalladioComponentModelSeffDiagramEditorPlugin.getInstance() |
424 | .logError("Link constraint evaluation error", e); //$NON-NLS-1$ |
425 | return false; |
426 | } |
427 | } |
428 | |
429 | /** |
430 | * @generated |
431 | */ |
432 | public static boolean canExistRecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004( |
433 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour source, |
434 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour target) { |
435 | try { |
436 | if (source == null) { |
437 | return true; |
438 | } |
439 | if (RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_SourceExpression == null) { |
440 | Map env = Collections |
441 | .singletonMap( |
442 | OPPOSITE_END_VAR, |
443 | de.uka.ipd.sdq.pcm.seff.seff_reliability.Seff_reliabilityPackage.eINSTANCE |
444 | .getRecoveryActionBehaviour()); |
445 | RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_SourceExpression = PalladioComponentModelOCLFactory |
446 | .getExpression( |
447 | "not self.failureHandlingAlternatives__RecoveryActionBehaviour->exists(x,y:RecoveryActionBehaviour | x<>y and not x.failureTypes_FailureHandlingEntity->intersection(y.failureTypes_FailureHandlingEntity)->isEmpty())", de.uka.ipd.sdq.pcm.seff.seff_reliability.Seff_reliabilityPackage.eINSTANCE.getRecoveryActionBehaviour(), env); //$NON-NLS-1$ |
448 | } |
449 | Object sourceVal = RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_SourceExpression |
450 | .evaluate(source, Collections.singletonMap( |
451 | OPPOSITE_END_VAR, target)); |
452 | if (false == sourceVal instanceof Boolean |
453 | || !((Boolean) sourceVal).booleanValue()) { |
454 | return false; |
455 | } // else fall-through |
456 | if (target == null) { |
457 | return true; |
458 | } |
459 | if (RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_TargetExpression == null) { |
460 | Map env = Collections |
461 | .singletonMap( |
462 | OPPOSITE_END_VAR, |
463 | de.uka.ipd.sdq.pcm.seff.seff_reliability.Seff_reliabilityPackage.eINSTANCE |
464 | .getRecoveryActionBehaviour()); |
465 | RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_TargetExpression = PalladioComponentModelOCLFactory |
466 | .getExpression( |
467 | "(not self.recoveryAction__RecoveryActionBehaviour.recoveryActionBehaviours__RecoveryAction->exists(x,y:RecoveryActionBehaviour | x<>y and x.failureHandlingAlternatives__RecoveryActionBehaviour->includes(self) and y.failureHandlingAlternatives__RecoveryActionBehaviour->includes(self))) and (self.recoveryAction__RecoveryActionBehaviour = oppositeEnd.recoveryAction__RecoveryActionBehaviour)", de.uka.ipd.sdq.pcm.seff.seff_reliability.Seff_reliabilityPackage.eINSTANCE.getRecoveryActionBehaviour(), env); //$NON-NLS-1$ |
468 | } |
469 | Object targetVal = RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004_TargetExpression |
470 | .evaluate(target, Collections.singletonMap( |
471 | OPPOSITE_END_VAR, source)); |
472 | if (false == targetVal instanceof Boolean |
473 | || !((Boolean) targetVal).booleanValue()) { |
474 | return false; |
475 | } // else fall-through |
476 | return true; |
477 | } catch (Exception e) { |
478 | PalladioComponentModelSeffDiagramEditorPlugin.getInstance() |
479 | .logError("Link constraint evaluation error", e); //$NON-NLS-1$ |
480 | return false; |
481 | } |
482 | } |
483 | |
484 | } |
485 | |
486 | } |