protected Command createChangeConstraintCommand(
      ChangeBoundsRequest request, EditPart child, Object constraint) {
    SetConstraintCommand cmd = new SetConstraintCommand();
    LogicSubpart part = (LogicSubpart) child.getModel();
    cmd.setPart(part);
    cmd.setLocation((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;
  }
  protected Command createAddCommand(
      ChangeBoundsRequest request, EditPart child, Object constraint) {
    LogicSubpart part = (LogicSubpart) child.getModel();
    Rectangle rect = (Rectangle) constraint;

    AddCommand add = new AddCommand();
    add.setParent((LogicDiagram) getHost().getModel());
    add.setChild(part);
    add.setLabel(LogicMessages.LogicXYLayoutEditPolicy_AddCommandLabelText);
    add.setDebugLabel("LogicXYEP add subpart"); // $NON-NLS-1$

    SetConstraintCommand setConstraint = new SetConstraintCommand();
    setConstraint.setLocation(rect);
    setConstraint.setPart(part);
    setConstraint.setLabel(LogicMessages.LogicXYLayoutEditPolicy_AddCommandLabelText);
    setConstraint.setDebugLabel("LogicXYEP setConstraint"); // $NON-NLS-1$

    Command cmd = add.chain(setConstraint);
    cmd = chainGuideAttachmentCommand(request, part, cmd, true);
    cmd = chainGuideAttachmentCommand(request, part, cmd, false);
    cmd = chainGuideDetachmentCommand(request, part, cmd, true);
    return chainGuideDetachmentCommand(request, part, cmd, false);
  }