@Override
  protected EditPolicy createChildEditPolicy(EditPart child) {

    BControl control = (BControl) child.getModel();

    ResizableEditPolicy policy = new ResizableEditPolicy();

    BAttributeWidth atrWidth =
        (BAttributeWidth) control.getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH);
    BAttributeHeight atrHeight =
        (BAttributeHeight) control.getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT);

    if (atrWidth.isEditable() && atrHeight.isEditable()) return policy;

    if (atrWidth.isEditable()) {
      policy.setResizeDirections(PositionConstants.EAST_WEST);
      return policy;
    }

    if (atrHeight.isEditable()) {
      policy.setResizeDirections(PositionConstants.NORTH_SOUTH);
      return policy;
    }

    policy.setResizeDirections(0);

    return policy;
  }
Exemple #2
0
  @Override
  protected void initAttributes() {

    BAttributeCoordinates aCoordinates = new BAttributeCoordinates(null);
    aCoordinates.setGroup(AbstractAttribute.ROOT);
    aCoordinates.setShow(false);
    aCoordinates.setEditable(false);
    initAttribute(aCoordinates);

    BAttributeSize aSize = new BAttributeSize(null);
    aSize.setGroup(AbstractAttribute.ROOT);
    aSize.setShow(false);
    aSize.setEditable(false);
    initAttribute(aSize);

    BAttributeHeight aHeight = new BAttributeHeight(12);
    aHeight.setGroup(BAttributeSize.ID);
    aHeight.setShow(false);
    aHeight.setEditable(false);
    initAttribute(aHeight);

    BAttributeWidth aWidth = new BAttributeWidth(12);
    aWidth.setGroup(BAttributeSize.ID);
    aWidth.setShow(false);
    aWidth.setEditable(false);
    initAttribute(aWidth);

    initAttribute(new BAttributeBackgroundColor(ColorConstants.lightGray.getRGB()));
  }
  @Override
  protected Command getCreateCommand(CreateRequest request) {

    if (request.getType() == REQ_CREATE && getHost() instanceof AppAbstractEditPart) {

      if (((BControl) ((AppAbstractEditPart) getHost()).getModel()).canHaveChildren()) {

        BControl newObj = (BControl) request.getNewObject();

        CreateCommand createCmd = new CreateCommand(newObj, (BControl) getHost().getModel());

        Rectangle constraint = (Rectangle) getConstraintFor(request);
        constraint.x = (constraint.x < 0) ? 0 : constraint.x;
        constraint.y = (constraint.y < 0) ? 0 : constraint.y;

        BAttributeWidth atrWidth =
            (BAttributeWidth) newObj.getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH);
        BAttributeHeight atrHeight =
            (BAttributeHeight) newObj.getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT);

        if (atrWidth != null) {
          constraint.width = Integer.valueOf(atrWidth.getValue().toString());
        } else {
          constraint.width = (constraint.width <= 0) ? 100 : constraint.width;
        }

        if (atrHeight != null) {
          constraint.height = Integer.valueOf(atrHeight.getValue().toString());
        } else {
          constraint.height = (constraint.height <= 0) ? 100 : constraint.height;
        }

        createCmd.setLayout(constraint);

        Command cmd = chainGuideAttachmentCommand(request, newObj, createCmd, true);
        return chainGuideAttachmentCommand(request, newObj, cmd, false);
      }
    }

    return null;
  }