コード例 #1
0
  public IReason updateNeeded(IUpdateContext context) {
    // retrieve name from pictogram model
    String pictogramName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          pictogramName = text.getValue();
        }
      }
    }

    // retrieve name from business model
    String businessName = null;
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // update needed, if names are different
    boolean updateNameNeeded =
        ((pictogramName == null && businessName != null)
            || (pictogramName != null && !pictogramName.equals(businessName)));
    if (updateNameNeeded) {
      return Reason.createTrueReason("Name is out of date");
    } else {
      return Reason.createFalseReason();
    }
  }
コード例 #2
0
  protected void internalResize(IResizeShapeContext context) {
    Shape shape = context.getShape();
    int x = context.getX();
    int y = context.getY();
    int width = context.getWidth();
    int height = context.getHeight();

    if (shape.getGraphicsAlgorithm() != null) {
      Graphiti.getGaService().setLocationAndSize(shape.getGraphicsAlgorithm(), x, y, width, height);
    }
  }
コード例 #3
0
  private void performMove(Shape labelShape, Point position) {

    // always move within the original container
    GraphicsAlgorithm labelGraphicsAlgorithm = labelShape.getGraphicsAlgorithm();

    if (labelGraphicsAlgorithm != null) {
      Graphiti.getGaService()
          .setLocation(
              labelGraphicsAlgorithm,
              position.getX() - labelGraphicsAlgorithm.getWidth() / 2,
              position.getY(),
              true);
    }
  }
コード例 #4
0
  @Override
  public void resizeShape(IResizeShapeContext context) {
    Shape shape = context.getShape();
    int x = context.getX();
    int y = context.getY();

    // Application Component Width cannot be changed
    int width = StyleUtil.APP_COMPONENT_WIDTH;

    int height = context.getHeight();

    if (shape.getGraphicsAlgorithm() != null) {
      Graphiti.getGaService().setLocationAndSize(shape.getGraphicsAlgorithm(), x, y, width, height);
    }

    layoutPictogramElement(shape);

    TNodeTemplateExtension applicationComponent =
        (TNodeTemplateExtension) getBusinessObjectForPictogramElement(shape);
    applicationComponent.setX(x);
    applicationComponent.setY(y);
    applicationComponent.setWidth(width);
    applicationComponent.setHeight(height);
  }
コード例 #5
0
  public boolean update(IUpdateContext context) {
    // retrieve name from business model
    String businessName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // Set name in pictogram model
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          text.setValue(businessName);
          return true;
        }
      }
    }

    return false;
  }
コード例 #6
0
  public boolean layout(ILayoutContext context) {
    boolean anythingChanged = false;
    ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
    GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
    // the containerGa is the invisible rectangle
    // containing the visible rectangle as its (first and only) child
    GraphicsAlgorithm rectangle = containerGa.getGraphicsAlgorithmChildren().get(0);

    // height of invisible rectangle
    if (containerGa.getHeight() < MIN_HEIGHT) {
      containerGa.setHeight(MIN_HEIGHT);
      anythingChanged = true;
    }

    // height of visible rectangle (same as invisible rectangle)
    if (rectangle.getHeight() != containerGa.getHeight()) {
      rectangle.setHeight(containerGa.getHeight());
      anythingChanged = true;
    }

    // width of invisible rectangle
    if (containerGa.getWidth() < MIN_WIDTH) {
      containerGa.setWidth(MIN_WIDTH);
      anythingChanged = true;
    }

    // width of visible rectangle (smaller than invisible rectangle)
    int rectangleWidth = containerGa.getWidth() - AddNodeFeature.INVISIBLE_RIGHT_SPACE;
    if (rectangle.getWidth() != rectangleWidth) {
      rectangle.setWidth(rectangleWidth);
      anythingChanged = true;
    }

    // width of text and line (same as visible rectangle)
    for (Shape shape : containerShape.getChildren()) {
      GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();
      IGaService gaService = Graphiti.getGaService();
      IDimension size = gaService.calculateSize(graphicsAlgorithm);
      if (rectangleWidth != size.getWidth()) {
        gaService.setWidth(graphicsAlgorithm, rectangleWidth);
        anythingChanged = true;
      }
    }

    return anythingChanged;
  }
コード例 #7
0
  protected void moveClassShape(
      IFeatureProvider fp, Diagram diagram, int x, int y, String className) {

    Shape shape = findShapeForEClass(diagram, className);

    MoveShapeContext moveShapeContext = new MoveShapeContext(shape);

    moveShapeContext.setSourceContainer(shape.getContainer());
    moveShapeContext.setTargetContainer(shape.getContainer());
    moveShapeContext.setLocation(x, y);
    moveShapeContext.setDeltaX(x - shape.getGraphicsAlgorithm().getX());
    moveShapeContext.setDeltaY(y - shape.getGraphicsAlgorithm().getY());

    IMoveShapeFeature moveShapeFeature = fp.getMoveShapeFeature(moveShapeContext);
    assertNotNull("move shape feature not available", moveShapeFeature);

    if (moveShapeFeature.canMoveShape(moveShapeContext)) {
      moveShapeFeature.execute(moveShapeContext);
    }
  }
コード例 #8
0
  public boolean layout(ILayoutContext context) {
    boolean anythingChanged = false;
    ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
    GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();

    // height
    if (containerGa.getHeight() < MIN_HEIGHT) {
      containerGa.setHeight(MIN_HEIGHT);
      anythingChanged = true;
    }

    // width
    if (containerGa.getWidth() < MIN_WIDTH) {
      containerGa.setWidth(MIN_WIDTH);
      anythingChanged = true;
    }

    int containerWidth = containerGa.getWidth();

    for (Shape shape : containerShape.getChildren()) {
      GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();
      IGaService gaService = Graphiti.getGaService();
      IDimension size = gaService.calculateSize(graphicsAlgorithm);
      if (containerWidth != size.getWidth()) {
        if (graphicsAlgorithm instanceof Polyline) {
          Polyline polyline = (Polyline) graphicsAlgorithm;
          Point secondPoint = polyline.getPoints().get(1);
          Point newSecondPoint = gaService.createPoint(containerWidth, secondPoint.getY());
          polyline.getPoints().set(1, newSecondPoint);
          anythingChanged = true;
        } else {
          gaService.setWidth(graphicsAlgorithm, containerWidth);
          anythingChanged = true;
        }
      }
    }
    return anythingChanged;
  }