Search in sources :

Example 6 with ERDAssociation

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;
}
Also used : ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) ERDAssociation(org.jkiss.dbeaver.ext.erd.model.ERDAssociation)

Example 7 with ERDAssociation

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;
}
Also used : ERDAssociation(org.jkiss.dbeaver.ext.erd.model.ERDAssociation) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) PointList(org.eclipse.draw2d.geometry.PointList)

Aggregations

ERDAssociation (org.jkiss.dbeaver.ext.erd.model.ERDAssociation)7 ERDEntity (org.jkiss.dbeaver.ext.erd.model.ERDEntity)4 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 Bendpoint (org.eclipse.draw2d.Bendpoint)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 PointList (org.eclipse.draw2d.geometry.PointList)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 AssociationDeleteCommand (org.jkiss.dbeaver.ext.erd.command.AssociationDeleteCommand)1 AttributeListFigure (org.jkiss.dbeaver.ext.erd.figures.AttributeListFigure)1 EntityFigure (org.jkiss.dbeaver.ext.erd.figures.EntityFigure)1 ERDEntityAttribute (org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute)1 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)1 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)1 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)1