| 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.emf.type.core.commands.EditElementCommand; |
| 12 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
| 13 | |
| 14 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
| 15 | import de.uka.ipd.sdq.pcm.seff.AbstractAction; |
| 16 | |
| 17 | /** |
| 18 | * @generated |
| 19 | */ |
| 20 | public class AbstractActionSuccessor_AbstractActionCreateCommand extends |
| 21 | EditElementCommand { |
| 22 | |
| 23 | /** |
| 24 | * @generated |
| 25 | */ |
| 26 | private final EObject source; |
| 27 | |
| 28 | /** |
| 29 | * @generated |
| 30 | */ |
| 31 | private final EObject target; |
| 32 | |
| 33 | /** |
| 34 | * @generated |
| 35 | */ |
| 36 | public AbstractActionSuccessor_AbstractActionCreateCommand( |
| 37 | CreateRelationshipRequest request, EObject source, EObject target) { |
| 38 | super(request.getLabel(), null, request); |
| 39 | this.source = source; |
| 40 | this.target = target; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @generated |
| 45 | */ |
| 46 | public boolean canExecute() { |
| 47 | if (source == null && target == null) { |
| 48 | return false; |
| 49 | } |
| 50 | if (source != null && false == source instanceof AbstractAction) { |
| 51 | return false; |
| 52 | } |
| 53 | if (target != null && false == target instanceof AbstractAction) { |
| 54 | return false; |
| 55 | } |
| 56 | if (getSource() == null) { |
| 57 | return true; // link creation is in progress; source is not defined yet |
| 58 | } |
| 59 | // target may be null here but it's possible to check constraint |
| 60 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
| 61 | .canCreateAbstractActionSuccessor_AbstractAction_4001( |
| 62 | getSource(), getTarget()); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @generated |
| 67 | */ |
| 68 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 69 | IAdaptable info) throws ExecutionException { |
| 70 | if (!canExecute()) { |
| 71 | throw new ExecutionException( |
| 72 | "Invalid arguments in create link command"); //$NON-NLS-1$ |
| 73 | } |
| 74 | |
| 75 | if (getSource() != null && getTarget() != null) { |
| 76 | getSource().setSuccessor_AbstractAction(getTarget()); |
| 77 | } |
| 78 | return CommandResult.newOKCommandResult(); |
| 79 | |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @generated |
| 84 | */ |
| 85 | protected void setElementToEdit(EObject element) { |
| 86 | throw new UnsupportedOperationException(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @generated |
| 91 | */ |
| 92 | protected AbstractAction getSource() { |
| 93 | return (AbstractAction) source; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @generated |
| 98 | */ |
| 99 | protected AbstractAction getTarget() { |
| 100 | return (AbstractAction) target; |
| 101 | } |
| 102 | } |