use of org.jkiss.dbeaver.ext.erd.model.ERDAssociation in project dbeaver by serge-rider.
the class AssociationReconnectTargetCommand method canExecute.
/**
* Makes sure that foreign key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDEntity foreignKeyEntity = relationship.getForeignKeyEntity();
if (foreignKeyEntity.equals(targetPrimaryKey)) {
returnVal = false;
} else {
List<?> relationships = targetPrimaryKey.getPrimaryKeyRelationships();
for (int i = 0; i < relationships.size(); i++) {
ERDAssociation relationship = ((ERDAssociation) (relationships.get(i)));
if (relationship.getForeignKeyEntity().equals(sourceForeignKey) && relationship.getPrimaryKeyEntity().equals(targetPrimaryKey)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
use of org.jkiss.dbeaver.ext.erd.model.ERDAssociation in project dbeaver by serge-rider.
the class AssociationPart method createFigure.
@Override
protected IFigure createFigure() {
ERDAssociation association = (ERDAssociation) getModel();
PolylineConnection conn = (PolylineConnection) super.createFigure();
//conn.setToolTip(new TextFlow(association.getObject().getName()));
if (association.getObject().getConstraintType() == DBSEntityConstraintType.INHERITANCE) {
final PolygonDecoration srcDec = new PolygonDecoration();
srcDec.setTemplate(PolygonDecoration.TRIANGLE_TIP);
srcDec.setFill(true);
srcDec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
srcDec.setScale(10, 6);
conn.setSourceDecoration(srcDec);
}
if (association.getObject().getConstraintType() == DBSEntityConstraintType.FOREIGN_KEY) {
final CircleDecoration targetDecor = new CircleDecoration();
targetDecor.setRadius(3);
targetDecor.setFill(true);
targetDecor.setBackgroundColor(getParent().getViewer().getControl().getForeground());
//dec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
conn.setTargetDecoration(targetDecor);
if (!association.isIdentifying()) {
final RhombusDecoration sourceDecor = new RhombusDecoration();
sourceDecor.setBackgroundColor(getParent().getViewer().getControl().getBackground());
//dec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
conn.setSourceDecoration(sourceDecor);
}
}
if (!association.isIdentifying() || association.isLogical()) {
conn.setLineStyle(SWT.LINE_CUSTOM);
conn.setLineDash(new float[] { 5 });
}
//ChopboxAnchor sourceAnchor = new ChopboxAnchor(classFigure);
//ChopboxAnchor targetAnchor = new ChopboxAnchor(classFigure2);
//conn.setSourceAnchor(sourceAnchor);
//conn.setTargetAnchor(targetAnchor);
/*
ConnectionEndpointLocator relationshipLocator = new ConnectionEndpointLocator(conn, true);
//relationshipLocator.setUDistance(30);
//relationshipLocator.setVDistance(-20);
Label relationshipLabel = new Label(association.getObject().getName());
conn.add(relationshipLabel, relationshipLocator);
*/
// Set router and initial bends
ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
conn.setConnectionRouter(cLayer.getConnectionRouter());
if (!CommonUtils.isEmpty(association.getInitBends())) {
List<AbsoluteBendpoint> connBends = new ArrayList<>();
for (Point bend : association.getInitBends()) {
connBends.add(new AbsoluteBendpoint(bend.x, bend.y));
}
conn.setRoutingConstraint(connBends);
} else if (association.getPrimaryKeyEntity() == association.getForeignKeyEntity()) {
// Self link
final IFigure entityFigure = ((GraphicalEditPart) getSource()).getFigure();
//EntityPart entity = (EntityPart) connEdge.source.getParent().data;
//final Dimension entitySize = entity.getFigure().getSize();
final Dimension figureSize = entityFigure.getMinimumSize();
int entityWidth = figureSize.width;
int entityHeight = figureSize.height;
List<RelativeBendpoint> bends = new ArrayList<>();
{
RelativeBendpoint bp1 = new RelativeBendpoint(conn);
bp1.setRelativeDimensions(new Dimension(entityWidth, entityHeight / 2), new Dimension(entityWidth / 2, entityHeight / 2));
bends.add(bp1);
}
{
RelativeBendpoint bp2 = new RelativeBendpoint(conn);
bp2.setRelativeDimensions(new Dimension(-entityWidth, entityHeight / 2), new Dimension(entityWidth, entityHeight));
bends.add(bp2);
}
conn.setRoutingConstraint(bends);
}
// Set tool tip
Label toolTip = new Label(getAssociation().getObject().getName() + " [" + getAssociation().getObject().getConstraintType().getName() + "]");
toolTip.setIcon(DBeaverIcons.getImage(DBIcon.TREE_FOREIGN_KEY));
//toolTip.setTextPlacement(PositionConstants.SOUTH);
//toolTip.setIconTextGap();
conn.setToolTip(toolTip);
return conn;
}
Aggregations