| 1 | package de.uka.ipd.sdq.pcm.gmf.seff.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.seff.providers.PalladioComponentModelElementTypes; |
| 17 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
| 18 | import de.uka.ipd.sdq.pcm.seff.StartAction; |
| 19 | import de.uka.ipd.sdq.pcm.seff.StopAction; |
| 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 | StartAction startAction = null; |
| 34 | StopAction stopAction = null; |
| 35 | |
| 36 | CommandResult commandResult = createSEFFAction(PalladioComponentModelElementTypes.StartAction_2001,monitor); |
| 37 | if (!isOK(commandResult)) |
| 38 | { |
| 39 | return CommandResult.newErrorCommandResult("Create StartAction for the new SEFF failed!"); |
| 40 | } |
| 41 | startAction = (StartAction) commandResult.getReturnValue(); |
| 42 | commandResult = createSEFFAction(PalladioComponentModelElementTypes.StopAction_2002,monitor); |
| 43 | if (!isOK(commandResult)) |
| 44 | { |
| 45 | return CommandResult.newErrorCommandResult("Create StopAction for the new SEFF failed!"); |
| 46 | } |
| 47 | stopAction = (StopAction) 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(StartAction startAction, |
| 58 | StopAction stopAction, IProgressMonitor monitor) { |
| 59 | SetRequest setReq = new SetRequest(startAction, SeffPackage.eINSTANCE |
| 60 | .getAbstractAction_Successor_AbstractAction(), stopAction); |
| 61 | SetValueCommand createControlFlowCommand = new SetValueCommand(setReq); |
| 62 | try { |
| 63 | createControlFlowCommand.execute(monitor, null); |
| 64 | } catch (ExecutionException e) { |
| 65 | Log.error(SEFFHelperPlugin.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, IProgressMonitor monitor) |
| 75 | throws ExecutionException { |
| 76 | CreateElementRequest startRequest = new CreateElementRequest( |
| 77 | myRequest.getElementToConfigure(), |
| 78 | typeId, |
| 79 | SeffPackage.eINSTANCE.getResourceDemandingBehaviour_Steps_Behaviour() |
| 80 | ); |
| 81 | startRequest.setLabel("Create Action"); |
| 82 | CreateElementCommand createStartCommand = new CreateElementCommand(startRequest); |
| 83 | createStartCommand.execute(monitor, null); |
| 84 | CommandResult commandResult = createStartCommand.getCommandResult(); |
| 85 | return commandResult; |
| 86 | } |
| 87 | } |