use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by serge-rider.
the class PrefPageProjectNetworkProfiles method createContents.
@Override
protected Control createContents(final Composite parent) {
CustomSashForm divider = UIUtils.createPartDivider(null, parent, SWT.HORIZONTAL);
{
Composite profilesGroup = new Composite(divider, SWT.BORDER);
GridLayout gl = new GridLayout(1, false);
gl.marginWidth = 0;
gl.marginHeight = 0;
profilesGroup.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
profilesGroup.setLayoutData(gd);
{
ToolBar toolbar = new ToolBar(profilesGroup, SWT.HORIZONTAL | SWT.RIGHT);
UIUtils.createToolItem(toolbar, "Create", "Create new profile", UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String profileName = "";
while (true) {
profileName = EnterNameDialog.chooseName(getShell(), "Profile name", profileName);
if (CommonUtils.isEmptyTrimmed(profileName)) {
return;
}
if (projectMeta.getDataSourceRegistry().getNetworkProfile(profileName) != null) {
UIUtils.showMessageBox(getShell(), "Wrong profile name", "Profile '" + profileName + "' already exist in project '" + projectMeta.getName() + "'", SWT.ICON_ERROR);
continue;
}
break;
}
DBWNetworkProfile newProfile = new DBWNetworkProfile();
newProfile.setProfileName(profileName);
projectMeta.getDataSourceRegistry().updateNetworkProfile(newProfile);
projectMeta.getDataSourceRegistry().flushConfig();
TableItem item = new TableItem(profilesTable, SWT.NONE);
item.setText(newProfile.getProfileName());
item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_DOCUMENT));
item.setData(newProfile);
if (profilesTable.getItemCount() == 1) {
selectedProfile = newProfile;
profilesTable.select(0);
updateControlsState();
}
}
});
UIUtils.createToolItem(toolbar, "Delete", "Delete profile", UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (selectedProfile != null) {
List<? extends DBPDataSourceContainer> usedBy = projectMeta.getDataSourceRegistry().getDataSourcesByProfile(selectedProfile);
if (!usedBy.isEmpty()) {
UIUtils.showMessageBox(getShell(), "Can't delete profile", "Configuration profile '" + selectedProfile.getProfileName() + "' used by " + usedBy.size() + " connections:\n" + usedBy, SWT.ICON_ERROR);
return;
}
if (!UIUtils.confirmAction(getShell(), "Delete profile", "Are you sure you want to delete configuration profile '" + selectedProfile.getProfileName() + "'?")) {
return;
}
projectMeta.getDataSourceRegistry().removeNetworkProfile(selectedProfile);
projectMeta.getDataSourceRegistry().flushConfig();
profilesTable.remove(profilesTable.getSelectionIndex());
selectedProfile = null;
updateControlsState();
} else {
UIUtils.showMessageBox(getShell(), "No profile", "Select profile first", SWT.ICON_ERROR);
}
}
});
}
profilesTable = new Table(profilesGroup, SWT.SINGLE);
gd = new GridData(GridData.FILL_BOTH);
gd.minimumWidth = 150;
profilesTable.setLayoutData(gd);
profilesTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
saveHandlerSettings();
TableItem[] selection = profilesTable.getSelection();
if (ArrayUtils.isEmpty(selection)) {
selectedProfile = null;
} else {
selectedProfile = (DBWNetworkProfile) selection[0].getData();
}
updateControlsState();
}
});
}
{
handlersFolder = new TabFolder(divider, SWT.TOP | SWT.FLAT);
handlersFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
for (NetworkHandlerDescriptor nhd : NetworkHandlerRegistry.getInstance().getDescriptors()) {
if (!nhd.hasObjectTypes()) {
createHandlerTab(nhd);
}
}
handlersFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateControlsState();
}
});
}
divider.setWeights(new int[] { 300, 700 });
performDefaults();
return divider;
}
use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by serge-rider.
the class PrefPageProjectNetworkProfiles method saveHandlerSettings.
/**
* Saves state of UI controls to handler configuration
*/
private void saveHandlerSettings() {
if (selectedProfile == null) {
return;
}
for (TabItem handlerTab : handlersFolder.getItems()) {
NetworkHandlerDescriptor handler = (NetworkHandlerDescriptor) handlerTab.getData();
HandlerBlock handlerBlock = configurations.get(handler);
DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
if (handlerBlock.useHandlerCheck.getSelection()) {
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handler, null);
}
handlerConfiguration.setProperties(Collections.emptyMap());
handlerBlock.configurator.saveSettings(handlerConfiguration);
}
}
}
use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by serge-rider.
the class DataSourceSerializerModern method parseNetworkHandlerConfig.
@Nullable
private DBWHandlerConfiguration parseNetworkHandlerConfig(@Nullable DataSourceDescriptor dataSource, @Nullable DBWNetworkProfile profile, @NotNull Map.Entry<String, Map<String, Object>> handlerObject) {
String handlerId = handlerObject.getKey();
Map<String, Object> handlerCfg = handlerObject.getValue();
NetworkHandlerDescriptor handlerDescriptor = NetworkHandlerRegistry.getInstance().getDescriptor(handlerId);
if (handlerDescriptor == null) {
log.warn("Can't find network handler '" + handlerId + "'");
return null;
} else {
DBWHandlerConfiguration curNetworkHandler = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
curNetworkHandler.setEnabled(JSONUtils.getBoolean(handlerCfg, RegistryConstants.ATTR_ENABLED));
curNetworkHandler.setSavePassword(JSONUtils.getBoolean(handlerCfg, RegistryConstants.ATTR_SAVE_PASSWORD));
if (!passwordReadCanceled) {
final SecureCredentials creds = readSecuredCredentials(dataSource, profile, "network/" + handlerId + (profile == null ? "" : "/profile/" + profile.getProfileName()));
curNetworkHandler.setUserName(creds.getUserName());
if (curNetworkHandler.isSavePassword()) {
curNetworkHandler.setPassword(creds.getUserPassword());
}
}
{
// Still try to read credentials directly from configuration (#6564)
String userName = JSONUtils.getString(handlerCfg, RegistryConstants.ATTR_USER);
if (!CommonUtils.isEmpty(userName))
curNetworkHandler.setUserName(userName);
String userPassword = JSONUtils.getString(handlerCfg, RegistryConstants.ATTR_PASSWORD);
if (!CommonUtils.isEmpty(userPassword))
curNetworkHandler.setPassword(userPassword);
}
Map<String, Object> properties = JSONUtils.deserializeProperties(handlerCfg, RegistryConstants.TAG_PROPERTIES);
if (properties != null) {
curNetworkHandler.setProperties(properties);
}
return curNetworkHandler;
}
}
use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by dbeaver.
the class DataSourceSerializerModern method parseNetworkHandlerConfig.
@Nullable
private DBWHandlerConfiguration parseNetworkHandlerConfig(@Nullable DataSourceDescriptor dataSource, @Nullable DBWNetworkProfile profile, @NotNull Map.Entry<String, Map<String, Object>> handlerObject) {
String handlerId = handlerObject.getKey();
Map<String, Object> handlerCfg = handlerObject.getValue();
NetworkHandlerDescriptor handlerDescriptor = NetworkHandlerRegistry.getInstance().getDescriptor(handlerId);
if (handlerDescriptor == null) {
log.warn("Can't find network handler '" + handlerId + "'");
return null;
} else {
DBWHandlerConfiguration curNetworkHandler = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
curNetworkHandler.setEnabled(JSONUtils.getBoolean(handlerCfg, RegistryConstants.ATTR_ENABLED));
curNetworkHandler.setSavePassword(JSONUtils.getBoolean(handlerCfg, RegistryConstants.ATTR_SAVE_PASSWORD));
if (!passwordReadCanceled) {
final SecureCredentials creds = readSecuredCredentials(dataSource, profile, "network/" + handlerId + (profile == null ? "" : "/profile/" + profile.getProfileName()));
curNetworkHandler.setUserName(creds.getUserName());
if (curNetworkHandler.isSavePassword()) {
curNetworkHandler.setPassword(creds.getUserPassword());
}
}
{
// Still try to read credentials directly from configuration (#6564)
String userName = JSONUtils.getString(handlerCfg, RegistryConstants.ATTR_USER);
if (!CommonUtils.isEmpty(userName))
curNetworkHandler.setUserName(userName);
String userPassword = JSONUtils.getString(handlerCfg, RegistryConstants.ATTR_PASSWORD);
if (!CommonUtils.isEmpty(userPassword))
curNetworkHandler.setPassword(userPassword);
}
Map<String, Object> properties = JSONUtils.deserializeProperties(handlerCfg, RegistryConstants.TAG_PROPERTIES);
if (properties != null) {
curNetworkHandler.setProperties(properties);
}
return curNetworkHandler;
}
}
Aggregations