Ejemplo n.º 1
0
  @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;
  }
Ejemplo n.º 2
0
  @Override
  public EditPart createEditPart(EditPart context, Object model) {

    AbstractGraphicalEditPart part = null;

    BControl control = (BControl) model;

    if (control instanceof Visualization) {
      part = new VisualizationPart();
    } else {
      try {
        IBControlService service =
            (IBControlService)
                BMotionEditorPlugin.getControlServices()
                    .get(control.getType())
                    .createExecutableExtension("service");
        part = service.createEditPart();
      } catch (CoreException e) {
        e.printStackTrace();
      }
    }

    if (part != null) part.setModel(control);

    // TODO: check if part == null
    return part;
  }
Ejemplo n.º 3
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.º 4
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;
  }
Ejemplo n.º 5
0
  @Override
  public void check(Animation animation, BControl control) {

    this.setAttributes.clear();

    // Collect evaluate predicate objects in list
    for (SetAttributeObject obj : setAttributeObjects) {

      obj.setHasError(false);

      // First evaluate predicate (predicate field)
      String bolValue = "true";
      if (obj.getEval().length() > 0) {
        bolValue = parsePredicate(obj.getEval(), control, animation, obj);
      }

      if (!obj.hasError() && Boolean.valueOf(bolValue)) {

        String attributeID = obj.getAttribute();

        AbstractAttribute attributeObj = control.getAttribute(attributeID);

        Object attributeVal = obj.getValue();

        if (obj.isExpressionMode()) {
          String strAtrVal = parseExpression(attributeVal.toString(), control, animation, obj);
          String er = attributeObj.validateValue(strAtrVal, null);
          if (er != null) {
            addError(
                control,
                animation,
                "You selected "
                    + attributeObj.getName()
                    + " as attribute. There is a problem with your value: "
                    + strAtrVal
                    + " - Reason: "
                    + er);
            obj.setHasError(true);
          } else {
            attributeVal = attributeObj.unmarshal(strAtrVal);
          }
        }

        if (!obj.hasError()) {
          Object oldAttrVal = control.getAttributeValue(attributeID);
          if (!oldAttrVal.equals(attributeVal)) {
            control.setAttributeValue(attributeID, attributeVal);
          }
        }

        setAttributes.add(attributeID);
      }
    }

    // Restore attribute values
    for (SetAttributeObject obj : setAttributeObjects) {
      if (!setAttributes.contains(obj.getAttribute())) {
        AbstractAttribute attributeObj = control.getAttribute(obj.getAttribute());
        Object oldAttrVal = control.getAttributeValue(obj.getAttribute());
        if (!oldAttrVal.equals(attributeObj.getInitValue())) {
          control.restoreDefaultValue(attributeObj.getID());
        }
      }
    }
  }