/**
   * Retrieve the list of all source and target connections for the connection.
   *
   * @param set HashSet to add the connections to.
   * @param connectionEditPart the connection edit part.
   */
  private void getSourceAndTargetConnections(
      HashSet set, org.eclipse.gef.ConnectionEditPart connectionEditPart) {

    if (connectionEditPart == null || set == null) return;

    for (Iterator i = connectionEditPart.getSourceConnections().iterator(); i.hasNext(); ) {

      org.eclipse.gef.ConnectionEditPart next = (org.eclipse.gef.ConnectionEditPart) i.next();
      Connection sourceConnection = (Connection) next.getFigure();
      set.add(sourceConnection);
      getSourceAndTargetConnections(set, next);
    }

    for (Iterator i = connectionEditPart.getTargetConnections().iterator(); i.hasNext(); ) {

      org.eclipse.gef.ConnectionEditPart next = (org.eclipse.gef.ConnectionEditPart) i.next();
      Connection targetConnection = (Connection) next.getFigure();
      set.add(targetConnection);
      getSourceAndTargetConnections(set, next);
    }
  }
 private Collection<Shape> getConnectionFigures() {
   EditPart host = getHost();
   Collection<Shape> shapes = new ArrayList<Shape>();
   if (host instanceof CompositeConnectionEditPart) {
     Collection<ConnectionEditPart> editParts =
         ((CompositeConnectionEditPart) host).getEditParts();
     for (ConnectionEditPart editPart : editParts) {
       shapes.add((Shape) editPart.getFigure());
     }
   } else {
     shapes.add((Shape) ((GraphicalEditPart) getHost()).getFigure());
   }
   return shapes;
 }
  /**
   * 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;
  }