1 | /* |
2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.edit.commands; |
5 | |
6 | import org.eclipse.core.commands.ExecutionException; |
7 | import org.eclipse.core.runtime.IAdaptable; |
8 | import org.eclipse.core.runtime.IProgressMonitor; |
9 | import org.eclipse.emf.ecore.EObject; |
10 | import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
11 | import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
13 | |
14 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
15 | |
16 | /** |
17 | * @generated |
18 | */ |
19 | public class RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviourCreateCommand |
20 | extends EditElementCommand { |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | private final EObject source; |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | private final EObject target; |
31 | |
32 | /** |
33 | * @generated |
34 | */ |
35 | public RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviourCreateCommand( |
36 | CreateRelationshipRequest request, EObject source, EObject target) { |
37 | super(request.getLabel(), null, request); |
38 | this.source = source; |
39 | this.target = target; |
40 | } |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | public boolean canExecute() { |
46 | if (source == null && target == null) { |
47 | return false; |
48 | } |
49 | if (source != null |
50 | && false == source instanceof de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour) { |
51 | return false; |
52 | } |
53 | if (target != null |
54 | && false == target instanceof de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour) { |
55 | return false; |
56 | } |
57 | if (getSource() == null) { |
58 | return true; // link creation is in progress; source is not defined yet |
59 | } |
60 | // target may be null here but it's possible to check constraint |
61 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
62 | .canCreateRecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004( |
63 | getSource(), getTarget()); |
64 | } |
65 | |
66 | /** |
67 | * @generated |
68 | */ |
69 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
70 | IAdaptable info) throws ExecutionException { |
71 | if (!canExecute()) { |
72 | throw new ExecutionException( |
73 | "Invalid arguments in create link command"); //$NON-NLS-1$ |
74 | } |
75 | |
76 | if (getSource() != null && getTarget() != null) { |
77 | getSource() |
78 | .getFailureHandlingAlternatives__RecoveryActionBehaviour() |
79 | .add(getTarget()); |
80 | } |
81 | return CommandResult.newOKCommandResult(); |
82 | |
83 | } |
84 | |
85 | /** |
86 | * @generated |
87 | */ |
88 | protected void setElementToEdit(EObject element) { |
89 | throw new UnsupportedOperationException(); |
90 | } |
91 | |
92 | /** |
93 | * @generated |
94 | */ |
95 | protected de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour getSource() { |
96 | return (de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour) source; |
97 | } |
98 | |
99 | /** |
100 | * @generated |
101 | */ |
102 | protected de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour getTarget() { |
103 | return (de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour) target; |
104 | } |
105 | } |