use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration 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);
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class ConnectionPageNetworkHandler method enableHandlerContent.
protected void enableHandlerContent() {
DBWHandlerConfiguration profileConfig = activeProfile == null ? null : activeProfile.getConfiguration(handlerDescriptor);
boolean hasProfileConfig = profileConfig != null && profileConfig.isEnabled();
if (handlerConfiguration.isEnabled() && !hasProfileConfig) {
if (blockEnableState != null) {
blockEnableState.restore();
blockEnableState = null;
}
} else if (blockEnableState == null) {
blockEnableState = ControlEnableState.disable(handlerComposite);
}
useHandlerCheck.setEnabled(!hasProfileConfig);
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class PrefPageProjectNetworkProfiles method createHandlerTab.
private void createHandlerTab(final NetworkHandlerDescriptor descriptor) {
IObjectPropertyConfigurator<DBWHandlerConfiguration> configurator;
try {
String implName = descriptor.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 '" + descriptor.getId() + "'", e);
return;
}
allHandlers.add(descriptor);
TabItem tabItem = new TabItem(handlersFolder, SWT.NONE);
tabItem.setText(descriptor.getLabel());
tabItem.setToolTipText(descriptor.getDescription());
tabItem.setData(descriptor);
Composite composite = new Composite(handlersFolder, SWT.NONE);
tabItem.setControl(composite);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
final Button useHandlerCheck = UIUtils.createCheckbox(composite, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, descriptor.getLabel()), false);
useHandlerCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (selectedProfile == null) {
useHandlerCheck.setSelection(false);
UIUtils.showMessageBox(getShell(), "No profile", "Select existing profile or create a new one", SWT.ICON_INFORMATION);
return;
}
HandlerBlock handlerBlock = configurations.get(descriptor);
DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(descriptor, null);
handlerBlock.loadedConfigs.put(selectedProfile, handlerConfiguration);
}
handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
enableHandlerContent(descriptor);
}
});
Composite handlerComposite = UIUtils.createPlaceholder(composite, 1);
configurations.put(descriptor, new HandlerBlock(configurator, handlerComposite, useHandlerCheck));
handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
configurator.createControl(handlerComposite, this::updateApplyButton);
enableHandlerContent(descriptor);
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class PrefPageProjectNetworkProfiles method enableHandlerContent.
private void enableHandlerContent(NetworkHandlerDescriptor descriptor) {
HandlerBlock handlerBlock = configurations.get(descriptor);
DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
handlerBlock.useHandlerCheck.setSelection(handlerConfiguration != null && handlerConfiguration.isEnabled());
if (handlerConfiguration != null && handlerConfiguration.isEnabled()) {
if (handlerBlock.blockEnableState != null) {
handlerBlock.blockEnableState.restore();
handlerBlock.blockEnableState = null;
}
} else if (handlerBlock.blockEnableState == null) {
handlerBlock.blockEnableState = ControlEnableState.disable(handlerBlock.blockControl);
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class ConnectionPageNetwork method saveSettings.
@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
boolean foundHandlers = false;
java.util.List<DBWHandlerConfiguration> handlers = new ArrayList<>();
for (HandlerBlock handlerBlock : configurations.values()) {
DBWHandlerConfiguration configuration = handlerBlock.loadedConfigs.get(dataSource.getId());
if (configuration != null) {
foundHandlers = true;
handlerBlock.configurator.saveSettings(configuration);
handlers.add(configuration);
}
}
if (foundHandlers) {
dataSource.getConnectionConfiguration().setHandlers(handlers);
}
}
Aggregations