Ejemplo n.º 1
0
  @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;
  }