| 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.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.core.entity.InterfaceRequiringEntity; |
| 19 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
| 20 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
| 21 | |
| 22 | /** |
| 23 | * The Operation Required Role create command for system operation required roles. |
| 24 | * |
| 25 | * @generated |
| 26 | */ |
| 27 | public class OperationRequiredRole2CreateCommand extends EditElementCommand { |
| 28 | |
| 29 | /** |
| 30 | * @generated |
| 31 | */ |
| 32 | public OperationRequiredRole2CreateCommand(CreateElementRequest req) { |
| 33 | super(req.getLabel(), null, req); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * FIXME: replace with setElementToEdit() |
| 38 | * @generated |
| 39 | */ |
| 40 | protected EObject getElementToEdit() { |
| 41 | EObject container = ((CreateElementRequest) getRequest()) |
| 42 | .getContainer(); |
| 43 | if (container instanceof View) { |
| 44 | container = ((View) container).getElement(); |
| 45 | } |
| 46 | return container; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @generated |
| 51 | */ |
| 52 | public boolean canExecute() { |
| 53 | return true; |
| 54 | |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @generated |
| 59 | */ |
| 60 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 61 | IAdaptable info) throws ExecutionException { |
| 62 | OperationRequiredRole newElement = RepositoryFactory.eINSTANCE |
| 63 | .createOperationRequiredRole(); |
| 64 | |
| 65 | InterfaceRequiringEntity owner = (InterfaceRequiringEntity) getElementToEdit(); |
| 66 | owner.getRequiredRoles_InterfaceRequiringEntity().add(newElement); |
| 67 | |
| 68 | doConfigure(newElement, monitor, info); |
| 69 | |
| 70 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
| 71 | return CommandResult.newOKCommandResult(newElement); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @generated |
| 76 | */ |
| 77 | protected void doConfigure(OperationRequiredRole newElement, |
| 78 | IProgressMonitor monitor, IAdaptable info) |
| 79 | throws ExecutionException { |
| 80 | IElementType elementType = ((CreateElementRequest) getRequest()) |
| 81 | .getElementType(); |
| 82 | ConfigureRequest configureRequest = new ConfigureRequest( |
| 83 | getEditingDomain(), newElement, elementType); |
| 84 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
| 85 | .getClientContext()); |
| 86 | configureRequest.addParameters(getRequest().getParameters()); |
| 87 | ICommand configureCommand = elementType |
| 88 | .getEditCommand(configureRequest); |
| 89 | if (configureCommand != null && configureCommand.canExecute()) { |
| 90 | configureCommand.execute(monitor, info); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | } |