Package OntoUML.diagram.edit.commands

Source Code of OntoUML.diagram.edit.commands.FormalAssociationReorientCommand

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 FormalAssociationReorientCommand extends EditElementCommand {

  /**
   * @generated
   */
  private final int reorientDirection;

  /**
   * @generated
   */
  private final EObject oldEnd;

  /**
   * @generated
   */
  private final EObject newEnd;

  /**
   * @generated
   */
  public FormalAssociationReorientCommand(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.FormalAssociation) {
      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
        .canExistFormalAssociation_4005(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
        .canExistFormalAssociation_4005(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.FormalAssociation getLink() {
    return (OntoUML.FormalAssociation) 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;
  }
}
TOP

Related Classes of OntoUML.diagram.edit.commands.FormalAssociationReorientCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.