Search in sources :

Example 56 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class ConnectionPageNetworkHandler method updateProfileList.

private void updateProfileList() {
    DBPConnectionConfiguration cfg = site.getActiveDataSource().getConnectionConfiguration();
    String profileId = cfg.getConfigProfileName();
    activeProfile = CommonUtils.isEmpty(profileId) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileId);
    // Refresh profile list
    profileCombo.removeAll();
    profileCombo.add("");
    for (DBWNetworkProfile profile : site.getProject().getDataSourceRegistry().getNetworkProfiles()) {
        profileCombo.add(profile.getProfileName());
        if (CommonUtils.equalObjects(profileId, profile.getProfileName())) {
            profileCombo.select(profileCombo.getItemCount() - 1);
        }
    }
    // Update settings from profile
    if (activeProfile != null) {
    }
    // Update page controls
    handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
    if (handlerConfiguration == null) {
        handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, site.getActiveDataSource());
    }
    useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
    configurator.loadSettings(handlerConfiguration);
    enableHandlerContent();
}
Also used : DBWNetworkProfile(org.jkiss.dbeaver.model.net.DBWNetworkProfile) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 57 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class ConnectionPageNetworkHandler method setConnectionConfigProfile.

private void setConnectionConfigProfile(String profileName) {
    activeProfile = CommonUtils.isEmpty(profileName) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileName);
    DBPDataSourceContainer dataSource = site.getActiveDataSource();
    DBPConnectionConfiguration cfg = dataSource.getConnectionConfiguration();
    String oldProfileId = cfg.getConfigProfileName();
    saveSettings(site.getActiveDataSource());
    if (activeProfile != null) {
        cfg.setConfigProfile(activeProfile);
        handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
        if (handlerConfiguration == null) {
            handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
        }
    } else {
        cfg.setConfigProfile(null);
    }
    site.firePropertyChange(this, PROP_CONFIG_PROFILE, oldProfileId, activeProfile == null ? null : activeProfile.getProfileName());
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 58 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class ConnectionPageNetworkHandler method createControl.

@Override
public void createControl(Composite parent) {
    try {
        String implName = handlerDescriptor.getHandlerType().getImplName();
        UIPropertyConfiguratorDescriptor configDescriptor = UIPropertyConfiguratorRegistry.getInstance().getDescriptor(implName);
        if (configDescriptor == null) {
            return;
        }
        configurator = configDescriptor.createConfigurator();
    } catch (DBException e) {
        log.error("Can't create network configurator '" + handlerDescriptor.getId() + "'", e);
        return;
    }
    DBPDataSourceContainer dataSource = site.getActiveDataSource();
    DBPConnectionConfiguration connectionConfiguration = dataSource.getConnectionConfiguration();
    handlerConfiguration = connectionConfiguration.getHandler(handlerDescriptor.getId());
    if (handlerConfiguration == null) {
        handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
        connectionConfiguration.updateHandler(handlerConfiguration);
    }
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite buttonsGroup = UIUtils.createComposite(composite, 5);
    buttonsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    useHandlerCheck = UIUtils.createCheckbox(buttonsGroup, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, handlerDescriptor.getLabel()), false);
    useHandlerCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
            enableHandlerContent();
        }
    });
    UIUtils.createEmptyLabel(buttonsGroup, 1, 1).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    profileCombo = UIUtils.createLabelCombo(buttonsGroup, "Profile", SWT.READ_ONLY | SWT.DROP_DOWN);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = 200;
    profileCombo.setLayoutData(gd);
    profileCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setConnectionConfigProfile(profileCombo.getText());
        }
    });
    ToolBar editToolbar = new ToolBar(buttonsGroup, SWT.HORIZONTAL);
    ToolItem editItem = new ToolItem(editToolbar, SWT.PUSH);
    editItem.setImage(DBeaverIcons.getImage(UIIcon.EDIT));
    editItem.setToolTipText("Edit profiles");
    editItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            PreferenceDialog preferenceDialog = PreferencesUtil.createPropertyDialogOn(getShell(), site.getProject().getEclipseProject(), PrefPageProjectNetworkProfiles.PAGE_ID, null, null);
            if (preferenceDialog != null) {
                if (preferenceDialog.open() == IDialogConstants.OK_ID) {
                    setConnectionConfigProfile(profileCombo.getText());
                }
            }
        }
    });
    handlerComposite = UIUtils.createComposite(composite, 1);
    handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    configurator.createControl(handlerComposite, this::updatePageCompletion);
    configurator.loadSettings(handlerConfiguration);
    useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
    enableHandlerContent();
    updateProfileList();
    if (activeProfile != null) {
        DBWHandlerConfiguration profileConfig = activeProfile.getConfiguration(handlerDescriptor);
        if (profileConfig != null) {
            configurator.loadSettings(profileConfig);
        }
    }
    setControl(composite);
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) GridLayout(org.eclipse.swt.layout.GridLayout) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 59 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class ConnectionPageGeneral method activatePage.

@Override
public void activatePage() {
    if (this.navigatorSettings == null) {
        this.navigatorSettings = new DataSourceNavigatorSettings(getWizard().getSelectedNavigatorSettings());
    }
    if (connectionNameText != null) {
        if (dataSourceDescriptor != null && !CommonUtils.isEmpty(dataSourceDescriptor.getName())) {
            connectionNameText.setText(dataSourceDescriptor.getName());
            connectionNameChanged = true;
        } else {
            ConnectionPageSettings settings = wizard.getPageSettings();
            if (CommonUtils.isEmpty(connectionNameText.getText()) || !connectionNameChanged) {
                String newName = generateConnectionName(settings);
                if (newName != null) {
                    connectionNameText.setText(newName);
                }
                connectionNameChanged = false;
            }
        }
    }
    if (dataSourceDescriptor != null) {
        if (!activated) {
            // Get settings from data source descriptor
            final DBPConnectionConfiguration conConfig = dataSourceDescriptor.getConnectionConfiguration();
            connectionTypeCombo.select(conConfig.getConnectionType());
            updateNavigatorSettingsPreset();
            dataSourceFolder = dataSourceDescriptor.getFolder();
            if (dataSourceDescriptor.getFolder() == null) {
                connectionFolderCombo.select(0);
            } else {
                connectionFolderCombo.select(connectionFolders.indexOf(dataSourceFolder));
            }
            if (dataSourceDescriptor.getDescription() != null) {
                descriptionText.setText(dataSourceDescriptor.getDescription());
            }
            readOnlyConnection.setSelection(dataSourceDescriptor.isConnectionReadOnly());
            activated = true;
        }
    } else {
        // Default settings
        connectionTypeCombo.select(0);
        if (dataSourceFolder != null) {
            connectionFolderCombo.select(connectionFolders.indexOf(dataSourceFolder));
        } else {
            connectionFolderCombo.select(0);
        }
        readOnlyConnection.setSelection(false);
    }
    long features = getWizard().getSelectedDriver().getDataSourceProvider().getFeatures();
    for (FilterInfo filterInfo : filters) {
        if (DBSCatalog.class.isAssignableFrom(filterInfo.type)) {
            enableFilter(filterInfo, (features & DBPDataSourceProvider.FEATURE_CATALOGS) != 0);
        } else if (DBSSchema.class.isAssignableFrom(filterInfo.type)) {
            enableFilter(filterInfo, (features & DBPDataSourceProvider.FEATURE_SCHEMAS) != 0);
        } else {
            enableFilter(filterInfo, true);
        }
    }
    filtersGroup.layout();
}
Also used : DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DataSourceNavigatorSettings(org.jkiss.dbeaver.registry.DataSourceNavigatorSettings)

Example 60 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class ConnectionPageGeneral method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    if (dataSourceDescriptor != null && !activated) {
        // No changes anyway
        return;
    }
    final DBPConnectionConfiguration confConfig = dataSource.getConnectionConfiguration();
    String name = connectionNameChanged ? connectionNameText.getText() : generateConnectionName(getWizard().getPageSettings());
    dataSource.setName(name);
    dataSource.setFolder(dataSourceFolder);
    if (connectionTypeCombo.getSelectionIndex() >= 0) {
        confConfig.setConnectionType(connectionTypeCombo.getItem(connectionTypeCombo.getSelectionIndex()));
    }
    DataSourceDescriptor dsDescriptor = (DataSourceDescriptor) dataSource;
    final String description = descriptionText.getText();
    if (description.isEmpty()) {
        dsDescriptor.setDescription(null);
    } else {
        dsDescriptor.setDescription(description);
    }
    if (this.navigatorSettings == null) {
        this.navigatorSettings = new DataSourceNavigatorSettings(getWizard().getSelectedNavigatorSettings());
    }
    dsDescriptor.setNavigatorSettings(this.navigatorSettings);
    dsDescriptor.setConnectionReadOnly(this.readOnlyConnection.getSelection());
    dsDescriptor.setModifyPermissions(this.accessRestrictions);
    for (FilterInfo filterInfo : filters) {
        if (filterInfo.filter != null) {
            dataSource.setObjectFilter(filterInfo.type, null, filterInfo.filter);
        }
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DataSourceNavigatorSettings(org.jkiss.dbeaver.registry.DataSourceNavigatorSettings) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)172 DBException (org.jkiss.dbeaver.DBException)25 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)16 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)14 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)12 ArrayList (java.util.ArrayList)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 GridData (org.eclipse.swt.layout.GridData)10 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Button (org.eclipse.swt.widgets.Button)8 Group (org.eclipse.swt.widgets.Group)8 Label (org.eclipse.swt.widgets.Label)8 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)7 Map (java.util.Map)6 Properties (java.util.Properties)6 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)6 File (java.io.File)5