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.AssemblyEventConnector; |
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.SinkRole; |
18 | import de.uka.ipd.sdq.pcm.repository.SourceRole; |
19 | |
20 | /** |
21 | * @generated |
22 | */ |
23 | public class AssemblyEventConnectorReorientCommand extends 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 AssemblyEventConnectorReorientCommand( |
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 AssemblyEventConnector) { |
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 SourceRole && newEnd instanceof SourceRole)) { |
72 | return false; |
73 | } |
74 | SinkRole target = getLink().getSinkRole__AssemblyEventConnector(); |
75 | if (!(getLink().eContainer() instanceof ComposedStructure)) { |
76 | return false; |
77 | } |
78 | ComposedStructure container = (ComposedStructure) getLink() |
79 | .eContainer(); |
80 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
81 | .canExistAssemblyEventConnector_4007(container, getNewSource(), |
82 | target); |
83 | } |
84 | |
85 | /** |
86 | * @generated |
87 | */ |
88 | protected boolean canReorientTarget() { |
89 | if (!(oldEnd instanceof SinkRole && newEnd instanceof SinkRole)) { |
90 | return false; |
91 | } |
92 | SourceRole source = getLink().getSourceRole__AssemblyEventConnector(); |
93 | if (!(getLink().eContainer() instanceof ComposedStructure)) { |
94 | return false; |
95 | } |
96 | ComposedStructure container = (ComposedStructure) getLink() |
97 | .eContainer(); |
98 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
99 | .canExistAssemblyEventConnector_4007(container, source, |
100 | getNewTarget()); |
101 | } |
102 | |
103 | /** |
104 | * @generated |
105 | */ |
106 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
107 | IAdaptable info) throws ExecutionException { |
108 | if (!canExecute()) { |
109 | throw new ExecutionException( |
110 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
111 | } |
112 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
113 | return reorientSource(); |
114 | } |
115 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
116 | return reorientTarget(); |
117 | } |
118 | throw new IllegalStateException(); |
119 | } |
120 | |
121 | /** |
122 | * @generated |
123 | */ |
124 | protected CommandResult reorientSource() throws ExecutionException { |
125 | getLink().setSourceRole__AssemblyEventConnector(getNewSource()); |
126 | return CommandResult.newOKCommandResult(getLink()); |
127 | } |
128 | |
129 | /** |
130 | * @generated |
131 | */ |
132 | protected CommandResult reorientTarget() throws ExecutionException { |
133 | getLink().setSinkRole__AssemblyEventConnector(getNewTarget()); |
134 | return CommandResult.newOKCommandResult(getLink()); |
135 | } |
136 | |
137 | /** |
138 | * @generated |
139 | */ |
140 | protected AssemblyEventConnector getLink() { |
141 | return (AssemblyEventConnector) getElementToEdit(); |
142 | } |
143 | |
144 | /** |
145 | * @generated |
146 | */ |
147 | protected SourceRole getOldSource() { |
148 | return (SourceRole) oldEnd; |
149 | } |
150 | |
151 | /** |
152 | * @generated |
153 | */ |
154 | protected SourceRole getNewSource() { |
155 | return (SourceRole) newEnd; |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected SinkRole getOldTarget() { |
162 | return (SinkRole) oldEnd; |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | protected SinkRole getNewTarget() { |
169 | return (SinkRole) newEnd; |
170 | } |
171 | } |