1 | package de.uka.ipd.sdq.pcm.gmf.repository.helper; |
2 | |
3 | import org.eclipse.core.commands.ExecutionException; |
4 | import org.eclipse.core.runtime.IAdaptable; |
5 | import org.eclipse.core.runtime.IProgressMonitor; |
6 | import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
7 | import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
8 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
9 | import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; |
10 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
11 | import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
15 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
18 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
19 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
20 | |
21 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
22 | import de.uka.ipd.sdq.pcm.repository.EventGroup; |
23 | import de.uka.ipd.sdq.pcm.repository.EventType; |
24 | import de.uka.ipd.sdq.pcm.repository.InfrastructureInterface; |
25 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
26 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
27 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
28 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
29 | import de.uka.ipd.sdq.pcm.repository.Signature; |
30 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
31 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
32 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
33 | import de.uka.ipd.sdq.pcm.seff.StartAction; |
34 | import de.uka.ipd.sdq.pcm.seff.StopAction; |
35 | |
36 | /** |
37 | * Command class to create the new SEFF. |
38 | * |
39 | * @author Benjamin Klatt (only documentation) |
40 | * |
41 | */ |
42 | class CreateLinkedSeffCommand extends ConfigureElementCommand { |
43 | |
44 | private Signature service; |
45 | private ConfigureRequest myRequest; |
46 | |
47 | /** |
48 | * Constructor to initialize the element creation command |
49 | * @param request The request about the element configuration |
50 | * @param service The signature to be created |
51 | */ |
52 | public CreateLinkedSeffCommand(ConfigureRequest request, |
53 | Signature service) { |
54 | super(request); |
55 | this.service = service; |
56 | myRequest = request; |
57 | } |
58 | |
59 | /** |
60 | * Execute the command and create the seff including |
61 | * the minimum setup with a StartAction and a StopAction |
62 | * @param monitor The monitor to report the progress to |
63 | * @param info Adaptable object for the environment |
64 | */ |
65 | @Override |
66 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
67 | IAdaptable info) throws ExecutionException { |
68 | |
69 | CommandResult commandResult = createSEFF( |
70 | ElementTypeRegistry.getInstance().getType("de.uka.ipd.sdq.pcm.gmf.repository.helper.InitialisedResourceDemandingSEFF_4201"),monitor); |
71 | if (!isOK(commandResult)) |
72 | { |
73 | return CommandResult.newErrorCommandResult("Create StartAction for the new SEFF failed!"); |
74 | } |
75 | ResourceDemandingSEFF seff = (ResourceDemandingSEFF) commandResult.getReturnValue(); |
76 | SetRequest setter = new SetRequest(seff, |
77 | SeffPackage.eINSTANCE.getServiceEffectSpecification_DescribedService__SEFF(), |
78 | service); |
79 | SetValueCommand setCommand = new SetValueCommand(setter); |
80 | setCommand.execute(monitor, info); |
81 | CommandResult result = setCommand.getCommandResult(); |
82 | if (!isOK(result)) |
83 | { |
84 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
85 | } |
86 | StartAction start = SeffFactory.eINSTANCE.createStartAction(); |
87 | SetRequest setter2 = new SetRequest(seff, |
88 | SeffPackage.eINSTANCE.getResourceDemandingBehaviour_Steps_Behaviour(), |
89 | start); |
90 | SetValueCommand setCommand2 = new SetValueCommand(setter2); |
91 | setCommand2.execute(monitor, info); |
92 | result = setCommand2.getCommandResult(); |
93 | if (!isOK(result)) |
94 | { |
95 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
96 | } |
97 | StopAction stop = SeffFactory.eINSTANCE.createStopAction(); |
98 | SetRequest setter3 = new SetRequest(seff, |
99 | SeffPackage.eINSTANCE.getResourceDemandingBehaviour_Steps_Behaviour(), |
100 | stop); |
101 | SetValueCommand setCommand3 = new SetValueCommand(setter3); |
102 | setCommand3.execute(monitor, info); |
103 | result = setCommand3.getCommandResult(); |
104 | if (!isOK(result)) |
105 | { |
106 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
107 | } |
108 | SetRequest setter4 = new SetRequest(start, |
109 | SeffPackage.eINSTANCE.getAbstractAction_Successor_AbstractAction(), |
110 | stop); |
111 | SetValueCommand setCommand4 = new SetValueCommand(setter4); |
112 | setCommand4.execute(monitor, info); |
113 | result = setCommand4.getCommandResult(); |
114 | if (!isOK(result)) |
115 | { |
116 | return CommandResult.newErrorCommandResult("Create SEFF failed!"); |
117 | } |
118 | return CommandResult.newOKCommandResult(); |
119 | } |
120 | |
121 | /** |
122 | * Create the SEFF object and return the result information |
123 | * about the creation process. |
124 | * |
125 | * @param typeId The class to created an instance of. |
126 | * @param monitor The monitor to report the progress. |
127 | * @return The Seff creation result information. |
128 | * @throws ExecutionException |
129 | */ |
130 | private CommandResult createSEFF( |
131 | IElementType typeId, |
132 | IProgressMonitor monitor) throws ExecutionException { |
133 | CreateElementRequest seffRequest = new CreateElementRequest( |
134 | myRequest.getElementToConfigure(), |
135 | typeId, |
136 | RepositoryPackage.eINSTANCE.getBasicComponent_ServiceEffectSpecifications__BasicComponent() |
137 | ); |
138 | seffRequest.setLabel("Create SEFF"); |
139 | CreateElementCommand createStartCommand = new CreateElementCommand(seffRequest); |
140 | createStartCommand.execute(monitor, null); |
141 | CommandResult commandResult = createStartCommand.getCommandResult(); |
142 | return commandResult; |
143 | } |
144 | |
145 | } |
146 | |
147 | |
148 | public class InterfaceEditHelperAdvice extends AbstractEditHelperAdvice |
149 | implements IEditHelperAdvice { |
150 | |
151 | /** |
152 | * If a new ProvidedRole relation ship is created, |
153 | * create the according SEFFs in the basic component. |
154 | * This applies for OperationProvidedRoles as well as for event SinkRoles. |
155 | * |
156 | * @param request The request to create the relationship |
157 | * @return The command for any further processing |
158 | */ |
159 | @Override |
160 | protected ICommand getAfterCreateRelationshipCommand( |
161 | CreateRelationshipRequest request) { |
162 | |
163 | // create seff for operation interface |
164 | if (request.getTarget() != null |
165 | && request.getTarget() instanceof OperationInterface) { |
166 | if (request.getElementType().getEClass() == RepositoryPackage.eINSTANCE |
167 | .getOperationProvidedRole()) { |
168 | OperationInterface target = (OperationInterface) request |
169 | .getTarget(); |
170 | if (target.getSignatures__OperationInterface().size() > 0) { |
171 | if (request.getSource() instanceof BasicComponent) { |
172 | BasicComponent source = (BasicComponent) request |
173 | .getSource(); |
174 | CompositeCommand createSEFFs = new CompositeCommand( |
175 | "Create SEFFs"); |
176 | for (OperationSignature s : target |
177 | .getSignatures__OperationInterface()) { |
178 | ConfigureRequest ceRequest = new ConfigureRequest( |
179 | source, |
180 | ElementTypeRegistry |
181 | .getInstance() |
182 | .getType( |
183 | "de.uka.ipd.sdq.pcm.gmf.seff.ResourceDemandingSEFF_1000")); |
184 | CreateLinkedSeffCommand cmd = new CreateLinkedSeffCommand( |
185 | ceRequest, s); |
186 | createSEFFs.add(cmd); |
187 | } |
188 | return createSEFFs; |
189 | } |
190 | } |
191 | } |
192 | } |
193 | |
194 | // create seff for event group |
195 | else if (request.getTarget() != null |
196 | && request.getTarget() instanceof EventGroup) { |
197 | if (request.getElementType().getEClass() == RepositoryPackage.eINSTANCE.getSinkRole()) { |
198 | EventGroup target = (EventGroup) request.getTarget(); |
199 | if (target.getEventTypes__EventGroup().size() > 0){ |
200 | BasicComponent source = (BasicComponent) request.getSource(); |
201 | CompositeCommand createSEFFs = new CompositeCommand( |
202 | "Create SEFFs"); |
203 | for (EventType t : target.getEventTypes__EventGroup()) { |
204 | ConfigureRequest ceRequest = new ConfigureRequest( |
205 | source, |
206 | ElementTypeRegistry |
207 | .getInstance() |
208 | .getType( |
209 | "de.uka.ipd.sdq.pcm.gmf.seff.ResourceDemandingSEFF_1000")); |
210 | CreateLinkedSeffCommand cmd = new CreateLinkedSeffCommand( |
211 | ceRequest, t); |
212 | createSEFFs.add(cmd); |
213 | } |
214 | return createSEFFs; |
215 | } |
216 | } |
217 | } |
218 | |
219 | // create SEFF for infrastructure interface |
220 | else if (request.getTarget() != null |
221 | && request.getTarget() instanceof InfrastructureInterface) { |
222 | if (request.getElementType().getEClass() == RepositoryPackage.eINSTANCE |
223 | .getInfrastructureProvidedRole()) { |
224 | InfrastructureInterface target = (InfrastructureInterface) request |
225 | .getTarget(); |
226 | if (target.getInfrastructureSignatures__InfrastructureInterface().size() > 0) { |
227 | if (request.getSource() instanceof BasicComponent) { |
228 | BasicComponent source = (BasicComponent) request |
229 | .getSource(); |
230 | CompositeCommand createSEFFs = new CompositeCommand( |
231 | "Create SEFFs"); |
232 | for (InfrastructureSignature s : target |
233 | .getInfrastructureSignatures__InfrastructureInterface()) { |
234 | ConfigureRequest ceRequest = new ConfigureRequest( |
235 | source, |
236 | ElementTypeRegistry |
237 | .getInstance() |
238 | .getType( |
239 | "de.uka.ipd.sdq.pcm.gmf.seff.ResourceDemandingSEFF_1000")); |
240 | CreateLinkedSeffCommand cmd = new CreateLinkedSeffCommand( |
241 | ceRequest, s); |
242 | createSEFFs.add(cmd); |
243 | } |
244 | return createSEFFs; |
245 | } |
246 | } |
247 | } |
248 | } |
249 | return super.getAfterCreateRelationshipCommand(request); |
250 | } |
251 | |
252 | } |