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);
  }
 /** Test that GMF Text drop is not possible in a lifeline. */
 public void testGMFTextDropInALifelineNotPossible() {
   ChangeBoundsRequest changeBoundsRequest = new ChangeBoundsRequest(RequestConstants.REQ_ADD);
   changeBoundsRequest.setEditParts(textEditPart);
   Command dropGMFNoteInLifelineCmd = lifelineEditPart.getCommand(changeBoundsRequest);
   assertFalse(
       "The GMF Text should not be droppable in lifeline", dropGMFNoteInLifelineCmd.canExecute());
 }
  /**
   * Override to return the <code>Command</code> to perform an {@link RequestConstants#REQ_CLONE
   * CLONE}. By default, <code>null</code> is returned.
   *
   * @param request the Clone Request
   * @return A command to perform the Clone.
   */
  protected Command getCloneCommand(ChangeBoundsRequest request) {
    CloneCommand clone = new CloneCommand();

    clone.setParent((LogicDiagram) getHost().getModel());

    Iterator i = request.getEditParts().iterator();
    GraphicalEditPart currPart = null;

    while (i.hasNext()) {
      currPart = (GraphicalEditPart) i.next();
      clone.addPart(
          (LogicSubpart) currPart.getModel(), (Rectangle) getConstraintFor(request, currPart));
    }

    // Attach to horizontal guide, if one is given
    Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
    if (guidePos != null) {
      int hAlignment =
          ((Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_ANCHOR)).intValue();
      clone.setGuide(findGuideAt(guidePos.intValue(), true), hAlignment, true);
    }

    // Attach to vertical guide, if one is given
    guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
    if (guidePos != null) {
      int vAlignment =
          ((Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_ANCHOR)).intValue();
      clone.setGuide(findGuideAt(guidePos.intValue(), false), vAlignment, false);
    }

    return clone;
  }
  protected Command createNodeChangeBoundCommands(final List<ShapeEditPart> sortedNodes) {

    final CompoundCommand result = new CompoundCommand();
    final Iterator<ShapeEditPart> iterEditParts = sortedNodes.iterator();
    while (iterEditParts.hasNext()) {
      final ShapeEditPart shapeEditPart = iterEditParts.next();

      final ChangeBoundsRequest request =
          new ChangeBoundsRequest(org.eclipse.gef.RequestConstants.REQ_MOVE);
      request.setEditParts(shapeEditPart);
      final Point ptLocation = new Point(0, 0);
      // the zoom.
      double scale = 1.0;
      if (shapeEditPart.getRoot() instanceof DiagramRootEditPart) {
        final ZoomManager zoomManager =
            ((DiagramRootEditPart) shapeEditPart.getRoot()).getZoomManager();
        scale = zoomManager.getZoom();
      }
      // Compute request data.
      final Point ptOldLocation = shapeEditPart.getFigure().getBounds().getLocation();

      final Dimension delta = ptLocation.getDifference(ptOldLocation);

      request.setMoveDelta(new PrecisionPoint(delta.width * scale, delta.height * scale));
      request.setLocation(new PrecisionPoint(ptLocation.x * scale, ptLocation.y * scale));

      final Command cmd = this.buildCommandWrapper(request, shapeEditPart);
      result.add(cmd);
    }

    return result;
  }
 /** 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;
   }
 }
 @Override
 protected Command getAddCommand(Request req) {
   ChangeBoundsRequest request = (ChangeBoundsRequest) req;
   List editParts = request.getEditParts();
   CompoundCommand command = new CompoundCommand();
   for (int i = 0; i < editParts.size(); i++) {
     EditPart child = (EditPart) editParts.get(i);
     command.add(createAddCommand(child));
   }
   return command.unwrap();
 }
Esempio n. 7
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);
  }
  /** Erases the guide and the feedback shown by the container of the elements. */
  protected void eraseSourceFeedback() {
    if (guideline.getParent() != null) {
      guideline.getParent().remove(guideline);
    }

    if (_container != null) {
      _container.eraseSourceFeedback(getSourceRequest());
    }

    ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
    request.setEditParts(Collections.emptyList());
    request.setSizeDelta(new Dimension(0, 0));
    request.setMoveDelta(new Point(0, 0));
    for (IGraphicalEditPart part : _movingShapes) {
      part.eraseSourceFeedback(request);
    }

    ChangeBoundsRequest spRequest = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
    spRequest.setEditParts(Collections.emptyList());
    spRequest.setSizeDelta(new Dimension(0, 0));
    spRequest.setMoveDelta(new Point(0, 0));
    for (IGraphicalEditPart sp : _subProcesses) {
      sp.eraseSourceFeedback(spRequest);
    }
  }
 private ChangeBoundsRequest initConstrainedRequest(ChangeBoundsRequest request) {
   ChangeBoundsRequest req = new ChangeBoundsRequest();
   req.setConstrainedResize(true);
   req.setConstrainedMove(true);
   req.setType(request.getType());
   req.setResizeDirection(request.getResizeDirection());
   req.getExtendedData().put(REGION_RESIZE_PROPAGATOR, getHost());
   req.getExtendedData()
       .put(
           SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY,
           request.getExtendedData().get(SiriusResizeTracker.CHILDREN_MOVE_MODE_KEY));
   req.getExtendedData().put(REGION_RESIZE_INITIAL_REQUEST, request);
   return req;
 }
  @Override
  protected boolean handleDragStarted() {
    // TODO Auto-generated method stub
    boolean b = super.handleDragStarted();

    CustomRegionResizableEditPolicy policy =
        (CustomRegionResizableEditPolicy) regionEP.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);

    regionEP.setSelected(EditPart.SELECTED_NONE);

    View regionView = (View) regionEP.getModel();
    IAdaptable adaptableForRegion = new SemanticAdapter(null, regionView);

    ChangeBoundsRequest internalResizeRequest = new ChangeBoundsRequest();
    int regionWidth = Zone.getWidth(regionView);
    int regionHeight = Zone.getHeight(regionView);

    RegionFigure regionFigure = regionEP.getPrimaryShape();
    regionFigureBounds = regionFigure.getBounds().getCopy();
    // transform the coordinates to absolute
    regionFigure.translateToAbsolute(regionFigureBounds);

    String zone = Zone.getZone(regionView);
    if (Zone.isRight(zone)) {
      internalResizeRequest.setResizeDirection(PositionConstants.WEST);
      internalResizeRequest.setSizeDelta(new Dimension(-regionWidth, 0));
    } else if (Zone.isLeft(zone)) {
      internalResizeRequest.setResizeDirection(PositionConstants.EAST);
      internalResizeRequest.setSizeDelta(new Dimension(-regionWidth, 0));
    } else if (Zone.isTop(zone)) {
      internalResizeRequest.setResizeDirection(PositionConstants.SOUTH);
      internalResizeRequest.setSizeDelta(new Dimension(0, -regionHeight));
    } else if (Zone.isBottom(zone)) {
      internalResizeRequest.setResizeDirection(PositionConstants.NORTH);
      internalResizeRequest.setSizeDelta(new Dimension(0, -regionHeight));
    }

    internalResizeCommand =
        new CustomRegionResizeCommand(
            adaptableForRegion,
            null,
            regionEP.getEditingDomain(),
            null,
            internalResizeRequest,
            null);

    try {
      internalResizeCommand.execute(null, null);
    } catch (ExecutionException e) {
    }

    return b;
  }
  /** {@inheritDoc} */
  @Override
  protected void updateTargetRequest() {

    super.updateTargetRequest();
    Dimension delta = getDragMoveDelta();

    if (getSourceEditPart() instanceof GraphicalEditPart) {
      Rectangle childRect = ((GraphicalEditPart) getSourceEditPart()).getFigure().getBounds();
      if (getSourceEditPart().getParent() instanceof GraphicalEditPart) {
        Rectangle parentRect =
            ((GraphicalEditPart) getSourceEditPart().getParent()).getFigure().getBounds();
        IFigure fig = ((GraphicalEditPart) getSourceEditPart().getParent()).getFigure();

        IFigure contentPane =
            ((GraphicalEditPart) getSourceEditPart().getParent()).getContentPane();

        // calculate the virtual position
        Rectangle virtualPosition = childRect.getCopy();
        virtualPosition.x = virtualPosition.x + delta.width;
        virtualPosition.y = virtualPosition.y + delta.height;

        if (virtualPosition.x < 0) {
          delta.width = 0 - childRect.x;
        }
        if (virtualPosition.y < 0) {
          delta.height = 0 - childRect.y;
        }

        if (virtualPosition.x + virtualPosition.width + getBorder() > parentRect.width) {
          delta.width = parentRect.width - childRect.width - childRect.x - getBorder();
        }

        if (virtualPosition.y + virtualPosition.height + 2 * getBorder() > parentRect.height) {
          delta.height = parentRect.height - childRect.height - childRect.y - 2 * getBorder();
        }
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        Point moveDelta = new Point(delta.width, delta.height);
        request.setMoveDelta(moveDelta);

        // Very important the child element to block inside the container
        // if not test first the target editPart.
        // let the default algorithm if the target is not its parent.
        setTargetEditPart(getSourceEditPart().getParent());
      }
    }
  }
  /**
   * Complete the given composite command with RegionContainer specific resize commands: the
   * commands to report the RegionContainer resize on its regions.
   */
  @Override
  protected void completeResizeCommand(
      CompositeTransactionalCommand ctc, ChangeBoundsRequest request) {
    if (request.getEditParts().size() > 1 && !request.isConstrainedResize()) {
      ctc.add(UnexecutableCommand.INSTANCE);
      return;
    }

    Collection<ChangeBoundsRequest> siblingRequests = getConstrainedRegionRequests(request);
    if (!siblingRequests.isEmpty()) {
      for (ChangeBoundsRequest siblingRequest : siblingRequests) {
        if (siblingRequest.getEditParts() != null) {
          for (IGraphicalEditPart constrainedPart :
              Iterables.filter(siblingRequest.getEditParts(), IGraphicalEditPart.class)) {
            Command constrainedCommand = constrainedPart.getCommand(siblingRequest);
            if (constrainedCommand == null) {
              ctc.add(UnexecutableCommand.INSTANCE);
            } else {
              ctc.add(new CommandProxy(constrainedCommand));
            }
          }
        }
      }
    } else if (!(request.isConstrainedMove() || request.isConstrainedResize())) {
      // Deactivate the manual resize of RegionContainer when there are no
      // regions.
      ctc.add(UnexecutableCommand.INSTANCE);
    }

    // Adjust border nodes and edges.
    ctc.add(new ChildrenAdjustmentCommand((IGraphicalEditPart) getHost(), request, true, false));
  }
Esempio n. 13
0
  @Override
  protected Command createChangeConstraintCommand(
      ChangeBoundsRequest request, EditPart child, Object constraint) {

    BControlChangeLayoutCommand cmd = new BControlChangeLayoutCommand();
    BControl part = (BControl) child.getModel();
    cmd.setModel(child.getModel());
    cmd.setConstraint((Rectangle) constraint);
    Command result = cmd;

    if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
      Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
      if (guidePos != null) {
        result = chainGuideAttachmentCommand(request, part, result, true);
      } else if (part.getHorizontalGuide() != null) {
        // SnapToGuides didn't provide a horizontal guide, but this part
        // is attached
        // to a horizontal guide. Now we check to see if the part is
        // attached to
        // the guide along the edge being resized. If that is the case,
        // we need to
        // detach the part from the guide; otherwise, we leave it alone.
        int alignment = part.getHorizontalGuide().getAlignment(part);
        int edgeBeingResized = 0;
        if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) edgeBeingResized = -1;
        else edgeBeingResized = 1;
        if (alignment == edgeBeingResized)
          result = result.chain(new ChangeGuideCommand(part, true));
      }
    }

    if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
      Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
      if (guidePos != null) {
        result = chainGuideAttachmentCommand(request, part, result, false);
      } else if (part.getVerticalGuide() != null) {
        int alignment = part.getVerticalGuide().getAlignment(part);
        int edgeBeingResized = 0;
        if ((request.getResizeDirection() & PositionConstants.WEST) != 0) edgeBeingResized = -1;
        else edgeBeingResized = 1;
        if (alignment == edgeBeingResized)
          result = result.chain(new ChangeGuideCommand(part, false));
      }
    }

    if (request.getType().equals(REQ_MOVE_CHILDREN)
        || request.getType().equals(REQ_ALIGN_CHILDREN)) {
      result = chainGuideAttachmentCommand(request, part, result, true);
      result = chainGuideAttachmentCommand(request, part, result, false);
      result = chainGuideDetachmentCommand(request, part, result, true);
      result = chainGuideDetachmentCommand(request, part, result, false);
    }

    return result;
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.gef.commands.Command#canExecute()
  */
 @Override
 public boolean canExecute() {
   final Object type = request.getType();
   // make sure the Request is of a type we support:
   return (RequestConstants.REQ_MOVE.equals(type)
       || RequestConstants.REQ_MOVE_CHILDREN.equals(type)
       || RequestConstants.REQ_RESIZE.equals(type)
       || RequestConstants.REQ_RESIZE_CHILDREN.equals(type));
 }
  /** Shows a nice guideline to show the move */
  protected void showSourceFeedback() {
    if (_container == null) {
      return;
    }
    if (guideline.getParent() == null) {
      addFeedback(guideline);
    }
    Rectangle bounds = Rectangle.SINGLETON.getCopy();
    bounds.y = getCurrentPositionZoomed();

    Rectangle containerBounds = _container.getFigure().getBounds().getCopy();

    _container.getFigure().translateToAbsolute(containerBounds);

    ((DiagramEditPart) getCurrentViewer().getContents())
        .getFigure()
        .translateToRelative(containerBounds);

    bounds.x = containerBounds.x;
    bounds.height = 1;
    bounds.width = containerBounds.width;

    ZoomManager zoomManager =
        ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
    bounds.performScale(zoomManager.getZoom());

    guideline.setBounds(bounds);
    guideline.setVisible(getState() == STATE_DRAG_IN_PROGRESS);

    ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
    request.setMoveDelta(((ChangeBoundsRequest) getSourceRequest()).getMoveDelta());
    request.setSizeDelta(new Dimension(0, 0));
    request.setEditParts(_movingShapes);

    for (IGraphicalEditPart part : _movingShapes) {
      part.showSourceFeedback(request);
    }

    ChangeBoundsRequest spRequest = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
    Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
    Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
    spRequest.setSizeDelta(spSizeDelta);
    spRequest.setMoveDelta(new Point(0, 0));
    spRequest.setEditParts(_subProcesses);

    for (IGraphicalEditPart sp : _subProcesses) {
      sp.showSourceFeedback(spRequest);
    }
    ((DiagramEditPart) getCurrentViewer().getContents()).getRoot().refresh();
  }
Esempio n. 16
0
 /**
  * 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);
 }
 @SuppressWarnings("unchecked")
 @Override
 protected Command getCloneCommand(final ChangeBoundsRequest request) {
   final ArrayList<EObject> copies = new ArrayList<EObject>();
   for (final EditPart editPart : (List<EditPart>) request.getEditParts()) {
     final EObject copy = EcoreUtil.copy((EObject) editPart.getModel());
     setConstraint(copy, (Rectangle) getConstraintForClone((GraphicalEditPart) editPart, request));
     copies.add(copy);
   }
   final String copyString =
       ClipboardUtil.copyElementsToString(copies, null, new NullProgressMonitor());
   final PasteCommand pasteCommand = new PasteCommand((EObject) getHost().getModel(), copyString);
   return pasteCommand;
 }
  /**
   * This method can be overridden by clients to customize the snapping behavior.
   *
   * @param request the <code>ChangeBoundsRequest</code> from which the move delta can be extracted
   *     and updated
   * @since 3.4
   */
  protected void snapPoint(ChangeBoundsRequest request) {
    Point moveDelta = request.getMoveDelta();
    SnapToHelper snapToHelper =
        (SnapToHelper) getConnectionEditPart().getAdapter(SnapToHelper.class);

    Rectangle rect = new Rectangle(originalLocation.x, originalLocation.y, 1, 1);
    if (sourceRectangle == null) {
      sourceRectangle = new PrecisionRectangle(rect);
    }

    if (snapToHelper != null && request.isSnapToEnabled()) {
      PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
      baseRect.translate(moveDelta);

      PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
      snapToHelper.snapPoint(
          request,
          PositionConstants.HORIZONTAL | PositionConstants.VERTICAL,
          new PrecisionRectangle[] {baseRect},
          preciseDelta);
      request.setMoveDelta(preciseDelta);
    }
  }
  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);
  }
  @Override
  protected void updateSourceRequest() {
    ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
    Dimension d = getDragMoveDelta();

    Point location = new Point(getLocation());
    Point moveDelta = new Point(0, 0);
    Dimension resizeDelta = new Dimension(0, 0);

    request.setConstrainedResize(false);

    request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1));

    if ((getResizeDirection() & PositionConstants.NORTH) != 0) {
      moveDelta.y += d.height;
      resizeDelta.height -= d.height;
    }
    if ((getResizeDirection() & PositionConstants.SOUTH) != 0) {
      resizeDelta.height += d.height;
    }
    if ((getResizeDirection() & PositionConstants.WEST) != 0) {
      moveDelta.x += d.width;
      resizeDelta.width -= d.width;
    }
    if ((getResizeDirection() & PositionConstants.EAST) != 0) {
      resizeDelta.width += d.width;
    }

    request.setMoveDelta(moveDelta);
    request.setSizeDelta(resizeDelta);
    request.setLocation(location);
    request.setEditParts(getOperationSet());

    request.getExtendedData().clear();

    // TODO: snapping
  }
  /** @see org.eclipse.gef.tools.SimpleDragTracker#updateSourceRequest() */
  protected void updateSourceRequest() {
    ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();

    if (originalLocation == null) {
      originalLocation = getStartLocation().getCopy();
    }

    Dimension delta = getDragMoveDelta();

    request.setConstrainedMove(getCurrentInput().isModKeyDown(MODIFIER_CONSTRAINED_MOVE));
    request.setSnapToEnabled(!getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING));

    Point moveDelta = new Point(delta.width, delta.height);
    request.getExtendedData().clear();
    request.setMoveDelta(moveDelta);
    snapPoint(request);

    request.setLocation(getLocation());
    request.setType(getCommandName());
  }
 /** Creates the initial request, overridden to use a ChangeBoundsRequest. */
 @Override
 protected Request createSourceRequest() {
   ChangeBoundsRequest request = new ChangeBoundsRequest(getCommandName());
   request.setSizeDelta(new Dimension(0, 0));
   return request;
 }
 // @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;
   }
 }
  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;
  }