| 1 | /* |
| 2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.seff.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.common.core.command.ICommand; |
| 12 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
| 13 | import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; |
| 14 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
| 16 | import org.eclipse.gmf.runtime.notation.View; |
| 17 | |
| 18 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingBehaviour; |
| 19 | |
| 20 | /** |
| 21 | * @generated |
| 22 | */ |
| 23 | public class RecoveryAction2CreateCommand extends EditElementCommand { |
| 24 | |
| 25 | /** |
| 26 | * @generated |
| 27 | */ |
| 28 | public RecoveryAction2CreateCommand(CreateElementRequest req) { |
| 29 | super(req.getLabel(), null, req); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * FIXME: replace with setElementToEdit() |
| 34 | * @generated |
| 35 | */ |
| 36 | protected EObject getElementToEdit() { |
| 37 | EObject container = ((CreateElementRequest) getRequest()) |
| 38 | .getContainer(); |
| 39 | if (container instanceof View) { |
| 40 | container = ((View) container).getElement(); |
| 41 | } |
| 42 | return container; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @generated |
| 47 | */ |
| 48 | public boolean canExecute() { |
| 49 | return true; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @generated |
| 55 | */ |
| 56 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 57 | IAdaptable info) throws ExecutionException { |
| 58 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryAction newElement = de.uka.ipd.sdq.pcm.seff.seff_reliability.Seff_reliabilityFactory.eINSTANCE |
| 59 | .createRecoveryAction(); |
| 60 | |
| 61 | ResourceDemandingBehaviour owner = (ResourceDemandingBehaviour) getElementToEdit(); |
| 62 | owner.getSteps_Behaviour().add(newElement); |
| 63 | |
| 64 | doConfigure(newElement, monitor, info); |
| 65 | |
| 66 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
| 67 | return CommandResult.newOKCommandResult(newElement); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @generated |
| 72 | */ |
| 73 | protected void doConfigure( |
| 74 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryAction newElement, |
| 75 | IProgressMonitor monitor, IAdaptable info) |
| 76 | throws ExecutionException { |
| 77 | IElementType elementType = ((CreateElementRequest) getRequest()) |
| 78 | .getElementType(); |
| 79 | ConfigureRequest configureRequest = new ConfigureRequest( |
| 80 | getEditingDomain(), newElement, elementType); |
| 81 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
| 82 | .getClientContext()); |
| 83 | configureRequest.addParameters(getRequest().getParameters()); |
| 84 | ICommand configureCommand = elementType |
| 85 | .getEditCommand(configureRequest); |
| 86 | if (configureCommand != null && configureCommand.canExecute()) { |
| 87 | configureCommand.execute(monitor, info); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | } |