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