/OntoUML.diagram/src/OntoUML/diagram/edit/commands/MaterialAssociationReorientCommand.java
http://ontouml.googlecode.com/ · Java · 172 lines · 107 code · 17 blank · 48 comment · 21 complexity · 11a6dd989f127fce276620d3a0b68f8d MD5 · raw file
- package OntoUML.diagram.edit.commands;
- import org.eclipse.core.commands.ExecutionException;
- import org.eclipse.core.runtime.IAdaptable;
- import org.eclipse.core.runtime.IProgressMonitor;
- import org.eclipse.emf.ecore.EObject;
- import org.eclipse.gmf.runtime.common.core.command.CommandResult;
- import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
- import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
- /**
- * @generated
- */
- public class MaterialAssociationReorientCommand extends EditElementCommand {
- /**
- * @generated
- */
- private final int reorientDirection;
- /**
- * @generated
- */
- private final EObject oldEnd;
- /**
- * @generated
- */
- private final EObject newEnd;
- /**
- * @generated
- */
- public MaterialAssociationReorientCommand(
- ReorientRelationshipRequest request) {
- super(request.getLabel(), request.getRelationship(), request);
- reorientDirection = request.getDirection();
- oldEnd = request.getOldRelationshipEnd();
- newEnd = request.getNewRelationshipEnd();
- }
- /**
- * @generated
- */
- public boolean canExecute() {
- if (false == getElementToEdit() instanceof OntoUML.MaterialAssociation) {
- return false;
- }
- if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
- return canReorientSource();
- }
- if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
- return canReorientTarget();
- }
- return false;
- }
- /**
- * @generated
- */
- protected boolean canReorientSource() {
- if (!(oldEnd instanceof OntoUML.Type && newEnd instanceof OntoUML.Type)) {
- return false;
- }
- if (getLink().getAssociationEndAux2().size() != 1) {
- return false;
- }
- OntoUML.Type target = (OntoUML.Type) getLink().getAssociationEndAux2()
- .get(0);
- if (!(getLink().eContainer() instanceof OntoUML.Container)) {
- return false;
- }
- OntoUML.Container container = (OntoUML.Container) getLink()
- .eContainer();
- return OntoUML.diagram.edit.policies.OntoUMLBaseItemSemanticEditPolicy.LinkConstraints
- .canExistMaterialAssociation_4007(container, getNewSource(),
- target);
- }
- /**
- * @generated
- */
- protected boolean canReorientTarget() {
- if (!(oldEnd instanceof OntoUML.Type && newEnd instanceof OntoUML.Type)) {
- return false;
- }
- if (getLink().getAssociationEndAux1().size() != 1) {
- return false;
- }
- OntoUML.Type source = (OntoUML.Type) getLink().getAssociationEndAux1()
- .get(0);
- if (!(getLink().eContainer() instanceof OntoUML.Container)) {
- return false;
- }
- OntoUML.Container container = (OntoUML.Container) getLink()
- .eContainer();
- return OntoUML.diagram.edit.policies.OntoUMLBaseItemSemanticEditPolicy.LinkConstraints
- .canExistMaterialAssociation_4007(container, source,
- getNewTarget());
- }
- /**
- * @generated
- */
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
- IAdaptable info) throws ExecutionException {
- if (!canExecute()) {
- throw new ExecutionException(
- "Invalid arguments in reorient link command"); //$NON-NLS-1$
- }
- if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
- return reorientSource();
- }
- if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
- return reorientTarget();
- }
- throw new IllegalStateException();
- }
- /**
- * @generated
- */
- protected CommandResult reorientSource() throws ExecutionException {
- getLink().getAssociationEndAux1().remove(getOldSource());
- getLink().getAssociationEndAux1().add(getNewSource());
- return CommandResult.newOKCommandResult(getLink());
- }
- /**
- * @generated
- */
- protected CommandResult reorientTarget() throws ExecutionException {
- getLink().getAssociationEndAux2().remove(getOldTarget());
- getLink().getAssociationEndAux2().add(getNewTarget());
- return CommandResult.newOKCommandResult(getLink());
- }
- /**
- * @generated
- */
- protected OntoUML.MaterialAssociation getLink() {
- return (OntoUML.MaterialAssociation) getElementToEdit();
- }
- /**
- * @generated
- */
- protected OntoUML.Type getOldSource() {
- return (OntoUML.Type) oldEnd;
- }
- /**
- * @generated
- */
- protected OntoUML.Type getNewSource() {
- return (OntoUML.Type) newEnd;
- }
- /**
- * @generated
- */
- protected OntoUML.Type getOldTarget() {
- return (OntoUML.Type) oldEnd;
- }
- /**
- * @generated
- */
- protected OntoUML.Type getNewTarget() {
- return (OntoUML.Type) newEnd;
- }
- }