Search in sources :

Example 1 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by serge-rider.

the class DataTypeProviderRegistry method findTransformers.

@Override
public List<AttributeTransformerDescriptor> findTransformers(DBPDataSource dataSource, DBSTypedObject typedObject, Boolean custom) {
    DBPDriver driver = dataSource.getContainer().getDriver();
    if (!(driver instanceof DriverDescriptor)) {
        log.warn("Bad datasource specified (driver is not recognized by registry) - " + dataSource);
        return null;
    }
    DataSourceProviderDescriptor dsProvider = ((DriverDescriptor) driver).getProviderDescriptor();
    // Find in default providers
    List<AttributeTransformerDescriptor> result = null;
    for (AttributeTransformerDescriptor descriptor : dataTypeTransformers) {
        if ((custom == null || custom == descriptor.isCustom()) && ((!descriptor.isGlobal() && descriptor.supportsDataSource(dataSource, dsProvider) && descriptor.supportsType(typedObject)) || (descriptor.isGlobal() && descriptor.supportsType(typedObject)))) {
            if (result == null) {
                result = new ArrayList<>();
            }
            result.add(descriptor);
        }
    }
    return result;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) DBDAttributeTransformerDescriptor(org.jkiss.dbeaver.model.data.DBDAttributeTransformerDescriptor)

Example 2 with DataSourceProviderDescriptor

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

the class SQLContextTypeRegistry method loadContextTypes.

private void loadContextTypes() {
    addContextType(new SQLContextTypeBase());
    for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getDataSourceProviders()) {
        if (!provider.isDriversManagable()) {
            SQLContextTypeProvider contextType = new SQLContextTypeProvider(provider);
            addContextType(contextType);
            provider.loadTemplateVariableResolvers(contextType);
        } else {
            Set<String> categoriesAdded = new HashSet<>();
            for (DriverDescriptor driver : provider.getEnabledDrivers()) {
                if (!CommonUtils.isEmpty(driver.getCategory())) {
                    if (categoriesAdded.contains(driver.getCategory())) {
                        continue;
                    }
                    categoriesAdded.add(driver.getCategory());
                }
                SQLContextTypeDriver contextType = new SQLContextTypeDriver(driver);
                addContextType(contextType);
                provider.loadTemplateVariableResolvers(contextType);
            }
        }
    }
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) HashSet(java.util.HashSet)

Example 3 with DataSourceProviderDescriptor

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

the class NewConnectionWizard method addPages.

/**
 * Adding the page to the wizard.
 */
@Override
public void addPages() {
    pageDrivers = new ConnectionPageDriver(this);
    addPage(pageDrivers);
    for (DataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders()) {
        availableProvides.add(provider);
        DataSourceViewDescriptor view = provider.getView(IActionConstants.NEW_CONNECTION_POINT);
        if (view != null) {
            ConnectionPageSettings pageSettings = new ConnectionPageSettings(NewConnectionWizard.this, view);
            settingsPages.put(provider, pageSettings);
            addPage(pageSettings);
        }
    }
    pageGeneral = new ConnectionPageGeneral(this);
    pageNetwork = new ConnectionPageNetwork(this);
    addPage(pageGeneral);
    addPage(pageNetwork);
    // Initial settings
    if (selection != null && !selection.isEmpty()) {
        final Object element = selection.getFirstElement();
        if (element instanceof DBNLocalFolder) {
            pageGeneral.setDataSourceFolder(((DBNLocalFolder) element).getFolder());
        }
    }
}
Also used : DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) DataSourceViewDescriptor(org.jkiss.dbeaver.registry.DataSourceViewDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 4 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by serge-rider.

the class WorkbenchInitializerCreateSampleDatabase method createSampleDatabase.

static void createSampleDatabase(DBPDataSourceRegistry dsRegistry) {
    DataSourceDescriptor dataSource = (DataSourceDescriptor) dsRegistry.getDataSource(SAMPLE_DB1_ID);
    if (dataSource != null) {
        return;
    }
    DataSourceProviderDescriptor genericDSProvider = DataSourceProviderRegistry.getInstance().getDataSourceProvider("generic");
    if (genericDSProvider == null) {
        log.error("Can't find generic data source provider");
        return;
    }
    DriverDescriptor sqliteDriver = genericDSProvider.getDriver("sqlite_jdbc");
    if (sqliteDriver == null) {
        log.error("Can't find SQLite driver is generic provider");
        return;
    }
    // Extract bundled database to workspace metadata
    File dbFolder = new File(GeneralUtils.getMetadataFolder(), SAMPLE_DB1_FOLDER);
    if (!dbFolder.exists()) {
        if (!dbFolder.mkdirs()) {
            log.error("Can't create target database folder " + dbFolder.getAbsolutePath());
            return;
        }
    }
    File dbFile = new File(dbFolder, SAMPLE_DB_FILE_NAME);
    try (InputStream is = WorkbenchInitializerCreateSampleDatabase.class.getClassLoader().getResourceAsStream(SAMPLE_DB_SOURCE_PATH)) {
        try (OutputStream os = new FileOutputStream(dbFile)) {
            IOUtils.copyStream(is, os);
        }
    } catch (IOException e) {
        log.error("Error extracting sample database to workspace", e);
        return;
    }
    DBPConnectionConfiguration connectionInfo = new DBPConnectionConfiguration();
    connectionInfo.setDatabaseName(dbFile.getAbsolutePath());
    connectionInfo.setConnectionType(DBPConnectionType.DEV);
    connectionInfo.setUrl(genericDSProvider.getInstance(sqliteDriver).getConnectionURL(sqliteDriver, connectionInfo));
    dataSource = new DataSourceDescriptor(dsRegistry, SAMPLE_DB1_ID, sqliteDriver, connectionInfo);
    dataSource.setSavePassword(true);
    dataSource.getNavigatorSettings().setShowSystemObjects(true);
    dataSource.setName("DBeaver Sample Database (SQLite)");
    dsRegistry.addDataSource(dataSource);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 5 with DataSourceProviderDescriptor

use of org.jkiss.dbeaver.registry.DataSourceProviderDescriptor in project dbeaver by serge-rider.

the class DriverEditDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    if (newDriver) {
        getShell().setText(UIConnectionMessages.dialog_edit_driver_title_create_driver);
    } else {
        // $NON-NLS-2$
        getShell().setText(UIConnectionMessages.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, UIConnectionMessages.dialog_edit_driver_setting, 4, -1, -1);
        propsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        gd = new GridData(GridData.FILL_HORIZONTAL);
        driverNameText = UIUtils.createLabelText(propsGroup, UIConnectionMessages.dialog_edit_driver_label_driver_name, driver.getName(), SWT.BORDER | advStyle, gd);
        driverNameText.setEnabled(driver == null || driver.isCustom());
        driverNameText.addModifyListener(e -> onChangeProperty());
        UIUtils.createControlLabel(propsGroup, UIConnectionMessages.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, UIConnectionMessages.dialog_edit_driver_label_class_name, CommonUtils.notEmpty(driver.getDriverClassName()), SWT.BORDER | advStyle, gd);
        driverClassText.setToolTipText(UIConnectionMessages.dialog_edit_driver_label_class_name_tip);
        driverClassText.addModifyListener(e -> onChangeProperty());
        driverURLText = UIUtils.createLabelText(propsGroup, UIConnectionMessages.dialog_edit_driver_label_sample_url, CommonUtils.notEmpty(driver.getSampleURL()), SWT.BORDER | advStyle, gd);
        driverURLText.setToolTipText(UIConnectionMessages.dialog_edit_driver_label_sample_url_tip);
        driverURLText.addModifyListener(e -> onChangeProperty());
        driverURLText.setEnabled(driver == null || driver.isUseURL());
        driverPortText = UIUtils.createLabelText(propsGroup, UIConnectionMessages.dialog_edit_driver_label_default_port, CommonUtils.notEmpty(driver.getDefaultPort()), SWT.BORDER | advStyle);
        driverPortText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        driverPortText.addModifyListener(e -> onChangeProperty());
        driverDatabaseText = UIUtils.createLabelText(propsGroup, UIConnectionMessages.dialog_edit_driver_label_default_database, CommonUtils.notEmpty(driver.getDefaultDatabase()), SWT.BORDER | advStyle);
        driverDatabaseText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        driverDatabaseText.addModifyListener(e -> onChangeProperty());
        driverUserText = UIUtils.createLabelText(propsGroup, UIConnectionMessages.dialog_edit_driver_label_default_user, CommonUtils.notEmpty(driver.getDefaultUser()), SWT.BORDER | advStyle);
        driverUserText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        driverUserText.addModifyListener(e -> onChangeProperty());
        UIUtils.createEmptyLabel(propsGroup, 2, 1);
        Composite optionsPanel = new Composite(propsGroup, SWT.NONE);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 4;
        optionsPanel.setLayoutData(gd);
        optionsPanel.setLayout(new RowLayout());
        embeddedDriverCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_embedded_label, UIConnectionMessages.dialog_edit_driver_embedded_tip, driver.isEmbedded(), 1);
        anonymousDriverCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_anonymous_label, UIConnectionMessages.dialog_edit_driver_anonymous_tip, driver.isAnonymousAccess(), 1);
        allowsEmptyPasswordCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_allows_empty_password_label, UIConnectionMessages.dialog_edit_driver_allows_empty_password_tip, driver.isAnonymousAccess(), 1);
        nonInstantiableCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_use_legacy_instantiation_label, UIConnectionMessages.dialog_edit_driver_use_legacy_instantiation_tip, !driver.isInstantiable(), 1);
        if (isReadOnly) {
            embeddedDriverCheck.setEnabled(false);
            anonymousDriverCheck.setEnabled(false);
            allowsEmptyPasswordCheck.setEnabled(false);
            nonInstantiableCheck.setEnabled(false);
        }
    }
    {
        Group infoGroup = UIUtils.createControlGroup(group, UIConnectionMessages.dialog_edit_driver_description, 4, -1, -1);
        infoGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        driverCategoryCombo = UIUtils.createLabelCombo(infoGroup, UIConnectionMessages.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 (DBPDriver 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, UIConnectionMessages.dialog_edit_driver_label_id, driver.getId(), SWT.BORDER | SWT.READ_ONLY, gd);
            idText.setToolTipText(UIConnectionMessages.dialog_edit_driver_label_id_tip);
        }
        driverDescText = UIUtils.createLabelText(infoGroup, UIConnectionMessages.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, UIConnectionMessages.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));
        createLibrariesTab(tabFolder);
        createConnectionPropertiesTab(tabFolder);
        createParametersTab(tabFolder);
        // Client homes
        if (driver.getNativeClientManager() != null) {
            createClientHomesTab(tabFolder);
        }
        final String license = driver.getLicense();
        if (license != null) {
            createLicenseTab(tabFolder, license);
        }
        tabFolder.setSelection(0);
    }
    loadSettings(false);
    if (showAddFiles) {
        getShell().getDisplay().asyncExec(this::addLibraryFiles);
    }
    driverNameText.setFocus();
    return group;
}
Also used : java.util(java.util) UIConnectionMessages(org.jkiss.dbeaver.ui.internal.UIConnectionMessages) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) UIMessages(org.jkiss.dbeaver.ui.internal.UIMessages) IStatus(org.eclipse.core.runtime.IStatus) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ConnectionPropertiesControl(org.jkiss.dbeaver.ui.dialogs.connection.ConnectionPropertiesControl) Log(org.jkiss.dbeaver.Log) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) DriverClassFindJob(org.jkiss.dbeaver.registry.driver.DriverClassFindJob) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) GridData(org.eclipse.swt.layout.GridData) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) HelpEnabledDialog(org.jkiss.dbeaver.ui.dialogs.HelpEnabledDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) NLS(org.eclipse.osgi.util.NLS) StandardErrorDialog(org.jkiss.dbeaver.ui.dialogs.StandardErrorDialog) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) org.eclipse.swt.widgets(org.eclipse.swt.widgets) ArrayUtils(org.jkiss.utils.ArrayUtils) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DriverLibraryAbstract(org.jkiss.dbeaver.registry.driver.DriverLibraryAbstract) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) DriverLibraryMavenArtifact(org.jkiss.dbeaver.registry.driver.DriverLibraryMavenArtifact) RowLayout(org.eclipse.swt.layout.RowLayout) List(java.util.List) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBIcon(org.jkiss.dbeaver.model.DBIcon) PropertySourceCustom(org.jkiss.dbeaver.runtime.properties.PropertySourceCustom) DBException(org.jkiss.dbeaver.DBException) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) ClientHomesPanel(org.jkiss.dbeaver.ui.dialogs.connection.ClientHomesPanel) SWT(org.eclipse.swt.SWT) IHelpContextIds(org.jkiss.dbeaver.ui.IHelpContextIds) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) 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