/** Handle resize InteractionOperand {@inheritDoc} */
 @Override
 protected Command getResizeCommand(ChangeBoundsRequest request) {
   if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
     EditPart parent = getHost().getParent().getParent();
     return parent.getCommand(request);
   } else {
     if (this.getHost() instanceof InteractionOperandEditPart
         && this.getHost().getParent()
             instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) {
       InteractionOperandEditPart currentIOEP = (InteractionOperandEditPart) this.getHost();
       CombinedFragmentCombinedFragmentCompartmentEditPart compartEP =
           (CombinedFragmentCombinedFragmentCompartmentEditPart) this.getHost().getParent();
       // if first interaction operand and resize direction is NORTH
       if (this.getHost() == OperandBoundsComputeHelper.findFirstIOEP(compartEP)
           && (request.getResizeDirection() & PositionConstants.NORTH) != 0) {
         return getHost().getParent().getParent().getCommand(request);
       } else {
         int heightDelta = request.getSizeDelta().height();
         if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
           return OperandBoundsComputeHelper.createIOEPResizeCommand(
               currentIOEP, heightDelta, compartEP, PositionConstants.NORTH);
         } else if ((request.getResizeDirection() & PositionConstants.SOUTH) != 0) {
           return OperandBoundsComputeHelper.createIOEPResizeCommand(
               currentIOEP, heightDelta, compartEP, PositionConstants.SOUTH);
         }
       }
     }
     return null;
   }
 }
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);
    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
示例#3
0
  /**
   * Fix for #422827
   *
   * <p>We would better override the Dimension.max() logic from the super class but it itself calls
   * super.super so we can't easily do that.
   *
   * <p>So we have to explicitly call {@link #getMinimumSizeForHint(GraphicalEditPart, Dimension)}
   * and ensure that Dimension.max() logic in super-class does not affect results by returning
   * something small from {@link #getMinimumSizeFor(GraphicalEditPart)}
   */
  @Override
  protected Object getConstraintFor(Request request, GraphicalEditPart child, Rectangle rect) {
    if (isReflowable(child) && request instanceof ChangeBoundsRequest) {
      ChangeBoundsRequest reqImpl = (ChangeBoundsRequest) request;

      Dimension sizeDelta = reqImpl.getSizeDelta();
      if (sizeDelta.width != 0 || sizeDelta.height != 0) {
        Dimension correctedMinSize = getMinimumSizeForHint(child, rect.getSize());
        rect.setSize(Dimension.max(correctedMinSize, rect.getSize()));
      }
    }
    return super.getConstraintFor(request, child, rect);
  }
 // @unused
 public static Request getNewSourceFeedbackRequest(Request request, ShapeNodeEditPart editPart) {
   if (request instanceof ChangeBoundsRequest) {
     ChangeBoundsRequest currRequest = (ChangeBoundsRequest) request;
     Dimension oldDelta = currRequest.getSizeDelta();
     Dimension newDelta =
         getSizeDeltaToFitAnchors(editPart, oldDelta, PreserveAnchorsPositionCommand.PRESERVE_Y);
     // Information for creating a new ChangeBoundsRequest has been taken
     // from org.eclipse.gef.editpolicies.ResizableEditPolicy
     ChangeBoundsRequest newRequest = new ChangeBoundsRequest();
     newRequest.setMoveDelta(currRequest.getMoveDelta());
     newRequest.setSizeDelta(newDelta);
     newRequest.setLocation(currRequest.getLocation());
     newRequest.setExtendedData(currRequest.getExtendedData());
     newRequest.setResizeDirection(currRequest.getResizeDirection());
     newRequest.setType(currRequest.getType());
     return newRequest;
   } else {
     return request;
   }
 }
 /**
  * Shows or updates feedback for a change bounds request. The request is updated by the way so
  * that the shape stays a square.
  *
  * @param request the request
  */
 @Override
 protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
   // adapt the request for a square resize
   Point move = request.getMoveDelta();
   Dimension delta = request.getSizeDelta();
   int dH = delta.height;
   int dW = delta.width;
   int signum = 0;
   if (dH <= 0 && dW <= 0) {
     signum = -1;
   } else {
     signum = 1;
   }
   int positiveResize = Math.max(dH, dW);
   if (positiveResize <= 0) {
     if (dH == 0) {
       positiveResize = -dW;
     } else if (dW == 0) {
       positiveResize = -dH;
     } else {
       positiveResize = Math.min(-dH, -dW);
     }
   }
   int newDH = signum * positiveResize;
   int newDW = newDH;
   int dir = request.getResizeDirection();
   // adjust new position if impacted by resizing
   if ((dir & PositionConstants.NORTH) > 0) {
     move.y += dH - newDH;
   }
   if ((dir & PositionConstants.WEST) > 0) {
     move.x += dW - newDW;
   }
   request.setMoveDelta(move);
   delta.height = newDH;
   delta.width = newDW;
   super.showChangeBoundsFeedback(request);
 }
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);

    // Only enable horizontal dragging on lifelines(except lifelines that are result of a create
    // message).
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364688
    if (this.getHost() instanceof LifelineEditPart) {
      LifelineEditPart lifelineEP = (LifelineEditPart) this.getHost();
      if (!SequenceUtil.isCreateMessageEndLifeline(lifelineEP)) {
        request.getMoveDelta().y = 0;
      }
    }

    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
  private Collection<ChangeBoundsRequest> getConstrainedRegionRequests(
      ChangeBoundsRequest request) {
    Collection<ChangeBoundsRequest> constrainedRequests = Lists.newArrayList();

    RequestQuery query = new RequestQuery(request);
    Dimension sizeDelta = request.getSizeDelta().getCopy();
    Point moveDelta = request.getMoveDelta().getCopy();

    List<AbstractDiagramElementContainerEditPart> regionToResize = getRegionParts();
    int stackDirection = getStackDirection();
    // Handle first and last regions.
    Object resizePropagator = request.getExtendedData().get(REGION_RESIZE_PROPAGATOR);
    if (query.isResizeFromTop() && stackDirection == PositionConstants.NORTH_SOUTH
        || query.isResizeFromLeft() && stackDirection == PositionConstants.EAST_WEST) {
      Option<AbstractDiagramElementContainerEditPart> firstRegionPart = getFirstRegionPart();
      if (firstRegionPart.some()
          && (!request.isConstrainedResize() || resizePropagator != firstRegionPart.get())) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(firstRegionPart.get());
        req.setSizeDelta(sizeDelta.getCopy());
        constrainedRequests.add(req);
      }
      // shift all other regions.
      regionToResize.remove(firstRegionPart.get());
      if (!regionToResize.isEmpty()
          && (!request.isConstrainedResize() || !regionToResize.contains(resizePropagator))) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(Lists.newArrayList(regionToResize));

        if (stackDirection == PositionConstants.NORTH_SOUTH) {
          req.setSizeDelta(new Dimension(sizeDelta.width, 0));
          req.setMoveDelta(new Point(0, -moveDelta.y));
        } else if (stackDirection == PositionConstants.EAST_WEST) {
          req.setSizeDelta(new Dimension(0, sizeDelta.height));
          req.setMoveDelta(new Point(-moveDelta.x, 0));
        }
        constrainedRequests.add(req);
        regionToResize.clear();
      }
    } else if (query.isResizeFromBottom() && stackDirection == PositionConstants.NORTH_SOUTH
        || query.isResizeFromRight() && stackDirection == PositionConstants.EAST_WEST) {
      // Resize the last region.
      Option<AbstractDiagramElementContainerEditPart> lastRegionPart = getLastRegionPart();
      if (lastRegionPart.some()
          && (!request.isConstrainedResize() || resizePropagator != lastRegionPart.get())) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(lastRegionPart.get());
        req.setSizeDelta(sizeDelta.getCopy());
        constrainedRequests.add(req);
        regionToResize.remove(lastRegionPart.get());
      }
    }

    // Handle horizontal resize for vstacks and vertical resize for hstacks.
    if (request.isConstrainedResize() && resizePropagator != null) {
      regionToResize.remove(resizePropagator);
    }
    if (!regionToResize.isEmpty()) {
      if (stackDirection == PositionConstants.NORTH_SOUTH
          && (query.isResizeFromLeft() || query.isResizeFromRight())
          && sizeDelta.width != 0) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(Lists.newArrayList(regionToResize));
        req.setSizeDelta(new Dimension(sizeDelta.width, 0));
        constrainedRequests.add(req);
      } else if (stackDirection == PositionConstants.EAST_WEST
          && (query.isResizeFromTop() || query.isResizeFromBottom())
          && sizeDelta.height != 0) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(Lists.newArrayList(regionToResize));
        req.setSizeDelta(new Dimension(0, sizeDelta.height));
        constrainedRequests.add(req);
      }
    }

    return constrainedRequests;
  }