private Point getPointForEnd(PointList points) {
   Point point = null;
   if (end == End_c.Middle) {
     point = points.getMidpoint();
   } else if (end == End_c.Start) {
     point = points.getFirstPoint();
   } else if (end == End_c.End) {
     point = points.getLastPoint();
   }
   return point;
 }
 @Override
 public boolean test() throws Exception {
   boolean location = false;
   PointList points = ((PolylineConnectionEx) connectionEditPart.getFigure()).getPoints();
   if (checkFirstBendpoint) {
     location = !initialLocation.equals(points.getFirstPoint());
   } else if (checkLastBendpoint) {
     location = !initialLocation.equals(points.getLastPoint());
   } else if (bendpointPosition >= 0 || bendpointPosition < points.size()) {
     location = !initialLocation.equals(points.getPoint(bendpointPosition));
   }
   return location;
 }
 private Point getAbsoluteEdgeExtremity(
     ConnectionNodeEditPart editPart, boolean isStart, Float[] preferPosition) {
   if (editPart == null) {
     return null;
   }
   PointList points = editPart.getConnectionFigure().getPoints().getCopy();
   if (points.size() == 2
       && new Point(0, 0).equals(points.getFirstPoint())
       && new Point(100, 100).equals(points.getLastPoint())) {
     // not display yet.
     if (preferPosition != null) {
       if (isStart && preferPosition[0] != null) {
         return new Point(0, preferPosition[0].intValue());
       } else if (!isStart && preferPosition[1] != null) {
         return new Point(0, preferPosition[1].intValue());
       }
     }
     return SequenceUtil.getAbsoluteEdgeExtremity(editPart, isStart, false);
   }
   return SequenceUtil.getAbsoluteEdgeExtremity(editPart, isStart, true);
 }
示例#4
0
 @Override
 public void execute() {
   // configure the request
   EditPart source = request.getSourceEditPart();
   EditPart target = request.getTargetEditPart();
   PointList list = feedback.getPoints();
   DiagramEditPart diagramEditPart = null;
   if (source.getParent() instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source.getParent();
   } else if (source instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source;
   } else {
     if (source.getParent().getParent() instanceof DiagramEditPart) {
       diagramEditPart = (DiagramEditPart) source.getParent().getParent();
     }
   }
   if (diagramEditPart == null) {
     return;
   }
   if (!(source instanceof DiagramEditPart || target instanceof DiagramEditPart)) {
     // one must be whitespace, we make it the target
     request.setTargetEditPart(diagramEditPart);
     // additionally we must cut the drawn connection
     // in half to share room with the element that will
     // be auto-created
     PointList newList = new PointList();
     newList.addPoint(list.getFirstPoint());
     if (list.size() == 4) {
       // rectilinear routing will have a three points
       newList.addPoint(list.getPoint(1));
     }
     newList.addPoint(list.getMidpoint());
     feedback.setPoints(newList);
   }
   // create the active tool's element first
   CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
   command.execute();
   Connector_c newConnector = command.result;
   if (newConnector == null) {
     return;
   }
   // we need to now refresh the diagram to get the new edit part
   source.refresh();
   source.getParent().refresh();
   GraphicalEditPart newPart =
       (GraphicalEditPart) source.getViewer().getEditPartRegistry().get(newConnector);
   // transfer the feedback connection points to the newly created
   // edit part
   ((Connection) newPart.getFigure()).setPoints(feedback.getPoints().getCopy());
   // now adjust the request for the new element to be created for each
   // terminal specification that requires auto-creation
   createElementForTerminalSpec(
       autoStartSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
   createElementForTerminalSpec(
       autoEndSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
 }
  /**
   * Computes clipping rectangle(s) for a given connection. Will consider all enclosing viewports,
   * excluding the root viewport.
   */
  protected Rectangle[] getEdgeClippingRectangle(Connection connection) {
    // start with clipping the connection at its original bounds
    Rectangle clipRect = getAbsoluteBoundsAsCopy(connection);

    // in case we cannot infer source and target of the connection (e.g.
    // if XYAnchors are used), returning the bounds is all we can do
    ConnectionAnchor sourceAnchor = connection.getSourceAnchor();
    ConnectionAnchor targetAnchor = connection.getTargetAnchor();
    if (sourceAnchor == null
        || sourceAnchor.getOwner() == null
        || targetAnchor == null
        || targetAnchor.getOwner() == null) {
      return new Rectangle[] {clipRect};
    }

    // source and target figure are known, see if there is common
    // viewport
    // the connection has to be clipped at.
    IFigure sourceFigure = sourceAnchor.getOwner();
    IFigure targetFigure = targetAnchor.getOwner();
    Viewport nearestEnclosingCommonViewport =
        ViewportUtilities.getNearestCommonViewport(sourceFigure, targetFigure);
    if (nearestEnclosingCommonViewport == null) {
      return new Rectangle[] {clipRect};
    }

    // if the nearest common viewport is not the root viewport, we may
    // start with clipping the connection at this viewport.
    if (nearestEnclosingCommonViewport != getRootViewport()) {
      clipRect.intersect(getNodeClippingRectangle(nearestEnclosingCommonViewport));
    }

    // if the nearest common viewport of source and target is not
    // simultaneously
    // the nearest enclosing viewport of source and target respectively, the
    // connection has to be further clipped (the connection may even not be
    // visible at all)
    Viewport nearestEnclosingSourceViewport =
        ViewportUtilities.getNearestEnclosingViewport(sourceFigure);
    Viewport nearestEnclosingTargetViewport =
        ViewportUtilities.getNearestEnclosingViewport(targetFigure);
    if (nearestEnclosingSourceViewport != nearestEnclosingTargetViewport) {
      // compute if source and target anchor are visible
      // within the nearest common enclosing viewport (which may
      // itself be nested in other viewports).
      Rectangle sourceClipRect = getAbsoluteBoundsAsCopy(connection);
      if (nearestEnclosingSourceViewport != nearestEnclosingCommonViewport) {
        clipAtViewports(
            sourceClipRect,
            ViewportUtilities.getViewportsPath(
                nearestEnclosingSourceViewport, nearestEnclosingCommonViewport, false));
      }
      Rectangle targetClipRect = getAbsoluteBoundsAsCopy(connection);
      if (nearestEnclosingTargetViewport != nearestEnclosingCommonViewport) {
        clipAtViewports(
            targetClipRect,
            ViewportUtilities.getViewportsPath(
                nearestEnclosingTargetViewport, nearestEnclosingCommonViewport, false));
      }
      PointList absolutePointsAsCopy = getAbsolutePointsAsCopy(connection);
      boolean sourceAnchorVisible =
          sourceClipRect.getExpanded(PRIVATE_INSETS).contains(absolutePointsAsCopy.getFirstPoint());
      boolean targetAnchorVisible =
          targetClipRect.getExpanded(PRIVATE_INSETS).contains(absolutePointsAsCopy.getLastPoint());

      if (!sourceAnchorVisible || !targetAnchorVisible) {
        // one (or both) of source or target anchor is invisible
        // within the nearest common viewport, so up to now
        // we regard the edge as invisible.
        return new Rectangle[] {};
        // TODO: We could come up with a more decent strategy here,
        // which also computes clipping fragments in those cases
        // where source/target are not visible but the edge
        // intersects with the enclosing source/target viewport's
        // parents bounds.

      } else {
        // both ends are visible, so just return what we have
        // computed before
        // (clipping at nearest enclosing viewport)
        return new Rectangle[] {clipRect};
      }
    } else {
      // source and target share the same enclosing viewport, so just
      // return what we have computed before (clipping at nearest
      // enclosing viewport)
      return new Rectangle[] {clipRect};
    }
  }