Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
 /*
  * (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));
 }
 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;
 }
 // @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;
   }
 }