Search in sources :

Example 81 with DBPConnectionConfiguration

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

the class SQLServerConnectionPage method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    boolean isDriverAzure = isSqlServer() && isDriverAzure();
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    if (hostText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
            hostText.setText(connectionInfo.getHostName());
        } else {
            hostText.setText(isDriverAzure ? SQLServerConstants.DEFAULT_HOST_AZURE : SQLServerConstants.DEFAULT_HOST);
        }
    }
    if (portText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
            portText.setText(String.valueOf(connectionInfo.getHostPort()));
        } else if (site.getDriver().getDefaultPort() != null) {
            portText.setText(site.getDriver().getDefaultPort());
        } else {
            portText.setText("");
        }
    }
    if (dbText != null) {
        String databaseName = connectionInfo.getDatabaseName();
        if (getSite().isNew() && CommonUtils.isEmpty(databaseName)) {
            databaseName = CommonUtils.notEmpty(site.getDriver().getDefaultDatabase());
        }
        dbText.setText(CommonUtils.notEmpty(databaseName));
    }
    if (userNameText != null) {
        if (site.isNew() && CommonUtils.isEmpty(connectionInfo.getUserName())) {
            userNameText.setText(CommonUtils.notEmpty(site.getDriver().getDefaultUser()));
        } else {
            userNameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
        }
    }
    if (passwordText != null) {
        passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
    }
    if (authCombo != null) {
        authCombo.select(ArrayUtils.indexOf(authSchemas, SQLServerUtils.detectAuthSchema(connectionInfo)));
        updateSecurityControls();
    }
    /*
        if (windowsAuthenticationButton != null) {
            windowsAuthenticationButton.setSelection(SQLServerUtils.isWindowsAuth(connectionInfo));
            enableTexts();
        }
        if (adpAuthenticationButton != null) {
            adpAuthenticationButton.setSelection(SQLServerUtils.isActiveDirectoryAuth(connectionInfo));
        }
*/
    showAllSchemas.setSelection(CommonUtils.toBoolean(connectionInfo.getProviderProperty(SQLServerConstants.PROP_SHOW_ALL_SCHEMAS)));
    activated = true;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 82 with DBPConnectionConfiguration

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

the class PostgreConnectionPageAdvanced method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionCfg = dataSource.getConnectionConfiguration();
    connectionCfg.setProviderProperty(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB, String.valueOf(showNonDefault.getSelection()));
    connectionCfg.setProviderProperty(PostgreConstants.PROP_SHOW_TEMPLATES_DB, String.valueOf(showTemplates.getSelection()));
    connectionCfg.setProviderProperty(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB, String.valueOf(showUnavailable.getSelection()));
    connectionCfg.setProviderProperty(PostgreConstants.PROP_DD_PLAIN_STRING, String.valueOf(ddPlainBehaviorCombo.getSelectionIndex() == 0));
    connectionCfg.setProviderProperty(PostgreConstants.PROP_DD_TAG_STRING, String.valueOf(ddTagBehaviorCombo.getSelectionIndex() == 0));
    saveConnectionURL(connectionCfg);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 83 with DBPConnectionConfiguration

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

the class PostgreToolWizardPageSettings method createSecurityGroup.

public void createSecurityGroup(Composite parent) {
    try {
        final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
        final DBPConnectionConfiguration connectionInfo = wizard.getSettings().getDataSourceContainer().getActualConnectionConfiguration();
        final String authProperty = DBConstants.INTERNAL_PROP_PREFIX + "-auth-" + wizard.getObjectsName() + "@";
        String authUser = null;
        String authPassword = null;
        {
            String authValue = connectionInfo.getProviderProperty(authProperty);
            if (authValue != null) {
                String authCredentials = encrypter.decrypt(authValue);
                int divPos = authCredentials.indexOf(':');
                if (divPos != -1) {
                    authUser = authCredentials.substring(0, divPos);
                    authPassword = authCredentials.substring(divPos + 1);
                }
            }
        }
        final boolean savePassword = authUser != null;
        Group securityGroup = UIUtils.createControlGroup(parent, PostgreMessages.wizard_backup_page_setting_group_security, 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        Label infoLabel = new Label(securityGroup, SWT.NONE);
        infoLabel.setText(NLS.bind(PostgreMessages.wizard_backup_page_setting_group_security_label_info, connectionInfo.getUserName(), wizard.getObjectsName()));
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        infoLabel.setLayoutData(gd);
        Button authButton = new Button(securityGroup, SWT.PUSH);
        authButton.setText(PostgreMessages.wizard_backup_page_setting_group_security_btn_authentication);
        authButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BaseAuthDialog authDialog = new BaseAuthDialog(getShell(), PostgreMessages.wizard_backup_page_setting_group_security_btn_authentication, false, true);
                authDialog.setUserName(wizard.getSettings().getToolUserName());
                authDialog.setUserPassword(wizard.getSettings().getToolUserPassword());
                authDialog.setSavePassword(savePassword);
                authDialog.setSavePasswordText(PostgreMessages.wizard_backup_page_setting_authentication_save_password);
                authDialog.setSavePasswordToolTipText(PostgreMessages.wizard_backup_page_setting_authentication_save_password_tip);
                if (authDialog.open() == IDialogConstants.OK_ID) {
                    wizard.getSettings().setToolUserName(authDialog.getUserName());
                    wizard.getSettings().setToolUserPassword(authDialog.getUserPassword());
                }
            }
        });
        Button resetButton = new Button(securityGroup, SWT.PUSH);
        resetButton.setText(PostgreMessages.wizard_backup_page_setting_group_security_btn_reset_default);
        resetButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                connectionInfo.getProviderProperties().remove(authProperty);
                wizard.getSettings().setToolUserName(null);
                wizard.getSettings().setToolUserPassword(null);
            }
        });
    } catch (EncryptionException e) {
    // Never be here
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SecuredPasswordEncrypter(org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter) Button(org.eclipse.swt.widgets.Button) BaseAuthDialog(org.jkiss.dbeaver.ui.dialogs.BaseAuthDialog) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EncryptionException(org.jkiss.dbeaver.runtime.encode.EncryptionException)

Example 84 with DBPConnectionConfiguration

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

the class PostgreConnectionPage method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    if (hostText != null) {
        connectionInfo.setHostName(hostText.getText().trim());
    }
    if (portText != null) {
        connectionInfo.setHostPort(portText.getText().trim());
    }
    if (dbText != null) {
        connectionInfo.setDatabaseName(dbText.getText().trim());
    }
    if (roleText != null) {
        connectionInfo.setProviderProperty(PostgreConstants.PROP_CHOSEN_ROLE, roleText.getText().trim());
    }
    if (homesSelector != null) {
        connectionInfo.setClientHomeId(homesSelector.getSelectedHome());
    }
    super.saveSettings(dataSource);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 85 with DBPConnectionConfiguration

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

the class GenericConnectionPage method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    this.parseSampleURL(site.getDriver());
    if (!isCustom) {
        if (hostText != null) {
            if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
                hostText.setText(CommonUtils.notEmpty(connectionInfo.getHostName()));
            } else {
                // $NON-NLS-1$
                hostText.setText("localhost");
            }
        }
        if (portText != null) {
            if (site.isNew() && CommonUtils.isEmpty(connectionInfo.getHostPort())) {
                portText.setText(CommonUtils.notEmpty(site.getDriver().getDefaultPort()));
            } else if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
                portText.setText(connectionInfo.getHostPort());
            }
        }
        if (serverText != null) {
            if (site.isNew() && CommonUtils.isEmpty(connectionInfo.getServerName())) {
                serverText.setText(CommonUtils.notEmpty(site.getDriver().getDefaultServer()));
            } else {
                serverText.setText(CommonUtils.notEmpty(connectionInfo.getServerName()));
            }
        }
        if (dbText != null) {
            if (site.isNew() && CommonUtils.isEmpty(connectionInfo.getDatabaseName())) {
                dbText.setText(CommonUtils.notEmpty(site.getDriver().getDefaultDatabase()));
            } else {
                dbText.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
            }
        }
        if (pathText != null) {
            pathText.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
        }
    } else {
        // $NON-NLS-1$
        hostText.setText("");
        // $NON-NLS-1$
        portText.setText("");
        // $NON-NLS-1$
        serverText.setText("");
        // $NON-NLS-1$
        dbText.setText("");
        // $NON-NLS-1$
        pathText.setText("");
    }
    if (urlText != null) {
        if (CommonUtils.isEmpty(connectionInfo.getUrl())) {
            try {
                saveSettings(site.getActiveDataSource());
            } catch (Exception e) {
                setMessage(e.getMessage());
            }
        }
        if (connectionInfo.getUrl() != null) {
            urlText.setText(CommonUtils.notEmpty(connectionInfo.getUrl()));
        } else {
            // $NON-NLS-1$
            urlText.setText("");
        }
    }
    activated = true;
    UIUtils.asyncExec(() -> {
        // Set first control
        if (CommonUtils.isEmpty(site.getDriver().getSampleURL())) {
            urlText.setFocus();
        } else if (hostText != null && hostText.isVisible()) {
            hostText.setFocus();
        } else if (serverText != null && serverText.isVisible()) {
            serverText.setFocus();
        } else if (dbText != null && dbText.isVisible()) {
            dbText.setFocus();
        } else if (pathText != null && pathText.isVisible()) {
            pathText.setFocus();
        }
    });
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

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