Search in sources :

Example 11 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by dbeaver.

the class PostgreConstraintConfigurator method configureObject.

@Override
public PostgreTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, PostgreTableConstraint constraint) {
    return UITask.run(() -> {
        EditConstraintPage editPage = new EditConstraintPage(PostgreMessages.edit_constraint_page_add_constraint, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (constraint.getConstraintType().isCustom()) {
            constraint.setSource(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new PostgreTableConstraintColumn(constraint, (PostgreAttribute) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) PostgreTableConstraintColumn(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) PostgreTableConstraint(org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint) PostgreAttribute(org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute)

Example 12 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by dbeaver.

the class SQLServerUniqueKeyConfigurator method configureObject.

@Override
public SQLServerTableUniqueKey configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableUniqueKey primaryKey) {
    return UITask.run(() -> {
        EditConstraintPage editPage = new EditConstraintPage("Create constraint", primaryKey, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        if (!editPage.edit()) {
            return null;
        }
        primaryKey.setConstraintType(editPage.getConstraintType());
        primaryKey.setName(editPage.getConstraintName());
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            primaryKey.addColumn(new SQLServerTableUniqueKeyColumn(primaryKey, (SQLServerTableColumn) tableColumn, colIndex++));
        }
        return primaryKey;
    });
}
Also used : SQLServerTableColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) SQLServerTableUniqueKeyColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableUniqueKeyColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Example 13 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by dbeaver.

the class OracleConstraintConfigurator method configureObject.

@Override
public OracleTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, OracleTableConstraint constraint) {
    return UITask.run(() -> {
        EditConstraintPage editPage = new EditConstraintPage(OracleUIMessages.edit_oracle_constraint_manager_dialog_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        constraint.setSearchCondition(editPage.getConstraintExpression());
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            constraint.addColumn(new OracleTableConstraintColumn(constraint, (OracleTableColumn) tableColumn, colIndex++));
        }
        return constraint;
    });
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) OracleTableColumn(org.jkiss.dbeaver.ext.oracle.model.OracleTableColumn) OracleTableConstraintColumn(org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraintColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) OracleTableConstraint(org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraint)

Example 14 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by dbeaver.

the class VirtualStructureEditor method createUniqueKeysPage.

private void createUniqueKeysPage(Composite parent) {
    uniqueConstraint = vEntity.getBestIdentifier();
    if (uniqueConstraint == null) {
        return;
    }
    Group group = UIUtils.createControlGroup(parent, DataEditorsMessages.virtual_structure_editor_columns_group_unique_keys, 1, GridData.FILL_BOTH, SWT.DEFAULT);
    ukTable = new Table(group, SWT.FULL_SELECTION | SWT.BORDER);
    ukTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    ukTable.setHeaderVisible(true);
    UIUtils.createTableColumn(ukTable, SWT.LEFT, DataEditorsMessages.virtual_structure_editor_table_column_key_name);
    UIUtils.createTableColumn(ukTable, SWT.LEFT, DataEditorsMessages.virtual_structure_editor_table_column_columns);
    {
        Composite buttonsPanel = UIUtils.createComposite(group, 3);
        buttonsPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        Button btnAdd = UIUtils.createDialogButton(buttonsPanel, DataEditorsMessages.virtual_structure_editor_dialog_button_add, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBVEntityConstraint newConstraint = new DBVEntityConstraint(vEntity, DBSEntityConstraintType.VIRTUAL_KEY, vEntity.getName() + "_uk");
                EditConstraintPage editPage = new EditConstraintPage(DataEditorsMessages.virtual_structure_editor_constraint_page_edit_key, newConstraint);
                if (editPage.edit()) {
                    changeConstraint(newConstraint, editPage);
                    vEntity.addConstraint(newConstraint);
                    createUniqueKeyItem(ukTable, newConstraint);
                    vEntity.persistConfiguration();
                }
            }
        });
        SelectionAdapter ukEditListener = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                TableItem ukItem = ukTable.getSelection()[0];
                DBVEntityConstraint virtualUK = (DBVEntityConstraint) ukItem.getData();
                EditConstraintPage editPage = new EditConstraintPage(DataEditorsMessages.virtual_structure_editor_constraint_page_edit_key, virtualUK);
                if (editPage.edit()) {
                    changeConstraint(virtualUK, editPage);
                    ukItem.setText(0, DBUtils.getObjectFullName(virtualUK, DBPEvaluationContext.UI));
                    ukItem.setText(1, getConstraintAttrNames(virtualUK));
                    vEntity.persistConfiguration();
                }
            }
        };
        Button btnEdit = UIUtils.createDialogButton(buttonsPanel, DataEditorsMessages.virtual_structure_editor_dialog_button_edit, ukEditListener);
        btnEdit.setEnabled(false);
        Button btnRemove = UIUtils.createDialogButton(buttonsPanel, DataEditorsMessages.virtual_structure_editor_dialog_button_remove, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBVEntityConstraint virtualUK = (DBVEntityConstraint) ukTable.getSelection()[0].getData();
                if (!UIUtils.confirmAction(parent.getShell(), DataEditorsMessages.virtual_structure_editor_confirm_action_delete_key, NLS.bind(DataEditorsMessages.virtual_structure_editor_confirm_action_question_delete, virtualUK.getName()))) {
                    return;
                }
                vEntity.removeConstraint(virtualUK);
                ukTable.remove(ukTable.getSelectionIndices());
                vEntity.persistConfiguration();
            }
        });
        btnRemove.setEnabled(false);
        ukTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                btnRemove.setEnabled(ukTable.getSelectionIndex() >= 0);
                btnEdit.setEnabled(ukTable.getSelectionIndex() >= 0);
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                ukEditListener.widgetSelected(e);
            }
        });
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Aggregations

EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)14 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 SQLServerTableColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn)2 SQLServerTableUniqueKeyColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableUniqueKeyColumn)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 OracleTableColumn (org.jkiss.dbeaver.ext.oracle.model.OracleTableColumn)2 OracleTableConstraint (org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraint)2 OracleTableConstraintColumn (org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraintColumn)2 PostgreAttribute (org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute)2 PostgreTableConstraint (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint)2 PostgreTableConstraintColumn (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintColumn)2 DBSEntityConstraintType (org.jkiss.dbeaver.model.struct.DBSEntityConstraintType)2