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.ReorientReferenceRelationshipRequest; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
14 | |
15 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
16 | import de.uka.ipd.sdq.pcm.seff.AbstractAction; |
17 | |
18 | /** |
19 | * @generated |
20 | */ |
21 | public class AbstractActionSuccessor_AbstractActionReorientCommand extends |
22 | EditElementCommand { |
23 | |
24 | /** |
25 | * @generated |
26 | */ |
27 | private final int reorientDirection; |
28 | |
29 | /** |
30 | * @generated |
31 | */ |
32 | private final EObject referenceOwner; |
33 | |
34 | /** |
35 | * @generated |
36 | */ |
37 | private final EObject oldEnd; |
38 | |
39 | /** |
40 | * @generated |
41 | */ |
42 | private final EObject newEnd; |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | public AbstractActionSuccessor_AbstractActionReorientCommand( |
48 | ReorientReferenceRelationshipRequest request) { |
49 | super(request.getLabel(), null, request); |
50 | reorientDirection = request.getDirection(); |
51 | referenceOwner = request.getReferenceOwner(); |
52 | oldEnd = request.getOldRelationshipEnd(); |
53 | newEnd = request.getNewRelationshipEnd(); |
54 | } |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | public boolean canExecute() { |
60 | if (false == referenceOwner instanceof AbstractAction) { |
61 | return false; |
62 | } |
63 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
64 | return canReorientSource(); |
65 | } |
66 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
67 | return canReorientTarget(); |
68 | } |
69 | return false; |
70 | } |
71 | |
72 | /** |
73 | * @generated |
74 | */ |
75 | protected boolean canReorientSource() { |
76 | if (!(oldEnd instanceof AbstractAction && newEnd instanceof AbstractAction)) { |
77 | return false; |
78 | } |
79 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
80 | .canExistAbstractActionSuccessor_AbstractAction_4001( |
81 | getNewSource(), getOldTarget()); |
82 | } |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | protected boolean canReorientTarget() { |
88 | if (!(oldEnd instanceof AbstractAction && newEnd instanceof AbstractAction)) { |
89 | return false; |
90 | } |
91 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
92 | .canExistAbstractActionSuccessor_AbstractAction_4001( |
93 | getOldSource(), getNewTarget()); |
94 | } |
95 | |
96 | /** |
97 | * @generated |
98 | */ |
99 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
100 | IAdaptable info) throws ExecutionException { |
101 | if (!canExecute()) { |
102 | throw new ExecutionException( |
103 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
104 | } |
105 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
106 | return reorientSource(); |
107 | } |
108 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
109 | return reorientTarget(); |
110 | } |
111 | throw new IllegalStateException(); |
112 | } |
113 | |
114 | /** |
115 | * @generated |
116 | */ |
117 | protected CommandResult reorientSource() throws ExecutionException { |
118 | getOldSource().setSuccessor_AbstractAction(null); |
119 | getNewSource().setSuccessor_AbstractAction(getOldTarget()); |
120 | return CommandResult.newOKCommandResult(referenceOwner); |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | protected CommandResult reorientTarget() throws ExecutionException { |
127 | getOldSource().setSuccessor_AbstractAction(getNewTarget()); |
128 | return CommandResult.newOKCommandResult(referenceOwner); |
129 | } |
130 | |
131 | /** |
132 | * @generated |
133 | */ |
134 | protected AbstractAction getOldSource() { |
135 | return (AbstractAction) referenceOwner; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected AbstractAction getNewSource() { |
142 | return (AbstractAction) newEnd; |
143 | } |
144 | |
145 | /** |
146 | * @generated |
147 | */ |
148 | protected AbstractAction getOldTarget() { |
149 | return (AbstractAction) oldEnd; |
150 | } |
151 | |
152 | /** |
153 | * @generated |
154 | */ |
155 | protected AbstractAction getNewTarget() { |
156 | return (AbstractAction) newEnd; |
157 | } |
158 | } |