Search in sources :

Example 1 with EditConstraintPage

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

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 2 with EditConstraintPage

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

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 3 with EditConstraintPage

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

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)

Example 4 with EditConstraintPage

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

the class EditVirtualEntityDialog method createUniqueKeysPage.

private void createUniqueKeysPage(TabFolder tabFolder) {
    uniqueConstraint = vEntity.getBestIdentifier();
    if (uniqueConstraint == null) {
        return;
    }
    TabItem ukItem = new TabItem(tabFolder, SWT.NONE);
    ukItem.setText("Virtual Unique Key");
    ukItem.setImage(DBeaverIcons.getImage(DBIcon.TREE_UNIQUE_KEY));
    ukItem.setData(InitPage.UNIQUE_KEY);
    editUniqueKeyPage = new EditConstraintPage("Define unique identifier", uniqueConstraint);
    editUniqueKeyPage.createControl(tabFolder);
    ukItem.setControl(editUniqueKeyPage.getControl());
}
Also used : EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Example 5 with EditConstraintPage

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

the class ResultSetViewer method editEntityIdentifier.

boolean editEntityIdentifier(DBRProgressMonitor monitor) throws DBException {
    DBDRowIdentifier virtualEntityIdentifier = getVirtualEntityIdentifier();
    if (virtualEntityIdentifier == null) {
        log.warn("No virtual identifier");
        return false;
    }
    DBVEntityConstraint constraint = (DBVEntityConstraint) virtualEntityIdentifier.getUniqueKey();
    EditConstraintPage page = new EditConstraintPage("Define virtual unique identifier", constraint);
    if (!page.edit()) {
        return false;
    }
    Collection<DBSEntityAttribute> uniqueAttrs = page.getSelectedAttributes();
    constraint.setAttributes(uniqueAttrs);
    virtualEntityIdentifier = getVirtualEntityIdentifier();
    if (virtualEntityIdentifier == null) {
        log.warn("No virtual identifier defined");
        return false;
    }
    virtualEntityIdentifier.reloadAttributes(monitor, model.getAttributes());
    persistConfig();
    return true;
}
Also used : 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