Search in sources :

Example 6 with NetworkHandlerDescriptor

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);
        }
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)

Example 7 with NetworkHandlerDescriptor

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();
}
Also used : DBWNetworkProfile(org.jkiss.dbeaver.model.net.DBWNetworkProfile) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)

Example 8 with NetworkHandlerDescriptor

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;
}
Also used : DBWNetworkProfile(org.jkiss.dbeaver.model.net.DBWNetworkProfile) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) CustomSashForm(org.jkiss.dbeaver.ui.controls.CustomSashForm) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 9 with NetworkHandlerDescriptor

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);
        }
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)

Example 10 with NetworkHandlerDescriptor

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;
    }
}
Also used : IDialogPage(org.eclipse.jface.dialogs.IDialogPage) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor) Nullable(org.jkiss.code.Nullable)

Aggregations

NetworkHandlerDescriptor (org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)14 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)10 Nullable (org.jkiss.code.Nullable)4 DBWNetworkProfile (org.jkiss.dbeaver.model.net.DBWNetworkProfile)4 List (java.util.List)2 IDialogPage (org.eclipse.jface.dialogs.IDialogPage)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 TabItem (org.eclipse.swt.widgets.TabItem)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)2 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)2 NetworkHandlerRegistry (org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry)2 CustomSashForm (org.jkiss.dbeaver.ui.controls.CustomSashForm)2