Search in sources :

Example 1 with DBPAuthModelDescriptor

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

the class AuthModelSelector method loadSettings.

public void loadSettings(DBPDataSourceContainer dataSourceContainer, DBPAuthModelDescriptor activeAuthModel, String defaultAuthModelId) {
    this.activeDataSource = dataSourceContainer;
    this.selectedAuthModel = activeAuthModel;
    this.allAuthModels = activeDataSource.getDriver() == DriverDescriptor.NULL_DRIVER ? DataSourceProviderRegistry.getInstance().getAllAuthModels() : DataSourceProviderRegistry.getInstance().getApplicableAuthModels(activeDataSource.getDriver());
    this.allAuthModels.removeIf(o -> modelFilter != null && !modelFilter.isValidElement(o));
    this.allAuthModels.sort((Comparator<DBPAuthModelDescriptor>) (o1, o2) -> AuthModelDatabaseNative.ID.equals(o1.getId()) ? -1 : (AuthModelDatabaseNative.ID.equals(o2.getId()) ? 1 : o1.getName().compareTo(o2.getName())));
    if (selectedAuthModel == null && !CommonUtils.isEmpty(defaultAuthModelId)) {
        // Set default to native
        for (DBPAuthModelDescriptor amd : allAuthModels) {
            if (amd.getId().equals(defaultAuthModelId)) {
                selectedAuthModel = amd;
                break;
            }
        }
        if (selectedAuthModel == null) {
            // First one
            selectedAuthModel = allAuthModels.get(0);
        }
    }
    changeAuthModel();
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) IElementFilter(org.jkiss.dbeaver.ui.IElementFilter) UIConnectionMessages(org.jkiss.dbeaver.ui.internal.UIConnectionMessages) org.eclipse.swt.widgets(org.eclipse.swt.widgets) IObjectPropertyConfigurator(org.jkiss.dbeaver.ui.IObjectPropertyConfigurator) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) AuthModelDatabaseNative(org.jkiss.dbeaver.model.impl.auth.AuthModelDatabaseNative) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SWT(org.eclipse.swt.SWT) Log(org.jkiss.dbeaver.Log) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) UIPropertyConfiguratorRegistry(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorRegistry) Comparator(java.util.Comparator) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor)

Example 2 with DBPAuthModelDescriptor

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

the class AuthModelSelector method showAuthModelSettings.

protected void showAuthModelSettings() {
    Composite parentFolder = UIUtils.getParentOfType(modelConfigPlaceholder, TabFolder.class);
    if (parentFolder == null) {
        parentFolder = UIUtils.getParentOfType(modelConfigPlaceholder, Shell.class);
    }
    modelConfigPlaceholder.setRedraw(false);
    UIUtils.disposeChildControls(modelConfigPlaceholder);
    Label authModelLabel = UIUtils.createControlLabel(modelConfigPlaceholder, UIConnectionMessages.dialog_connection_auth_group);
    Composite authModelComp = UIUtils.createComposite(modelConfigPlaceholder, 2);
    authModelComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Combo authModelCombo = new Combo(authModelComp, SWT.DROP_DOWN | SWT.READ_ONLY);
    authModelCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    authModelCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DBPAuthModelDescriptor newAuthModel = allAuthModels.get(authModelCombo.getSelectionIndex());
            if (selectedAuthModel != newAuthModel) {
                if (modelChangeFilter != null && !modelChangeFilter.isValidElement(newAuthModel)) {
                    authModelCombo.select(allAuthModels.indexOf(selectedAuthModel));
                    return;
                }
                selectedAuthModel = newAuthModel;
                showAuthModelSettings();
            }
            modelConfigPlaceholder.setFocus();
            changeListener.run();
        }
    });
    Label authModelDescLabel = new Label(authModelComp, SWT.NONE);
    authModelDescLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (selectedAuthModel != null) {
    // authModelDescLabel.setText(CommonUtils.notEmpty(selectedAuthModel.getDescription()));
    }
    for (DBPAuthModelDescriptor model : allAuthModels) {
        authModelCombo.add(model.getName());
    }
    if (selectedAuthModel != null) {
        authModelCombo.select(allAuthModels.indexOf(selectedAuthModel));
    }
    boolean authSelectorVisible = allAuthModels.size() >= 2;
    authModelLabel.setVisible(authSelectorVisible);
    ((GridData) authModelLabel.getLayoutData()).exclude = !authSelectorVisible;
    authModelComp.setVisible(authSelectorVisible);
    ((GridData) authModelComp.getLayoutData()).exclude = !authSelectorVisible;
    ((Group) modelConfigPlaceholder).setText(authSelectorVisible ? UIConnectionMessages.dialog_connection_auth_group : UIConnectionMessages.dialog_connection_auth_group + " (" + selectedAuthModel.getName() + ")");
    {
        authModelConfigurator = null;
        UIPropertyConfiguratorDescriptor uiConfiguratorDescriptor = UIPropertyConfiguratorRegistry.getInstance().getDescriptor(selectedAuthModel.getImplClassName());
        if (uiConfiguratorDescriptor != null) {
            try {
                authModelConfigurator = uiConfiguratorDescriptor.createConfigurator();
            } catch (DBException e) {
                log.error(e);
            }
        }
    }
    if (authModelConfigurator != null) {
        authModelConfigurator.createControl(modelConfigPlaceholder, () -> changeListener.run());
        authModelConfigurator.loadSettings(activeDataSource);
    } else {
        if (selectedAuthModel != null && !CommonUtils.isEmpty(selectedAuthModel.getDescription())) {
            Label descLabel = new Label(modelConfigPlaceholder, SWT.NONE);
            descLabel.setText(selectedAuthModel.getDescription());
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 2;
            descLabel.setLayoutData(gd);
        }
    }
    modelConfigPlaceholder.setRedraw(true);
    if (modelConfigPlaceholder.getSize().x > 0 && parentFolder != null) {
        parentFolder.layout(true, true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with DBPAuthModelDescriptor

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

the class ConnectionPageWithAuth method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    DBPDataSourceContainer activeDataSource = getSite().getActiveDataSource();
    DBPAuthModelDescriptor selectedAuthModel = null;
    DBPConnectionConfiguration configuration = activeDataSource.getConnectionConfiguration();
    if (site.isNew() && CommonUtils.isEmpty(configuration.getUserName())) {
        configuration.setUserName(activeDataSource.getDriver().getDefaultUser());
    }
    String dsModelId = configuration.getAuthModelId();
    if (dsModelId != null) {
        selectedAuthModel = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getAuthModel(dsModelId);
    }
    authModelSelector.loadSettings(getSite().getActiveDataSource(), selectedAuthModel, getDefaultAuthModelId(activeDataSource));
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 4 with DBPAuthModelDescriptor

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

the class AuthModelSelector method showAuthModelSettings.

protected void showAuthModelSettings() {
    Composite parentFolder = UIUtils.getParentOfType(modelConfigPlaceholder, TabFolder.class);
    if (parentFolder == null) {
        parentFolder = UIUtils.getParentOfType(modelConfigPlaceholder, Shell.class);
    }
    modelConfigPlaceholder.setRedraw(false);
    UIUtils.disposeChildControls(modelConfigPlaceholder);
    Label authModelLabel = UIUtils.createControlLabel(modelConfigPlaceholder, UIConnectionMessages.dialog_connection_auth_group);
    Composite authModelComp = UIUtils.createComposite(modelConfigPlaceholder, 2);
    authModelComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Combo authModelCombo = new Combo(authModelComp, SWT.DROP_DOWN | SWT.READ_ONLY);
    authModelCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    authModelCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DBPAuthModelDescriptor newAuthModel = allAuthModels.get(authModelCombo.getSelectionIndex());
            if (selectedAuthModel != newAuthModel) {
                if (modelChangeFilter != null && !modelChangeFilter.isValidElement(newAuthModel)) {
                    authModelCombo.select(allAuthModels.indexOf(selectedAuthModel));
                    return;
                }
                selectedAuthModel = newAuthModel;
                showAuthModelSettings();
            }
            modelConfigPlaceholder.setFocus();
            changeListener.run();
        }
    });
    Label authModelDescLabel = new Label(authModelComp, SWT.NONE);
    authModelDescLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (selectedAuthModel != null) {
    // authModelDescLabel.setText(CommonUtils.notEmpty(selectedAuthModel.getDescription()));
    }
    for (DBPAuthModelDescriptor model : allAuthModels) {
        authModelCombo.add(model.getName());
    }
    if (selectedAuthModel != null) {
        authModelCombo.select(allAuthModels.indexOf(selectedAuthModel));
    }
    boolean authSelectorVisible = allAuthModels.size() >= 2;
    authModelLabel.setVisible(authSelectorVisible);
    ((GridData) authModelLabel.getLayoutData()).exclude = !authSelectorVisible;
    authModelComp.setVisible(authSelectorVisible);
    ((GridData) authModelComp.getLayoutData()).exclude = !authSelectorVisible;
    ((Group) modelConfigPlaceholder).setText(authSelectorVisible ? UIConnectionMessages.dialog_connection_auth_group : UIConnectionMessages.dialog_connection_auth_group + " (" + selectedAuthModel.getName() + ")");
    {
        authModelConfigurator = null;
        UIPropertyConfiguratorDescriptor uiConfiguratorDescriptor = UIPropertyConfiguratorRegistry.getInstance().getDescriptor(selectedAuthModel.getImplClassName());
        if (uiConfiguratorDescriptor != null) {
            try {
                authModelConfigurator = uiConfiguratorDescriptor.createConfigurator();
            } catch (DBException e) {
                log.error(e);
            }
        }
    }
    if (authModelConfigurator != null) {
        authModelConfigurator.createControl(modelConfigPlaceholder, () -> changeListener.run());
        authModelConfigurator.loadSettings(activeDataSource);
    } else {
        if (selectedAuthModel != null && !CommonUtils.isEmpty(selectedAuthModel.getDescription())) {
            Label descLabel = new Label(modelConfigPlaceholder, SWT.NONE);
            descLabel.setText(selectedAuthModel.getDescription());
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 2;
            descLabel.setLayoutData(gd);
        }
    }
    modelConfigPlaceholder.setRedraw(true);
    if (modelConfigPlaceholder.getSize().x > 0 && parentFolder != null) {
        parentFolder.layout(true, true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 5 with DBPAuthModelDescriptor

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

the class ConnectionPageWithAuth method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    DBPDataSourceContainer activeDataSource = getSite().getActiveDataSource();
    DBPAuthModelDescriptor selectedAuthModel = null;
    DBPConnectionConfiguration configuration = activeDataSource.getConnectionConfiguration();
    if (site.isNew() && CommonUtils.isEmpty(configuration.getUserName())) {
        configuration.setUserName(activeDataSource.getDriver().getDefaultUser());
    }
    String dsModelId = configuration.getAuthModelId();
    if (dsModelId != null) {
        selectedAuthModel = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getAuthModel(dsModelId);
    }
    authModelSelector.loadSettings(getSite().getActiveDataSource(), selectedAuthModel, getDefaultAuthModelId(activeDataSource));
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBPAuthModelDescriptor (org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 DBException (org.jkiss.dbeaver.DBException)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 UIPropertyConfiguratorDescriptor (org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor)4 Comparator (java.util.Comparator)2 List (java.util.List)2 SWT (org.eclipse.swt.SWT)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 org.eclipse.swt.widgets (org.eclipse.swt.widgets)2 Log (org.jkiss.dbeaver.Log)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 AuthModelDatabaseNative (org.jkiss.dbeaver.model.impl.auth.AuthModelDatabaseNative)2 DataSourceProviderRegistry (org.jkiss.dbeaver.registry.DataSourceProviderRegistry)2 UIPropertyConfiguratorRegistry (org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorRegistry)2 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)2 IElementFilter (org.jkiss.dbeaver.ui.IElementFilter)2 IObjectPropertyConfigurator (org.jkiss.dbeaver.ui.IObjectPropertyConfigurator)2