1 | package de.uka.ipd.sdq.pcm.gmf.usage.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.util.Log; |
8 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
9 | import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand; |
10 | import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; |
11 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
15 | |
16 | import de.uka.ipd.sdq.pcm.gmf.usage.providers.PalladioComponentModelElementTypes; |
17 | import de.uka.ipd.sdq.pcm.usagemodel.Start; |
18 | import de.uka.ipd.sdq.pcm.usagemodel.Stop; |
19 | import de.uka.ipd.sdq.pcm.usagemodel.UsagemodelPackage; |
20 | |
21 | public class ConfigureMinimalSeffCommand extends ConfigureElementCommand { |
22 | |
23 | private ConfigureRequest myRequest = null; |
24 | |
25 | public ConfigureMinimalSeffCommand(ConfigureRequest request) { |
26 | super(request); |
27 | myRequest = request; |
28 | } |
29 | |
30 | @Override |
31 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
32 | IAdaptable info) throws ExecutionException { |
33 | Start start = null; |
34 | Stop stop = null; |
35 | |
36 | CommandResult commandResult = createSEFFAction(PalladioComponentModelElementTypes.Start_3001,monitor); |
37 | if (!isOK(commandResult)) |
38 | { |
39 | return CommandResult.newErrorCommandResult("Create StartAction for the new SEFF failed!"); |
40 | } |
41 | start = (Start) commandResult.getReturnValue(); |
42 | commandResult = createSEFFAction(PalladioComponentModelElementTypes.Stop_3002,monitor); |
43 | if (!isOK(commandResult)) |
44 | { |
45 | return CommandResult.newErrorCommandResult("Create StopAction for the new SEFF failed!"); |
46 | } |
47 | stop = (Stop) commandResult.getReturnValue(); |
48 | // Removed due to recent CanonicalEditPolicy Bug in GMF |
49 | //commandResult = createControlFlow(startAction, stopAction, monitor); |
50 | //if (!isOK(commandResult)) |
51 | //{ |
52 | // return CommandResult.newErrorCommandResult("Create ControlFlow for the new SEFF failed!"); |
53 | //} |
54 | return CommandResult.newOKCommandResult(); |
55 | } |
56 | |
57 | private CommandResult createControlFlow(Start start, |
58 | Stop stop, IProgressMonitor monitor) { |
59 | SetRequest setReq = new SetRequest(start, UsagemodelPackage.eINSTANCE |
60 | .getAbstractUserAction_Successor(), stop); |
61 | SetValueCommand createControlFlowCommand = new SetValueCommand(setReq); |
62 | try { |
63 | createControlFlowCommand.execute(monitor, null); |
64 | } catch (ExecutionException e) { |
65 | Log.error(UsageHelperPlugin.getDefault(), |
66 | -1, e |
67 | .getLocalizedMessage()); |
68 | return CommandResult.newErrorCommandResult(e.getLocalizedMessage()); |
69 | } |
70 | CommandResult commandResult = createControlFlowCommand.getCommandResult(); |
71 | return commandResult; |
72 | } |
73 | |
74 | private CommandResult createSEFFAction(IElementType typeId, |
75 | IProgressMonitor monitor) throws ExecutionException { |
76 | CreateElementRequest startRequest = new CreateElementRequest(myRequest |
77 | .getElementToConfigure(), typeId, UsagemodelPackage.eINSTANCE |
78 | .getScenarioBehaviour_Actions_ScenarioBehaviour()); |
79 | startRequest.setLabel("Create Action"); |
80 | CreateElementCommand createStartCommand = new CreateElementCommand( |
81 | startRequest); |
82 | createStartCommand.execute(monitor, null); |
83 | CommandResult commandResult = createStartCommand.getCommandResult(); |
84 | return commandResult; |
85 | } |
86 | } |