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 | import org.eclipse.swt.SWT; |
14 | import org.eclipse.swt.widgets.MessageBox; |
15 | import org.eclipse.swt.widgets.Shell; |
16 | import org.eclipse.ui.PlatformUI; |
17 | |
18 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyConnector; |
19 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
20 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
21 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
22 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
23 | |
24 | /** |
25 | * |
26 | * @author Christian Busch |
27 | * @generated |
28 | */ |
29 | public class AssemblyConnectorReorientCommand extends EditElementCommand { |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | private final int reorientDirection; |
35 | |
36 | /** |
37 | * @generated |
38 | */ |
39 | private final EObject oldEnd; |
40 | |
41 | /** |
42 | * @generated |
43 | */ |
44 | private final EObject newEnd; |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public AssemblyConnectorReorientCommand(ReorientRelationshipRequest request) { |
50 | super(request.getLabel(), request.getRelationship(), request); |
51 | reorientDirection = request.getDirection(); |
52 | oldEnd = request.getOldRelationshipEnd(); |
53 | newEnd = request.getNewRelationshipEnd(); |
54 | } |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | public boolean canExecute() { |
60 | if (false == getElementToEdit() instanceof AssemblyConnector) { |
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 OperationRequiredRole && newEnd instanceof OperationRequiredRole)) { |
77 | return false; |
78 | } |
79 | OperationProvidedRole target = getLink() |
80 | .getProvidedRole_AssemblyConnector(); |
81 | if (!(getLink().eContainer() instanceof ComposedStructure)) { |
82 | return false; |
83 | } |
84 | ComposedStructure container = (ComposedStructure) getLink() |
85 | .eContainer(); |
86 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
87 | .canExistAssemblyConnector_4004(container, getNewSource(), |
88 | target); |
89 | } |
90 | |
91 | /** |
92 | * @generated |
93 | */ |
94 | protected boolean canReorientTarget() { |
95 | if (!(oldEnd instanceof OperationProvidedRole && newEnd instanceof OperationProvidedRole)) { |
96 | return false; |
97 | } |
98 | OperationRequiredRole source = getLink() |
99 | .getRequiredRole_AssemblyConnector(); |
100 | if (!(getLink().eContainer() instanceof ComposedStructure)) { |
101 | return false; |
102 | } |
103 | ComposedStructure container = (ComposedStructure) getLink() |
104 | .eContainer(); |
105 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
106 | .canExistAssemblyConnector_4004(container, source, |
107 | getNewTarget()); |
108 | } |
109 | |
110 | /** |
111 | * @generated |
112 | */ |
113 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
114 | IAdaptable info) throws ExecutionException { |
115 | if (!canExecute()) { |
116 | throw new ExecutionException( |
117 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
118 | } |
119 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
120 | return reorientSource(); |
121 | } |
122 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
123 | return reorientTarget(); |
124 | } |
125 | throw new IllegalStateException(); |
126 | } |
127 | |
128 | /** |
129 | * @generated NOT |
130 | */ |
131 | protected CommandResult reorientSource() throws ExecutionException { |
132 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() |
133 | .getShell(); |
134 | MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); |
135 | messageBox.setText("Notice"); |
136 | messageBox |
137 | .setMessage("Please delete the link and create a new one instead of reorienting it."); |
138 | messageBox.open(); |
139 | return CommandResult.newCancelledCommandResult(); |
140 | } |
141 | |
142 | /** |
143 | * @generated NOT |
144 | */ |
145 | protected CommandResult reorientTarget() throws ExecutionException { |
146 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() |
147 | .getShell(); |
148 | MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); |
149 | messageBox.setText("Notice"); |
150 | messageBox |
151 | .setMessage("Please delete the link and create a new one instead of reorienting it."); |
152 | messageBox.open(); |
153 | return CommandResult.newCancelledCommandResult(); |
154 | } |
155 | |
156 | /** |
157 | * @generated |
158 | */ |
159 | protected AssemblyConnector getLink() { |
160 | return (AssemblyConnector) getElementToEdit(); |
161 | } |
162 | |
163 | /** |
164 | * @generated |
165 | */ |
166 | protected OperationRequiredRole getOldSource() { |
167 | return (OperationRequiredRole) oldEnd; |
168 | } |
169 | |
170 | /** |
171 | * @generated |
172 | */ |
173 | protected OperationRequiredRole getNewSource() { |
174 | return (OperationRequiredRole) newEnd; |
175 | } |
176 | |
177 | /** |
178 | * @generated |
179 | */ |
180 | protected OperationProvidedRole getOldTarget() { |
181 | return (OperationProvidedRole) oldEnd; |
182 | } |
183 | |
184 | /** |
185 | * @generated |
186 | */ |
187 | protected OperationProvidedRole getNewTarget() { |
188 | return (OperationProvidedRole) newEnd; |
189 | } |
190 | } |