Search in sources :

Example 1 with DBPConnectionType

use of org.jkiss.dbeaver.model.connection.DBPConnectionType in project dbeaver by serge-rider.

the class ConnectionPageGeneral method createControl.

@Override
public void createControl(Composite parent) {
    boldFont = UIUtils.makeBoldFont(parent.getFont());
    Composite group = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout(2, false);
    group.setLayout(gl);
    //$NON-NLS-1$
    String connectionName = dataSourceDescriptor == null ? "" : dataSourceDescriptor.getName();
    connectionNameText = UIUtils.createLabelText(group, CoreMessages.dialog_connection_wizard_final_label_connection_name, CommonUtils.toString(connectionName));
    connectionNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            connectionNameChanged = true;
            ConnectionPageGeneral.this.getContainer().updateButtons();
        }
    });
    {
        UIUtils.createControlLabel(group, "Connection type");
        Composite ctGroup = UIUtils.createPlaceholder(group, 2, 5);
        connectionTypeCombo = new CSmartCombo<>(ctGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new ConnectionTypeLabelProvider());
        loadConnectionTypes();
        connectionTypeCombo.select(0);
        connectionTypeCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBPConnectionType type = connectionTypeCombo.getItem(connectionTypeCombo.getSelectionIndex());
                autocommit.setSelection(type.isAutocommit());
            }
        });
        Button pickerButton = new Button(ctGroup, SWT.PUSH);
        pickerButton.setText("Edit");
        pickerButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DataSourceDescriptor dataSource = getActiveDataSource();
                UIUtils.showPreferencesFor(getControl().getShell(), dataSource.getConnectionConfiguration().getConnectionType(), PrefPageConnectionTypes.PAGE_ID);
                loadConnectionTypes();
                DBPConnectionType connectionType = dataSource.getConnectionConfiguration().getConnectionType();
                connectionTypeCombo.select(connectionType);
                autocommit.setSelection(connectionType.isAutocommit());
            }
        });
    }
    {
        UIUtils.createControlLabel(group, "Connection folder");
        connectionFolderCombo = new CSmartCombo<>(group, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new ConnectionFolderLabelProvider());
        //connectionFolderCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        loadConnectionFolders();
        connectionFolderCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                dataSourceFolder = connectionFolderCombo.getItem(connectionFolderCombo.getSelectionIndex());
            }
        });
    }
    {
        Composite optionsGroup = new Composite(group, SWT.NONE);
        gl = new GridLayout(2, true);
        gl.verticalSpacing = 0;
        gl.horizontalSpacing = 5;
        gl.marginHeight = 0;
        gl.marginWidth = 0;
        optionsGroup.setLayout(gl);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        optionsGroup.setLayoutData(gd);
        Composite leftSide = UIUtils.createPlaceholder(optionsGroup, 1, 5);
        leftSide.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
        Composite rightSide = UIUtils.createPlaceholder(optionsGroup, 1, 5);
        rightSide.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
        {
            Group securityGroup = UIUtils.createControlGroup(leftSide, CoreMessages.dialog_connection_wizard_final_group_security, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
            savePasswordCheck = UIUtils.createCheckbox(securityGroup, CoreMessages.dialog_connection_wizard_final_checkbox_save_password_locally, dataSourceDescriptor == null || dataSourceDescriptor.isSavePassword());
            savePasswordCheck.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        }
        {
            Group txnGroup = UIUtils.createControlGroup(rightSide, "Connection", 2, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
            autocommit = UIUtils.createLabelCheckbox(txnGroup, CoreMessages.dialog_connection_wizard_final_checkbox_auto_commit, "Sets auto-commit mode for all connections", dataSourceDescriptor != null && dataSourceDescriptor.isDefaultAutoCommit());
            autocommit.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
            autocommit.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (dataSourceDescriptor != null && dataSourceDescriptor.isConnected()) {
                        isolationLevel.setEnabled(!autocommit.getSelection());
                    }
                }
            });
            isolationLevel = UIUtils.createLabelCombo(txnGroup, "Isolation level", "Default transaction isolation level.", SWT.DROP_DOWN | SWT.READ_ONLY);
            defaultSchema = UIUtils.createLabelCombo(txnGroup, "Default schema", "Name of schema or catalog which will be set as default.", SWT.DROP_DOWN);
            keepAliveInterval = UIUtils.createLabelSpinner(txnGroup, "Keep-Alive", "Keep-alive interval (in seconds). Zero turns keep-alive off", 0, 0, Short.MAX_VALUE);
            {
                String bootstrapTooltip = "SQL queries to execute right after connection establishment";
                UIUtils.createControlLabel(txnGroup, "Bootstrap queries").setToolTipText(bootstrapTooltip);
                final Button queriesConfigButton = UIUtils.createPushButton(txnGroup, "Configure ...", DBeaverIcons.getImage(UIIcon.SQL_SCRIPT));
                queriesConfigButton.setToolTipText(bootstrapTooltip);
                if (dataSourceDescriptor != null && !CommonUtils.isEmpty(dataSourceDescriptor.getConnectionConfiguration().getBootstrap().getInitQueries())) {
                    queriesConfigButton.setFont(boldFont);
                }
                queriesConfigButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        EditBootstrapQueriesDialog dialog = new EditBootstrapQueriesDialog(getShell(), bootstrapQueries, ignoreBootstrapErrors);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            bootstrapQueries = dialog.getQueries();
                            ignoreBootstrapErrors = dialog.isIgnoreErrors();
                        }
                    }
                });
            }
            if (getWizard().isNew()) {
                UIUtils.createControlLabel(txnGroup, "Shell Commands");
                eventsButton = new Button(txnGroup, SWT.PUSH);
                eventsButton.setText("Configure ...");
                eventsButton.setImage(DBeaverIcons.getImage(UIIcon.EVENT));
                eventsButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
                eventsButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        configureEvents();
                    }
                });
            }
        }
        {
            Group miscGroup = UIUtils.createControlGroup(leftSide, CoreMessages.dialog_connection_wizard_final_group_misc, 1, GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL, 0);
            showSystemObjects = UIUtils.createCheckbox(miscGroup, CoreMessages.dialog_connection_wizard_final_checkbox_show_system_objects, dataSourceDescriptor == null || dataSourceDescriptor.isShowSystemObjects());
            showSystemObjects.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
            showUtilityObjects = UIUtils.createCheckbox(miscGroup, CoreMessages.dialog_connection_wizard_final_checkbox_show_util_objects, dataSourceDescriptor == null || dataSourceDescriptor.isShowUtilityObjects());
            showUtilityObjects.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
            readOnlyConnection = UIUtils.createCheckbox(miscGroup, CoreMessages.dialog_connection_wizard_final_checkbox_connection_readonly, dataSourceDescriptor != null && dataSourceDescriptor.isConnectionReadOnly());
            gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
            //gd.horizontalSpan = 2;
            readOnlyConnection.setLayoutData(gd);
        }
        {
            // Filters
            filtersGroup = UIUtils.createControlGroup(leftSide, CoreMessages.dialog_connection_wizard_final_group_filters, 1, GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL, 0);
            for (int i = 0; i < filters.size(); i++) {
                final FilterInfo filterInfo = filters.get(i);
                filterInfo.link = UIUtils.createLink(filtersGroup, "<a>" + filterInfo.title + "</a>", new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        EditObjectFilterDialog dialog = new EditObjectFilterDialog(getShell(), filterInfo.title, filterInfo.filter != null ? filterInfo.filter : new DBSObjectFilter(), true);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            filterInfo.filter = dialog.getFilter();
                            if (filterInfo.filter != null && !filterInfo.filter.isNotApplicable()) {
                                filterInfo.link.setFont(boldFont);
                            } else {
                                filterInfo.link.setFont(getFont());
                            }
                        }
                    }
                });
            }
        }
    }
    {
        final Group descGroup = UIUtils.createControlGroup(group, "Description", 1, GridData.FILL_HORIZONTAL, 0);
        ((GridData) descGroup.getLayoutData()).horizontalSpan = 2;
        descriptionText = new Text(descGroup, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.MULTI);
        final GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = descriptionText.getLineHeight() * 3;
        descriptionText.setLayoutData(gd);
    }
    setControl(group);
    UIUtils.setHelp(group, IHelpContextIds.CTX_CON_WIZARD_FINAL);
}
Also used : DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 2 with DBPConnectionType

use of org.jkiss.dbeaver.model.connection.DBPConnectionType in project dbeaver by serge-rider.

the class PrefPageConnectionTypes method createContents.

@Override
protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1, 5);
    {
        typeTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
        typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        UIUtils.createTableColumn(typeTable, SWT.LEFT, "Name");
        UIUtils.createTableColumn(typeTable, SWT.LEFT, "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(SecurityUtils.generateUniqueId(), name, "255,255,255", "New type", true, false);
                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(), "Delete connection type", "Are you sure you want to delete connection type '" + connectionType.getName() + "'?\n" + "All connections of this type will be reset to default type (" + 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, "Settings", 2, GridData.VERTICAL_ALIGN_BEGINNING, 300);
        groupSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
        typeName = UIUtils.createLabelText(groupSettings, "Name", null);
        typeName.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                getSelectedType().setName(typeName.getText());
                updateTableInfo();
            }
        });
        typeDescription = UIUtils.createLabelText(groupSettings, "Description", null);
        typeDescription.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                getSelectedType().setDescription(typeDescription.getText());
                updateTableInfo();
            }
        });
        {
            UIUtils.createControlLabel(groupSettings, "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(new IPropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent 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();
                        }
                    }
                });
*/
        }
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        autocommitCheck = UIUtils.createCheckbox(groupSettings, "Auto-commit by default", false);
        autocommitCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                getSelectedType().setAutocommit(autocommitCheck.getSelection());
            }
        });
        autocommitCheck.setLayoutData(gd);
        confirmCheck = UIUtils.createCheckbox(groupSettings, "Confirm SQL execution", false);
        confirmCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                getSelectedType().setConfirmExecute(confirmCheck.getSelection());
            }
        });
        confirmCheck.setLayoutData(gd);
    }
    performDefaults();
    return composite;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) GridData(org.eclipse.swt.layout.GridData) ColorSelector(org.eclipse.jface.preference.ColorSelector)

Example 3 with DBPConnectionType

use of org.jkiss.dbeaver.model.connection.DBPConnectionType in project dbeaver by serge-rider.

the class PrefPageConnectionTypes method performOk.

@Override
public boolean performOk() {
    DataSourceProviderRegistry registry = DataSourceProviderRegistry.getInstance();
    java.util.List<DBPConnectionType> toRemove = new ArrayList<>();
    for (DBPConnectionType type : registry.getConnectionTypes()) {
        if (!changedInfo.values().contains(type)) {
            // Remove
            toRemove.add(type);
        }
    }
    for (DBPConnectionType connectionType : toRemove) {
        registry.removeConnectionType(connectionType);
    }
    for (DBPConnectionType changed : changedInfo.keySet()) {
        DBPConnectionType source = changedInfo.get(changed);
        if (source == changed) {
            // New type
            registry.addConnectionType(changed);
        } else {
            // Changed type
            source.setName(changed.getName());
            source.setDescription(changed.getDescription());
            source.setAutocommit(changed.isAutocommit());
            source.setConfirmExecute(changed.isConfirmExecute());
            source.setColor(changed.getColor());
        }
    }
    registry.saveConnectionTypes();
    return super.performOk();
}
Also used : DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) ArrayList(java.util.ArrayList)

Example 4 with DBPConnectionType

use of org.jkiss.dbeaver.model.connection.DBPConnectionType in project dbeaver by serge-rider.

the class PrefPageConnectionTypes method performDefaults.

@Override
protected void performDefaults() {
    typeTable.removeAll();
    //colorPicker.loadStandardColors();
    for (DBPConnectionType source : DataSourceProviderRegistry.getInstance().getConnectionTypes()) {
        addTypeToTable(source, new DBPConnectionType(source));
    }
    typeTable.select(0);
    if (selectedType != null) {
        for (int i = 0; i < typeTable.getItemCount(); i++) {
            if (typeTable.getItem(i).getData().equals(selectedType)) {
                typeTable.select(i);
                break;
            }
        }
    }
    showSelectedType(getSelectedType());
    typeTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            UIUtils.packColumns(typeTable, true);
        }
    });
    super.performDefaults();
}
Also used : DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType)

Example 5 with DBPConnectionType

use of org.jkiss.dbeaver.model.connection.DBPConnectionType in project dbeaver by serge-rider.

the class PrefPageConnectionTypes method updateTableInfo.

private void updateTableInfo() {
    DBPConnectionType connectionType = getSelectedType();
    for (TableItem item : typeTable.getItems()) {
        if (item.getData() == connectionType) {
            item.setText(0, connectionType.getName());
            item.setText(1, connectionType.getDescription());
            Color connectionColor = UIUtils.getConnectionTypeColor(connectionType);
            item.setBackground(0, connectionColor);
            item.setBackground(1, connectionColor);
            break;
        }
    }
}
Also used : DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) Color(org.eclipse.swt.graphics.Color)

Aggregations

DBPConnectionType (org.jkiss.dbeaver.model.connection.DBPConnectionType)6 GridData (org.eclipse.swt.layout.GridData)2 ArrayList (java.util.ArrayList)1 ColorSelector (org.eclipse.jface.preference.ColorSelector)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Color (org.eclipse.swt.graphics.Color)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 DBSObjectFilter (org.jkiss.dbeaver.model.struct.DBSObjectFilter)1 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)1 DataSourceProviderRegistry (org.jkiss.dbeaver.registry.DataSourceProviderRegistry)1 CSmartCombo (org.jkiss.dbeaver.ui.controls.CSmartCombo)1 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)1 XMLException (org.jkiss.utils.xml.XMLException)1