/** * 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; }
/** Displays all relations with their functional dependencies */ private void display() { int offset = 5; mxCell relationCell; removeAllRelations(); for (RelationSchema relation : dbRelations) { relationCell = (mxCell) insertRelation(graph, relation, offset); offset += relationCell.getGeometry().getHeight() + (50 + 30 * relation.getFunctionalDependencies().size()); } }