use of org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionPermissionsDialog in project dbeaver by serge-rider.
the class PrefPageConnectionTypes method createContents.
@Override
protected Control createContents(final Composite parent) {
Composite composite = UIUtils.createComposite(parent, 1);
{
typeTable = new Table(composite, SWT.SINGLE | SWT.BORDER);
typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
UIUtils.createTableColumn(typeTable, SWT.LEFT, CoreMessages.pref_page_connection_types_label_table_column_name);
UIUtils.createTableColumn(typeTable, SWT.LEFT, CoreMessages.pref_page_connection_types_label_table_column_description);
typeTable.setHeaderVisible(true);
typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
typeTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showSelectedType(getSelectedType());
}
});
ToolBar toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL);
final ToolItem newButton = new ToolItem(toolbar, SWT.NONE);
newButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_ADD));
deleteButton = new ToolItem(toolbar, SWT.NONE);
deleteButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_DELETE));
newButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String name;
for (int i = 1; ; i++) {
name = "Type" + i;
boolean hasName = false;
for (DBPConnectionType type : changedInfo.keySet()) {
if (type.getName().equals(name)) {
hasName = true;
break;
}
}
if (!hasName) {
break;
}
}
DBPConnectionType newType = new DBPConnectionType(name.toLowerCase(), name, "255,255,255", "New type", true, false, true);
addTypeToTable(newType, newType);
typeTable.select(typeTable.getItemCount() - 1);
typeTable.showSelection();
showSelectedType(newType);
}
});
this.deleteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPConnectionType connectionType = getSelectedType();
if (!UIUtils.confirmAction(getShell(), CoreMessages.pref_page_connection_types_label_delete_connection_type, NLS.bind(CoreMessages.pref_page_connection_types_label_delete_connection_type_description, connectionType.getName(), DBPConnectionType.DEFAULT_TYPE.getName()))) {
return;
}
changedInfo.remove(connectionType);
int index = typeTable.getSelectionIndex();
typeTable.remove(index);
if (index > 0)
index--;
typeTable.select(index);
showSelectedType(getSelectedType());
}
});
}
{
Group groupSettings = UIUtils.createControlGroup(composite, CoreMessages.pref_page_connection_types_group_settings, 2, GridData.VERTICAL_ALIGN_BEGINNING, 300);
groupSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
typeId = UIUtils.createLabelText(groupSettings, CoreMessages.pref_page_connection_types_label_id, null);
typeId.addModifyListener(e -> {
getSelectedType().setId(typeId.getText());
updateTableInfo();
});
typeName = UIUtils.createLabelText(groupSettings, CoreMessages.pref_page_connection_types_label_name, null);
typeName.addModifyListener(e -> {
getSelectedType().setName(typeName.getText());
updateTableInfo();
});
typeDescription = UIUtils.createLabelText(groupSettings, CoreMessages.pref_page_connection_types_label_description, null);
typeDescription.addModifyListener(e -> {
getSelectedType().setDescription(typeDescription.getText());
updateTableInfo();
});
{
UIUtils.createControlLabel(groupSettings, CoreMessages.pref_page_connection_types_label_color);
// Composite colorGroup = UIUtils.createPlaceholder(groupSettings, 2, 5);
// colorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
colorPicker = new ColorSelector(groupSettings);
// colorPicker.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
colorPicker.addListener(event -> {
getSelectedType().setColor(StringConverter.asString(colorPicker.getColorValue()));
updateTableInfo();
});
/*
Button pickerButton = new Button(colorGroup, SWT.PUSH);
pickerButton.setText("...");
pickerButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
DBPConnectionType connectionType = getSelectedType();
ColorDialog colorDialog = new ColorDialog(parent.getShell());
colorDialog.setRGB(StringConverter.asRGB(connectionType.getColor()));
RGB rgb = colorDialog.open();
if (rgb != null) {
Color color = null;
int count = colorPicker.getItemCount();
for (int i = 0; i < count; i++) {
Color item = colorPicker.getColorItem(i);
if (item != null && item.getRGB().equals(rgb)) {
color = item;
break;
}
}
if (color == null) {
color = new Color(colorPicker.getDisplay(), rgb);
colorPicker.addColor(color);
}
colorPicker.select(color);
getSelectedType().setColor(StringConverter.asString(color.getRGB()));
updateTableInfo();
}
}
});
*/
}
autocommitCheck = UIUtils.createCheckbox(groupSettings, CoreMessages.pref_page_connection_types_label_auto_commit_by_default, null, false, 2);
autocommitCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getSelectedType().setAutocommit(autocommitCheck.getSelection());
}
});
confirmCheck = UIUtils.createCheckbox(groupSettings, CoreMessages.pref_page_connection_types_label_confirm_sql_execution, null, false, 2);
confirmCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getSelectedType().setConfirmExecute(confirmCheck.getSelection());
}
});
confirmDataChange = UIUtils.createCheckbox(groupSettings, CoreMessages.pref_page_connection_types_label_confirm_data_change, CoreMessages.pref_page_connection_types_label_confirm_data_change_tip, false, 2);
confirmDataChange.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getSelectedType().setConfirmDataChange(confirmDataChange.getSelection());
}
});
Button epButton = UIUtils.createDialogButton(groupSettings, "Edit permissions ...", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditConnectionPermissionsDialog dialog = new EditConnectionPermissionsDialog(getShell(), getSelectedType().getModifyPermission());
if (dialog.open() == IDialogConstants.OK_ID) {
getSelectedType().setModifyPermissions(dialog.getAccessRestrictions());
}
}
});
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalSpan = 2;
epButton.setLayoutData(gd);
}
performDefaults();
return composite;
}
Aggregations