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