Search in sources :

Example 11 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by dbeaver.

the class DriverEditDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    if (newDriver) {
        getShell().setText(CoreMessages.dialog_edit_driver_title_create_driver);
    } else {
        // $NON-NLS-2$
        getShell().setText(CoreMessages.dialog_edit_driver_title_edit_driver + driver.getName() + "'");
        getShell().setImage(DBeaverIcons.getImage(driver.getPlainIcon()));
    }
    boolean isReadOnly = !provider.isDriversManagable();
    int advStyle = isReadOnly ? SWT.READ_ONLY : SWT.NONE;
    final Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 500;
    group.setLayoutData(gd);
    {
        Group propsGroup = UIUtils.createControlGroup(group, CoreMessages.dialog_edit_driver_setting, 4, -1, -1);
        propsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        gd = new GridData(GridData.FILL_HORIZONTAL);
        driverNameText = UIUtils.createLabelText(propsGroup, CoreMessages.dialog_edit_driver_label_driver_name + "*", driver.getName(), SWT.BORDER | advStyle, gd);
        driverNameText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                onChangeProperty();
            }
        });
        UIUtils.createControlLabel(propsGroup, CoreMessages.dialog_edit_driver_type_label);
        final CSmartCombo<DataSourceProviderDescriptor> providerCombo = new CSmartCombo<>(propsGroup, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, new LabelProvider() {

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(((DataSourceProviderDescriptor) element).getIcon());
            }

            @Override
            public String getText(Object element) {
                return ((DataSourceProviderDescriptor) element).getName();
            }
        });
        providerCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        if (newDriver) {
            for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getDataSourceProviders()) {
                if (provider.isDriversManagable()) {
                    providerCombo.addItem(provider);
                }
            }
            providerCombo.select(provider);
            providerCombo.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    provider = providerCombo.getItem(providerCombo.getSelectionIndex());
                    driver = provider.createDriver();
                }
            });
        } else {
            providerCombo.addItem(provider);
            providerCombo.select(provider);
        }
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 3;
        driverClassText = UIUtils.createLabelText(propsGroup, CoreMessages.dialog_edit_driver_label_class_name + "*", CommonUtils.notEmpty(driver.getDriverClassName()), SWT.BORDER | advStyle, gd);
        driverClassText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                onChangeProperty();
            }
        });
        driverURLText = UIUtils.createLabelText(propsGroup, CoreMessages.dialog_edit_driver_label_sample_url, CommonUtils.notEmpty(driver.getSampleURL()), SWT.BORDER | advStyle, gd);
        driverURLText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                onChangeProperty();
            }
        });
        gd = new GridData(GridData.FILL_HORIZONTAL);
        driverPortText = UIUtils.createLabelText(propsGroup, CoreMessages.dialog_edit_driver_label_default_port, driver.getDefaultPort() == null ? "" : driver.getDefaultPort(), SWT.BORDER | advStyle, gd);
        driverPortText.setLayoutData(new GridData(SWT.NONE));
        driverPortText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                onChangeProperty();
            }
        });
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        embeddedDriverCheck = UIUtils.createCheckbox(propsGroup, CoreMessages.dialog_edit_driver_embedded_label, driver.isEmbedded());
        embeddedDriverCheck.setLayoutData(gd);
    }
    {
        Group infoGroup = UIUtils.createControlGroup(group, CoreMessages.dialog_edit_driver_description, 4, -1, -1);
        infoGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        driverCategoryCombo = UIUtils.createLabelCombo(infoGroup, CoreMessages.dialog_edit_driver_label_category, SWT.BORDER | SWT.DROP_DOWN | advStyle);
        driverCategoryCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        if (isReadOnly) {
            driverCategoryCombo.setEnabled(false);
        }
        Set<String> categories = new TreeSet<>();
        for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getDataSourceProviders()) {
            for (DriverDescriptor drv : provider.getEnabledDrivers()) {
                if (!CommonUtils.isEmpty(drv.getCategory())) {
                    categories.add(drv.getCategory());
                }
            }
        }
        for (String category : categories) {
            driverCategoryCombo.add(category);
        }
        if (!CommonUtils.isEmpty(driver.getCategory())) {
            driverCategoryCombo.setText(driver.getCategory());
        } else if (!CommonUtils.isEmpty(defaultCategory)) {
            driverCategoryCombo.setText(defaultCategory);
        }
        {
            gd = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
            Text idText = UIUtils.createLabelText(infoGroup, "ID", driver.getId(), SWT.BORDER | SWT.READ_ONLY, gd);
            idText.setToolTipText("Internal driver ID.\nCan be used in connections configurations and CLI commands.");
        }
        driverDescText = UIUtils.createLabelText(infoGroup, CoreMessages.dialog_edit_driver_label_description, CommonUtils.notEmpty(driver.getDescription()), SWT.BORDER | advStyle);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 3;
        driverDescText.setLayoutData(gd);
        if (!CommonUtils.isEmpty(driver.getWebURL())) {
            UIUtils.createControlLabel(infoGroup, CoreMessages.dialog_edit_driver_label_website);
            Link urlLabel = UIUtils.createLink(infoGroup, "<a>" + driver.getWebURL() + "</a>", new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    UIUtils.launchProgram(driver.getWebURL());
                }
            });
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 3;
            driverDescText.setLayoutData(gd);
            urlLabel.setLayoutData(gd);
        }
    }
    {
        TabFolder tabFolder = new TabFolder(group, SWT.NONE);
        tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
        if (provider.isDriversManagable()) {
            createLibrariesTab(tabFolder);
        }
        createConnectionPropertiesTab(tabFolder);
        createParametersTab(tabFolder);
        // Client homes
        if (driver.getClientManager() != null) {
            createClientHomesTab(tabFolder);
        }
        final String license = driver.getLicense();
        if (license != null) {
            createLicenseTab(tabFolder, license);
        }
        tabFolder.setSelection(0);
    }
    loadSettings(false);
    if (showAddFiles) {
        getShell().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                addLibraryFiles();
            }
        });
    }
    driverNameText.setFocus();
    return group;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 12 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by dbeaver.

the class DriverManagerDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    List<DataSourceProviderDescriptor> enabledProviders = DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders();
    {
        DataSourceProviderDescriptor manProvider = null;
        for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders()) {
            if (provider.isDriversManagable()) {
                if (manProvider != null) {
                    manProvider = null;
                    break;
                }
                manProvider = provider;
            }
        }
        if (manProvider != null) {
            onlyManagableProvider = manProvider;
        }
    }
    getShell().setText(CoreMessages.dialog_driver_manager_title);
    getShell().setMinimumSize(300, 300);
    // $NON-NLS-1$
    dialogImage = DBeaverActivator.getImageDescriptor("/icons/driver_manager.png").createImage();
    getShell().setImage(dialogImage);
    Composite group = UIUtils.createPlaceholder((Composite) super.createDialogArea(parent), 2);
    group.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        treeControl = new DriverTreeControl(group, this, enabledProviders, false);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        gd.widthHint = 300;
        treeControl.setLayoutData(gd);
    }
    {
        Composite buttonBar = new Composite(group, SWT.TOP);
        buttonBar.setLayout(new GridLayout(1, false));
        GridData gd = new GridData(GridData.FILL_VERTICAL);
        buttonBar.setLayoutData(gd);
        newButton = UIUtils.createPushButton(buttonBar, CoreMessages.dialog_driver_manager_button_new, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                createDriver();
            }
        });
        newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        copyButton = UIUtils.createPushButton(buttonBar, CoreMessages.dialog_driver_manager_button_copy, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                copyDriver();
            }
        });
        copyButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editButton = UIUtils.createPushButton(buttonBar, CoreMessages.dialog_driver_manager_button_edit, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                editDriver();
            }
        });
        editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        deleteButton = UIUtils.createPushButton(buttonBar, CoreMessages.dialog_driver_manager_button_delete, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                deleteDriver();
            }
        });
        deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        {
            final Composite legend = UIUtils.createPlaceholder(buttonBar, 2, 5);
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.verticalIndent = 5;
            gd.horizontalSpan = 2;
            legend.setLayoutData(gd);
            UIUtils.createLabel(legend, DBIcon.OVER_LAMP);
            UIUtils.createLabel(legend, CoreMessages.dialog_driver_manager_label_user_defined);
            UIUtils.createLabel(legend, DBIcon.OVER_ERROR);
            UIUtils.createLabel(legend, CoreMessages.dialog_driver_manager_label_unavailable);
        }
    }
    descText = new Text(group, SWT.READ_ONLY);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.verticalIndent = 5;
    gd.horizontalSpan = 2;
    gd.grabExcessHorizontalSpace = true;
    descText.setLayoutData(gd);
    /*
        monitorPart = new ProgressMonitorPart(group, null, true);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.verticalIndent = 5;
        gd.horizontalSpan = 2;
        gd.grabExcessHorizontalSpace = true;
        monitorPart.setLayoutData(gd);
        monitorPart.setVisible(false);
*/
    setDefaultSelection();
    this.updateButtons();
    return group;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 13 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by dbeaver.

the class DriverManagerDialog method createDriver.

private void createDriver() {
    if (onlyManagableProvider != null || selectedProvider != null) {
        DataSourceProviderDescriptor provider = selectedProvider;
        if (provider == null || !provider.isDriversManagable()) {
            provider = onlyManagableProvider;
        }
        DriverEditDialog dialog = new DriverEditDialog(getShell(), provider, selectedCategory);
        if (dialog.open() == IDialogConstants.OK_ID) {
            treeControl.getViewer().refresh();
            treeControl.getViewer().setSelection(new StructuredSelection(dialog.getDriver()));
        }
    }
}
Also used : DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 14 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by dbeaver.

the class DriverTreeViewer method collectDrivers.

private Collection<Object> collectDrivers() {
    for (DriverCategory category : categories.values()) {
        category.drivers.clear();
    }
    driverList.clear();
    for (DataSourceProviderDescriptor provider : providers) {
        List<DriverDescriptor> drivers = provider.getEnabledDrivers();
        for (DriverDescriptor driver : drivers) {
            String category = driver.getCategory();
            if (CommonUtils.isEmpty(category)) {
                driverList.add(driver);
            } else {
                DriverCategory driverCategory = categories.get(category);
                if (driverCategory == null) {
                    driverCategory = new DriverCategory(category);
                    categories.put(category, driverCategory);
                }
                if (!driverList.contains(driverCategory)) {
                    driverList.add(driverCategory);
                }
                driverCategory.drivers.add(driver);
            }
        }
    }
    Collections.sort(driverList, (o1, o2) -> {
        int count1 = getConnectionCount(o1);
        int count2 = getConnectionCount(o2);
        if (sortByName || count1 == count2) {
            String name1 = o1 instanceof DriverDescriptor ? ((DriverDescriptor) o1).getName() : ((DriverCategory) o1).getName();
            String name2 = o2 instanceof DriverDescriptor ? ((DriverDescriptor) o2).getName() : ((DriverCategory) o2).getName();
            return name1.compareToIgnoreCase(name2);
        } else {
            return count2 - count1;
        }
    });
    for (DriverCategory category : categories.values()) {
        category.drivers.sort((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    }
    return driverList;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 15 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by dbeaver.

the class SQLTemplateStore method readContributedTemplates.

private Collection<TemplatePersistenceData> readContributedTemplates() throws IOException {
    Collection<TemplatePersistenceData> templates = new ArrayList<>();
    readIncludedTemplates(DBeaverCore.PLUGIN_ID, templates, "templates/default-templates.xml", "$nl$/templates/default-templates.properties");
    // Read templates for DS providers
    for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getDataSourceProviders()) {
        readIncludedTemplates(provider.getPluginId(), templates, "templates/" + provider.getId() + "-templates.xml", "$nl$/templates/" + provider.getId() + "-templates.properties");
    }
    return templates;
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ArrayList(java.util.ArrayList) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Aggregations

DataSourceProviderDescriptor (org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)18 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)10 GridData (org.eclipse.swt.layout.GridData)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 DBPDataSourceProviderDescriptor (org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)4 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)4 ArrayList (java.util.ArrayList)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DBException (org.jkiss.dbeaver.DBException)3 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)2 DataSourceProviderRegistry (org.jkiss.dbeaver.registry.DataSourceProviderRegistry)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 java.util (java.util)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1