use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by dbeaver.
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 dbeaver.
the class PrefPageProjectNetworkProfiles method performDefaults.
@Override
protected void performDefaults() {
super.performDefaults();
profilesTable.removeAll();
if (projectMeta != null) {
for (DBWNetworkProfile profile : projectMeta.getDataSourceRegistry().getNetworkProfiles()) {
TableItem item = new TableItem(profilesTable, SWT.NONE);
item.setText(profile.getProfileName());
item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_DOCUMENT));
item.setData(profile);
if (selectedProfile == null) {
selectedProfile = profile;
profilesTable.select(0);
}
for (NetworkHandlerDescriptor nhd : allHandlers) {
HandlerBlock handlerBlock = configurations.get(nhd);
DBWHandlerConfiguration configuration = profile.getConfiguration(nhd);
if (configuration != null) {
handlerBlock.loadedConfigs.put(profile, configuration);
}
}
}
}
updateControlsState();
}
use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by dbeaver.
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 dbeaver.
the class PrefPageProjectNetworkProfiles method updateControlsState.
private void updateControlsState() {
NetworkHandlerDescriptor descriptor = getSelectedHandler();
enableHandlerContent(descriptor);
if (descriptor != null) {
HandlerBlock handlerBlock = configurations.get(descriptor);
DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
if (handlerConfiguration == null) {
handlerBlock.configurator.loadSettings(new DBWHandlerConfiguration(descriptor, null));
} else {
handlerBlock.configurator.loadSettings(handlerConfiguration);
}
}
}
use of org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor in project dbeaver by serge-rider.
the class ConnectionPageSettings method getSubPages.
@Nullable
@Override
public IDialogPage[] getSubPages(boolean extrasOnly, boolean forceCreate) {
if (extrasOnly) {
return extraPages;
}
if (subPages != null) {
return subPages;
}
if (!forceCreate) {
return new IDialogPage[0];
}
if (this.connectionEditor == null) {
this.connectionEditor = viewDescriptor.createView(IDataSourceConnectionEditor.class);
this.connectionEditor.setSite(this);
}
if (connectionEditor instanceof ICompositeDialogPage) {
subPages = ((ICompositeDialogPage) connectionEditor).getSubPages(extrasOnly, true);
if (!ArrayUtils.isEmpty(subPages)) {
for (IDialogPage page : subPages) {
if (page instanceof IDataSourceConnectionEditor) {
((IDataSourceConnectionEditor) page).setSite(this);
}
}
}
if (isNew() || !getDriver().isEmbedded()) {
// Add network tabs (for new connections or non-embedded drivers)
for (NetworkHandlerDescriptor descriptor : NetworkHandlerRegistry.getInstance().getDescriptors(getActiveDataSource())) {
subPages = ArrayUtils.add(IDialogPage.class, subPages, new ConnectionPageNetworkHandler(this, descriptor));
}
}
if (extraPages != null) {
subPages = ArrayUtils.concatArrays(subPages, extraPages);
}
return subPages;
} else {
return extraPages;
}
}
Aggregations