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