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();
}
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);
}
}
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));
}
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);
}
}
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));
}
Aggregations