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