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;
});
}
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;
});
}
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;
});
}
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);
}
});
}
}
Aggregations