| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.usage.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.ReorientReferenceRelationshipRequest; |
| 13 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
| 14 | |
| 15 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
| 16 | import de.uka.ipd.sdq.pcm.usagemodel.AbstractUserAction; |
| 17 | |
| 18 | /** |
| 19 | * @generated |
| 20 | */ |
| 21 | public class AbstractUserActionSuccessorReorientCommand extends |
| 22 | EditElementCommand { |
| 23 | |
| 24 | /** |
| 25 | * @generated |
| 26 | */ |
| 27 | private final int reorientDirection; |
| 28 | |
| 29 | /** |
| 30 | * @generated |
| 31 | */ |
| 32 | private final EObject referenceOwner; |
| 33 | |
| 34 | /** |
| 35 | * @generated |
| 36 | */ |
| 37 | private final EObject oldEnd; |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | private final EObject newEnd; |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | public AbstractUserActionSuccessorReorientCommand( |
| 48 | ReorientReferenceRelationshipRequest request) { |
| 49 | super(request.getLabel(), null, request); |
| 50 | reorientDirection = request.getDirection(); |
| 51 | referenceOwner = request.getReferenceOwner(); |
| 52 | oldEnd = request.getOldRelationshipEnd(); |
| 53 | newEnd = request.getNewRelationshipEnd(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @generated |
| 58 | */ |
| 59 | public boolean canExecute() { |
| 60 | if (false == referenceOwner instanceof AbstractUserAction) { |
| 61 | return false; |
| 62 | } |
| 63 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
| 64 | return canReorientSource(); |
| 65 | } |
| 66 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
| 67 | return canReorientTarget(); |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @generated |
| 74 | */ |
| 75 | protected boolean canReorientSource() { |
| 76 | if (!(oldEnd instanceof AbstractUserAction && newEnd instanceof AbstractUserAction)) { |
| 77 | return false; |
| 78 | } |
| 79 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
| 80 | .canExistAbstractUserActionSuccessor_4002(getNewSource(), |
| 81 | getOldTarget()); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @generated |
| 86 | */ |
| 87 | protected boolean canReorientTarget() { |
| 88 | if (!(oldEnd instanceof AbstractUserAction && newEnd instanceof AbstractUserAction)) { |
| 89 | return false; |
| 90 | } |
| 91 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
| 92 | .canExistAbstractUserActionSuccessor_4002(getOldSource(), |
| 93 | getNewTarget()); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @generated |
| 98 | */ |
| 99 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 100 | IAdaptable info) throws ExecutionException { |
| 101 | if (!canExecute()) { |
| 102 | throw new ExecutionException( |
| 103 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
| 104 | } |
| 105 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
| 106 | return reorientSource(); |
| 107 | } |
| 108 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
| 109 | return reorientTarget(); |
| 110 | } |
| 111 | throw new IllegalStateException(); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @generated |
| 116 | */ |
| 117 | protected CommandResult reorientSource() throws ExecutionException { |
| 118 | getOldSource().setSuccessor(null); |
| 119 | getNewSource().setSuccessor(getOldTarget()); |
| 120 | return CommandResult.newOKCommandResult(referenceOwner); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @generated |
| 125 | */ |
| 126 | protected CommandResult reorientTarget() throws ExecutionException { |
| 127 | getOldSource().setSuccessor(getNewTarget()); |
| 128 | return CommandResult.newOKCommandResult(referenceOwner); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @generated |
| 133 | */ |
| 134 | protected AbstractUserAction getOldSource() { |
| 135 | return (AbstractUserAction) referenceOwner; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @generated |
| 140 | */ |
| 141 | protected AbstractUserAction getNewSource() { |
| 142 | return (AbstractUserAction) newEnd; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @generated |
| 147 | */ |
| 148 | protected AbstractUserAction getOldTarget() { |
| 149 | return (AbstractUserAction) oldEnd; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * @generated |
| 154 | */ |
| 155 | protected AbstractUserAction getNewTarget() { |
| 156 | return (AbstractUserAction) newEnd; |
| 157 | } |
| 158 | } |