/** Navigates to the source or target of the currently focused ConnectionEditPart. */
 void navigateOutOfConnection(KeyEvent event) {
   GraphicalEditPart cached = getCachedNode();
   ConnectionEditPart conn = (ConnectionEditPart) getFocusEntityPart();
   if (cached != null && (cached == conn.getSource() || cached == conn.getTarget()))
     navigateTo(cached, event);
   else navigateTo(conn.getSource(), event);
 }
Ejemplo n.º 2
0
  @Override
  public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {

    // handle reconnections
    if (connection != null) {
      if (connection.getSource() != null && connection.getTarget() != null) {
        if (connection.getSource().equals(connection.getTarget())) {
          return new ReconnectionTargetAnchor(getFigure());
        }
      }
    }

    if (((WorkflowNode) getModel())
            .getComponentDescription()
            .getComponentInstallation()
            .getComponentRevision()
            .getComponentInterface()
            .getShape()
        == ComponentShape.CIRCLE) {
      return new EllipseAnchor(getFigure());
    } else {
      return new ChopboxAnchor(getFigure());
    }
  }
  /**
   * Figure out if a cyclic dependency will arise if target connection edit part is connected to the
   * source connection edit part.
   *
   * @param targetCEP the target connection edit part
   * @param sourceCEP the source connection edit part
   * @param checkSourceAndTargetEditParts check both the source and taret edit parts for cyclic
   *     dependencies
   * @param doNotCheckSourceEditPart (if checkSourceAndTargetEditParts is false) check only the
   *     target edit part if true, otherwise check only the source edit part
   * @return true if a cyclic dependency would be create when targetCEP and sourceCEP were to be
   *     connected, false otherwise.
   */
  private boolean isCyclicConnectionRequest(
      org.eclipse.gef.ConnectionEditPart targetCEP,
      org.eclipse.gef.ConnectionEditPart sourceCEP,
      boolean checkSourceAndTargetEditParts,
      boolean doNotCheckSourceEditPart) {

    if (targetCEP == null || sourceCEP == null) return false;

    if (sourceCEP == targetCEP) return true;

    // first, do a cyclic check on source and target connections
    // of the source connection itself.
    // (as every connection is also a node).

    HashSet set = new HashSet();
    getSourceAndTargetConnections(set, sourceCEP);
    if (set.contains(targetCEP.getFigure())) return true;

    // now do the cyclic check on the source and target of the source connection...
    EditPart sourceEP = sourceCEP.getSource(), targetEP = sourceCEP.getTarget();

    if ((sourceEP == targetCEP) || (targetEP == targetCEP)) {
      return true;
    } else {

      if (!checkSourceAndTargetEditParts && doNotCheckSourceEditPart) {
        // .
      } else if (sourceEP instanceof org.eclipse.gef.ConnectionEditPart
          && isCyclicConnectionRequest(
              targetCEP,
              (org.eclipse.gef.ConnectionEditPart) sourceEP,
              true,
              doNotCheckSourceEditPart)) return true;

      if (!checkSourceAndTargetEditParts && !doNotCheckSourceEditPart) {
        // .
      } else if (targetEP instanceof org.eclipse.gef.ConnectionEditPart
          && isCyclicConnectionRequest(
              targetCEP,
              (org.eclipse.gef.ConnectionEditPart) targetEP,
              true,
              doNotCheckSourceEditPart)) return true;
    }

    return false;
  }
  /** This method navigates through connections based on the keys pressed. */
  void navigateConnections(KeyEvent event) {
    GraphicalEditPart focus = (GraphicalEditPart) getFocusEntityPart();
    ConnectionEditPart current = null;
    GraphicalEditPart node = getCachedNode();
    if (focus instanceof ConnectionEditPart) {
      current = (ConnectionEditPart) focus;
      if (node == null || (node != current.getSource() && node != current.getTarget())) {
        node = (GraphicalEditPart) current.getSource();
        counter = 0;
      }
    } else {
      node = focus;
    }

    setCachedNode(node);
    boolean forward = event.character == '/' || event.character == '?';
    ConnectionEditPart next = findConnection(node, current, forward);
    navigateTo(next, event);
  }
Ejemplo n.º 5
0
  /** Gets the remote figure. */
  private void updateRemoteFig() {
    // CreateConnectionRequest needs to refresh fRemoteFig each time
    switch (fAnchorType) {
      case CRCONREQ_SRC:
        fRemoteFig =
            (((CreateConnectionRequest) fRequest).getTargetEditPart() != null)
                ? ((GraphicalEditPart) ((CreateConnectionRequest) fRequest).getTargetEditPart())
                    .getFigure()
                : null;
        break;
      case CRCONREQ_TGT:
        fRemoteFig =
            (((CreateConnectionRequest) fRequest).getSourceEditPart() != null)
                ? ((GraphicalEditPart) ((CreateConnectionRequest) fRequest).getSourceEditPart())
                    .getFigure()
                : null;
        break;
    }

    // The other cases can be cached
    if (fRemoteFig != null) {
      return;
    }

    switch (fAnchorType) {
      case CONNECTION_SRC:
        fRemoteFig = ((GraphicalEditPart) fAnchorConnection.getTarget()).getFigure();
        break;
      case CONNECTION_TGT:
        fRemoteFig = ((GraphicalEditPart) fAnchorConnection.getSource()).getFigure();
        break;
      case RECONREQ_SRC:
        fRemoteFig =
            (((ReconnectRequest) fRequest).getConnectionEditPart().getTarget() != null)
                ? ((GraphicalEditPart)
                        ((ReconnectRequest) fRequest).getConnectionEditPart().getTarget())
                    .getFigure()
                : null;
        if (((Connection) ((ReconnectRequest) fRequest).getConnectionEditPart().getFigure())
                .getTargetAnchor()
            instanceof OrthogonalAnchor)
          ((OrthogonalAnchor)
                  ((Connection) ((ReconnectRequest) fRequest).getConnectionEditPart().getFigure())
                      .getTargetAnchor())
              .setAlternateRemoteFig(getOwner());
        break;
      case RECONREQ_TGT:
        fRemoteFig =
            (((ReconnectRequest) fRequest).getConnectionEditPart().getSource() != null)
                ? ((GraphicalEditPart)
                        ((ReconnectRequest) fRequest).getConnectionEditPart().getSource())
                    .getFigure()
                : null;
        if (((Connection) ((ReconnectRequest) fRequest).getConnectionEditPart().getFigure())
                .getSourceAnchor()
            instanceof OrthogonalAnchor)
          ((OrthogonalAnchor)
                  ((Connection) ((ReconnectRequest) fRequest).getConnectionEditPart().getFigure())
                      .getSourceAnchor())
              .setAlternateRemoteFig(getOwner());
        break;
    }
  }