/**
   * Inserts a given Relation in a graph
   *
   * @param graph the graph as target for insertion
   * @param relation the relation that should be inserted
   * @param verticalOffset the vertical offset of the relation
   * @return the mxCell representing the Relation
   */
  private Object insertRelation(mxGraph graph, RelationSchema relation, int verticalOffset) {
    int attributeOffset;
    int horizontalOffset = 0;
    ArrayList<mxCell> attributeCells = new ArrayList<>();

    mxCell relationVertex =
        (mxCell)
            graph.insertVertex(
                parentPane,
                relation.getName(),
                relation,
                horizontalOffset,
                verticalOffset,
                15 * relation.getName().length(),
                25,
                "RELATION_HEADER");

    attributeOffset = (int) (relationVertex.getGeometry().getY() + 25);

    // Add attributes
    for (Attribute attr : relation.getAttributes()) {
      attributeCells.add(
          (mxCell)
              graph.insertVertex(
                  parentPane,
                  attr.getName(),
                  attr,
                  horizontalOffset,
                  attributeOffset,
                  30,
                  25,
                  super.getAttributeStyle(attr, getImageSizeClass(attr))));
      graph.updateCellSize(attributeCells.get(attributeCells.size() - 1));
      horizontalOffset += 30;
    }

    double currentXPos = 0;
    for (int i = 0; i < attributeCells.size(); i++) {
      mxGeometry geo = attributeCells.get(i).getGeometry();
      if (i > 0) {
        currentXPos += attributeCells.get(i - 1).getGeometry().getWidth();
        geo.setX(currentXPos);
      }

      geo.setHeight(25);
      geo.setWidth(geo.getWidth() + 5);
    }

    drawFunctionalDependencies(
        relation.getAttributes(), attributeCells, relation.getFunctionalDependencies());

    return relationVertex;
  }
Ejemplo n.º 2
0
  /**
   * Set the geometry of the block
   *
   * @param geometry change split block geometry
   */
  @Override
  public void setGeometry(mxGeometry geometry) {
    if (geometry != null) {
      geometry.setWidth(DEFAULT_SIZE);
      geometry.setHeight(DEFAULT_SIZE);

      /*
       * Align the geometry on the grid
       */
      if (getParentDiagram() != null && getParentDiagram().isGridEnabled()) {
        final double cx = getParentDiagram().snap(geometry.getCenterX());
        final double cy = getParentDiagram().snap(geometry.getCenterY());

        geometry.setX(cx - (DEFAULT_SIZE / 2));
        geometry.setY(cy - (DEFAULT_SIZE / 2));
      }
    }

    super.setGeometry(geometry);
  }