Search in sources :

Example 1 with EditConnectionPermissionsDialog

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;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ColorSelector(org.eclipse.jface.preference.ColorSelector) ControlEvent(org.eclipse.swt.events.ControlEvent) DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SecurityUtils(org.jkiss.utils.SecurityUtils) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IAdaptable(org.eclipse.core.runtime.IAdaptable) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) NLS(org.eclipse.osgi.util.NLS) IWorkbenchPropertyPage(org.eclipse.ui.IWorkbenchPropertyPage) org.eclipse.swt.widgets(org.eclipse.swt.widgets) IWorkbenchPreferencePage(org.eclipse.ui.IWorkbenchPreferencePage) CoreMessages(org.jkiss.dbeaver.core.CoreMessages) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) List(java.util.List) Color(org.eclipse.swt.graphics.Color) EditConnectionPermissionsDialog(org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionPermissionsDialog) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SWT(org.eclipse.swt.SWT) StringConverter(org.eclipse.jface.resource.StringConverter) IWorkbench(org.eclipse.ui.IWorkbench) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) EditConnectionPermissionsDialog(org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionPermissionsDialog)

Aggregations

java.util (java.util)1 List (java.util.List)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 ColorSelector (org.eclipse.jface.preference.ColorSelector)1 StringConverter (org.eclipse.jface.resource.StringConverter)1 NLS (org.eclipse.osgi.util.NLS)1 SWT (org.eclipse.swt.SWT)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Color (org.eclipse.swt.graphics.Color)1 GridData (org.eclipse.swt.layout.GridData)1 org.eclipse.swt.widgets (org.eclipse.swt.widgets)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPreferencePage (org.eclipse.ui.IWorkbenchPreferencePage)1 IWorkbenchPropertyPage (org.eclipse.ui.IWorkbenchPropertyPage)1 CoreMessages (org.jkiss.dbeaver.core.CoreMessages)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1