1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.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.ReorientRelationshipRequest; |
13 | |
14 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
15 | import de.uka.ipd.sdq.pcm.core.composition.RequiredDelegationConnector; |
16 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
17 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
18 | |
19 | /** |
20 | * @generated |
21 | */ |
22 | public class RequiredDelegationConnectorReorientCommand extends |
23 | EditElementCommand { |
24 | |
25 | /** |
26 | * @generated |
27 | */ |
28 | private final int reorientDirection; |
29 | |
30 | /** |
31 | * @generated |
32 | */ |
33 | private final EObject oldEnd; |
34 | |
35 | /** |
36 | * @generated |
37 | */ |
38 | private final EObject newEnd; |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | public RequiredDelegationConnectorReorientCommand( |
44 | ReorientRelationshipRequest request) { |
45 | super(request.getLabel(), request.getRelationship(), request); |
46 | reorientDirection = request.getDirection(); |
47 | oldEnd = request.getOldRelationshipEnd(); |
48 | newEnd = request.getNewRelationshipEnd(); |
49 | } |
50 | |
51 | /** |
52 | * @generated |
53 | */ |
54 | public boolean canExecute() { |
55 | if (false == getElementToEdit() instanceof RequiredDelegationConnector) { |
56 | return false; |
57 | } |
58 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
59 | return canReorientSource(); |
60 | } |
61 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
62 | return canReorientTarget(); |
63 | } |
64 | return false; |
65 | } |
66 | |
67 | /** |
68 | * @generated |
69 | */ |
70 | protected boolean canReorientSource() { |
71 | if (!(oldEnd instanceof OperationRequiredRole && newEnd instanceof OperationRequiredRole)) { |
72 | return false; |
73 | } |
74 | OperationRequiredRole target = getLink() |
75 | .getOuterRequiredRole_RequiredDelegationConnector(); |
76 | if (!(getLink().eContainer() instanceof ComposedStructure)) { |
77 | return false; |
78 | } |
79 | ComposedStructure container = (ComposedStructure) getLink() |
80 | .eContainer(); |
81 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
82 | .canExistRequiredDelegationConnector_4005(container, |
83 | getNewSource(), target); |
84 | } |
85 | |
86 | /** |
87 | * @generated |
88 | */ |
89 | protected boolean canReorientTarget() { |
90 | if (!(oldEnd instanceof OperationRequiredRole && newEnd instanceof OperationRequiredRole)) { |
91 | return false; |
92 | } |
93 | OperationRequiredRole source = getLink() |
94 | .getInnerRequiredRole_RequiredDelegationConnector(); |
95 | if (!(getLink().eContainer() instanceof ComposedStructure)) { |
96 | return false; |
97 | } |
98 | ComposedStructure container = (ComposedStructure) getLink() |
99 | .eContainer(); |
100 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
101 | .canExistRequiredDelegationConnector_4005(container, source, |
102 | getNewTarget()); |
103 | } |
104 | |
105 | /** |
106 | * @generated |
107 | */ |
108 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
109 | IAdaptable info) throws ExecutionException { |
110 | if (!canExecute()) { |
111 | throw new ExecutionException( |
112 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
113 | } |
114 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
115 | return reorientSource(); |
116 | } |
117 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
118 | return reorientTarget(); |
119 | } |
120 | throw new IllegalStateException(); |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | protected CommandResult reorientSource() throws ExecutionException { |
127 | getLink().setInnerRequiredRole_RequiredDelegationConnector( |
128 | getNewSource()); |
129 | return CommandResult.newOKCommandResult(getLink()); |
130 | } |
131 | |
132 | /** |
133 | * @generated |
134 | */ |
135 | protected CommandResult reorientTarget() throws ExecutionException { |
136 | getLink().setOuterRequiredRole_RequiredDelegationConnector( |
137 | getNewTarget()); |
138 | return CommandResult.newOKCommandResult(getLink()); |
139 | } |
140 | |
141 | /** |
142 | * @generated |
143 | */ |
144 | protected RequiredDelegationConnector getLink() { |
145 | return (RequiredDelegationConnector) getElementToEdit(); |
146 | } |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | protected OperationRequiredRole getOldSource() { |
152 | return (OperationRequiredRole) oldEnd; |
153 | } |
154 | |
155 | /** |
156 | * @generated |
157 | */ |
158 | protected OperationRequiredRole getNewSource() { |
159 | return (OperationRequiredRole) newEnd; |
160 | } |
161 | |
162 | /** |
163 | * @generated |
164 | */ |
165 | protected OperationRequiredRole getOldTarget() { |
166 | return (OperationRequiredRole) oldEnd; |
167 | } |
168 | |
169 | /** |
170 | * @generated |
171 | */ |
172 | protected OperationRequiredRole getNewTarget() { |
173 | return (OperationRequiredRole) newEnd; |
174 | } |
175 | } |