Search in sources :

Example 1 with UIPropertyConfiguratorDescriptor

use of org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor 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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with UIPropertyConfiguratorDescriptor

use of org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor 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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with UIPropertyConfiguratorDescriptor

use of org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor 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);
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) GridLayout(org.eclipse.swt.layout.GridLayout) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 4 with UIPropertyConfiguratorDescriptor

use of org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor in project dbeaver by dbeaver.

the class ConnectionPageNetwork method createHandlerTab.

private void createHandlerTab(final NetworkHandlerDescriptor descriptor) throws DBException {
    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;
    }
    TabItem tabItem = new TabItem(handlersFolder, SWT.NONE);
    tabItem.setText(descriptor.getLabel());
    tabItem.setToolTipText(descriptor.getDescription());
    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) {
            HandlerBlock handlerBlock = configurations.get(descriptor);
            DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(wizard.getPageSettings().getActiveDataSource().getId());
            handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
            enableHandlerContent(descriptor);
        }
    });
    Composite handlerComposite = UIUtils.createComposite(composite, 1);
    configurations.put(descriptor, new HandlerBlock(configurator, handlerComposite, useHandlerCheck, tabItem));
    handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    configurator.createControl(handlerComposite, this::updatePageCompletion);
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 5 with UIPropertyConfiguratorDescriptor

use of org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor 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);
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 GridData (org.eclipse.swt.layout.GridData)8 DBException (org.jkiss.dbeaver.DBException)8 UIPropertyConfiguratorDescriptor (org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor)8 GridLayout (org.eclipse.swt.layout.GridLayout)6 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)6 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 TabItem (org.eclipse.swt.widgets.TabItem)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPAuthModelDescriptor (org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2