Search in sources :

Example 1 with DBSEntityConstraintType

use of org.jkiss.dbeaver.model.struct.DBSEntityConstraintType in project dbeaver by serge-rider.

the class AssociationPart method setConnectionStyles.

protected void setConnectionStyles(PolylineConnection conn) {
    ERDAssociation association = getAssociation();
    boolean identifying = ERDUtils.isIdentifyingAssociation(association);
    DBSEntityConstraintType constraintType = association.getObject().getConstraintType();
    if (constraintType == 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.setTargetDecoration(srcDec);
    } else if (constraintType.isAssociation()) {
        final CircleDecoration sourceDecor = new CircleDecoration();
        sourceDecor.setRadius(3);
        sourceDecor.setFill(true);
        sourceDecor.setBackgroundColor(getParent().getViewer().getControl().getForeground());
        // dec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
        conn.setSourceDecoration(sourceDecor);
        if (!identifying) {
            final RhombusDecoration targetDecor = new RhombusDecoration();
            targetDecor.setBackgroundColor(getParent().getViewer().getControl().getBackground());
            // dec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
            conn.setTargetDecoration(targetDecor);
        }
    }
    if (!identifying || constraintType.isLogical()) {
        conn.setLineStyle(SWT.LINE_CUSTOM);
        conn.setLineDash(constraintType.isLogical() ? new float[] { 4 } : new float[] { 5 });
    }
}
Also used : DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Example 2 with DBSEntityConstraintType

use of org.jkiss.dbeaver.model.struct.DBSEntityConstraintType in project dbeaver by dbeaver.

the class AssociationPart method setConnectionStyles.

protected void setConnectionStyles(PolylineConnection conn) {
    ERDAssociation association = getAssociation();
    boolean identifying = ERDUtils.isIdentifyingAssociation(association);
    DBSEntityConstraintType constraintType = association.getObject().getConstraintType();
    if (constraintType == 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.setTargetDecoration(srcDec);
    } else if (constraintType.isAssociation()) {
        final CircleDecoration sourceDecor = new CircleDecoration();
        sourceDecor.setRadius(3);
        sourceDecor.setFill(true);
        sourceDecor.setBackgroundColor(getParent().getViewer().getControl().getForeground());
        // dec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
        conn.setSourceDecoration(sourceDecor);
        if (!identifying) {
            final RhombusDecoration targetDecor = new RhombusDecoration();
            targetDecor.setBackgroundColor(getParent().getViewer().getControl().getBackground());
            // dec.setBackgroundColor(getParent().getViewer().getControl().getBackground());
            conn.setTargetDecoration(targetDecor);
        }
    }
    if (!identifying || constraintType.isLogical()) {
        conn.setLineStyle(SWT.LINE_CUSTOM);
        conn.setLineDash(constraintType.isLogical() ? new float[] { 4 } : new float[] { 5 });
    }
}
Also used : DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Example 3 with DBSEntityConstraintType

use of org.jkiss.dbeaver.model.struct.DBSEntityConstraintType in project dbeaver by serge-rider.

the class MySQLConstraintConfigurator method configureObject.

@Override
public MySQLTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableConstraint constraint) {
    MySQLDataSource dataSource = constraint.getDataSource();
    return UITask.run(() -> {
        EditConstraintPage editPage;
        if (dataSource.supportsCheckConstraints()) {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        } else {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        }
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (editPage.getConstraintType() == DBSEntityConstraintType.CHECK && dataSource.supportsCheckConstraints()) {
            constraint.setCheckClause(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new MySQLTableConstraintColumn(constraint, (MySQLTableColumn) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint) MySQLTableConstraintColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)

Example 4 with DBSEntityConstraintType

use of org.jkiss.dbeaver.model.struct.DBSEntityConstraintType in project dbeaver by dbeaver.

the class MySQLConstraintConfigurator method configureObject.

@Override
public MySQLTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableConstraint constraint) {
    MySQLDataSource dataSource = constraint.getDataSource();
    return UITask.run(() -> {
        EditConstraintPage editPage;
        if (dataSource.supportsCheckConstraints()) {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        } else {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        }
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (editPage.getConstraintType() == DBSEntityConstraintType.CHECK && dataSource.supportsCheckConstraints()) {
            constraint.setCheckClause(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new MySQLTableConstraintColumn(constraint, (MySQLTableColumn) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint) MySQLTableConstraintColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)

Aggregations

DBSEntityConstraintType (org.jkiss.dbeaver.model.struct.DBSEntityConstraintType)4 ERDAssociation (org.jkiss.dbeaver.erd.model.ERDAssociation)2 MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)2 MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)2 MySQLTableConstraint (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint)2 MySQLTableConstraintColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)2 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)2 EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)2