Search in sources :

Example 6 with DataSourceProviderDescriptor

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

the class DriverTreeViewer method initDrivers.

public void initDrivers(List<DBPDataSourceProviderDescriptor> providers, boolean expandRecent) {
    getTree().setHeaderVisible(true);
    this.providers = providers;
    if (this.providers == null) {
        this.providers = DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders();
    }
    TreeColumn nameColumn = new TreeColumn(getTree(), SWT.LEFT);
    nameColumn.setText("Name");
    nameColumn.addListener(SWT.Selection, new DriversSortListener(nameColumn, true));
    TreeColumn usersColumn = new TreeColumn(getTree(), SWT.LEFT);
    usersColumn.setText("#");
    usersColumn.addListener(SWT.Selection, new DriversSortListener(usersColumn, false));
    this.setContentProvider(new ViewContentProvider());
    this.setLabelProvider(new ViewLabelProvider());
    this.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    Collection<Object> drivers = collectDrivers();
    this.setInput(drivers);
    UIUtils.expandAll(this);
    UIUtils.packColumns(getTree(), true, new float[] { 0.9f, 0.1f });
    if (expandRecent) {
        // Expand used driver categories
        for (Object driver : drivers) {
            if (driver instanceof DriverCategory && getConnectionCount(driver) > 0) {
                expandToLevel(driver, ALL_LEVELS);
            } else {
                collapseToLevel(driver, ALL_LEVELS);
            }
        }
    } else {
        this.collapseAll();
    }
    addDoubleClickListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        if (!selection.isEmpty()) {
            Object element = selection.getFirstElement();
            if (element instanceof DriverCategory || element instanceof DataSourceProviderDescriptor) {
                if (Boolean.TRUE.equals(getExpandedState(element))) {
                    super.collapseToLevel(element, 1);
                } else {
                    super.expandToLevel(element, 1);
                }
            }
        }
    });
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 7 with DataSourceProviderDescriptor

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

the class DriverManagerDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    List<DBPDataSourceProviderDescriptor> enabledProviders = DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders();
    {
        DBPDataSourceProviderDescriptor manProvider = null;
        for (DBPDataSourceProviderDescriptor provider : DataSourceProviderRegistry.getInstance().getEnabledDataSourceProviders()) {
            if (provider.isDriversManagable()) {
                if (manProvider != null) {
                    manProvider = null;
                    break;
                }
                manProvider = provider;
            }
        }
        if (manProvider != null) {
            onlyManagableProvider = (DataSourceProviderDescriptor) manProvider;
        }
    }
    getShell().setText(UIConnectionMessages.dialog_driver_manager_title);
    getShell().setMinimumSize(300, 300);
    dialogImage = DBeaverIcons.getImageDescriptor(UIIcon.DRIVER_MANAGER);
    getShell().setImage(dialogImage.createImage());
    Composite group = UIUtils.createPlaceholder((Composite) super.createDialogArea(parent), 2);
    group.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        treeControl = new DriverSelectViewer(group, this, enabledProviders, false, true);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        gd.widthHint = 300;
        treeControl.getControl().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, UIConnectionMessages.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, UIConnectionMessages.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, UIConnectionMessages.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, UIConnectionMessages.dialog_driver_manager_button_delete, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                deleteDriver();
            }
        });
        deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        Button unDeleteButton = UIUtils.createPushButton(buttonBar, "Un-delete", null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (undeleteDrivers()) {
                    treeControl.refresh();
                }
            }
        });
        unDeleteButton.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, UIConnectionMessages.dialog_driver_manager_label_user_defined);
            UIUtils.createLabel(legend, DBIcon.OVER_ERROR);
            UIUtils.createLabel(legend, UIConnectionMessages.dialog_driver_manager_label_unavailable);
        }
        if (SHOW_EXPORT) {
            UIUtils.createPushButton(buttonBar, "Export", null, new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    exportDriverList();
                }
            });
        }
    }
    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) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Example 8 with DataSourceProviderDescriptor

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

the class ConfigImportWizard method findOrCreateDriver.

private boolean findOrCreateDriver(ImportConnectionInfo connectionInfo) throws DBException {
    final ImportDriverInfo driverInfo = connectionInfo.getDriverInfo();
    if (CommonUtils.isEmpty(driverInfo.getDriverClass())) {
        throw new DBException("Cannot create driver '" + driverInfo.getName() + "' - no driver class specified");
    }
    String sampleURL = driverInfo.getSampleURL();
    if (CommonUtils.isEmpty(sampleURL)) {
        throw new DBException("Cannot create driver '" + driverInfo.getName() + "' - no connection URL pattern specified");
    }
    {
        DriverDescriptor driver = driverClassMap.get(driverInfo.getDriverClass());
        if (driver != null) {
            connectionInfo.setDriver(driver);
            return true;
        }
    }
    final DataSourceProviderRegistry registry = DataSourceProviderRegistry.getInstance();
    List<DriverDescriptor> matchedDrivers = new ArrayList<>();
    for (DataSourceProviderDescriptor dataSourceProvider : registry.getDataSourceProviders()) {
        for (DriverDescriptor driver : dataSourceProvider.getEnabledDrivers()) {
            final String driverClassName = driver.getDriverClassName();
            if (driverClassName != null && driverClassName.equals(driverInfo.getDriverClass())) {
                matchedDrivers.add(driver);
            }
        }
    }
    DriverDescriptor driver;
    if (matchedDrivers.isEmpty()) {
        // Create new driver
        final DataSourceProviderDescriptor genericProvider = registry.getDataSourceProvider("generic");
        if (genericProvider == null) {
            throw new DBException("Generic datasource provider not found");
        }
        driver = genericProvider.createDriver();
        driver.setName(driverInfo.getName());
        driver.setDriverClassName(driverInfo.getDriverClass());
        driver.setSampleURL(driverInfo.getSampleURL());
        driver.setConnectionProperties(driverInfo.getProperties());
        driver.setDescription(driverInfo.getDescription());
        driver.setDriverDefaultPort(driverInfo.getDefaultPort());
        driver.setDriverDefaultDatabase(driverInfo.getDefaultDatabase());
        driver.setDriverDefaultServer(driverInfo.getDefaultServer());
        driver.setDriverDefaultUser(driverInfo.getDefaultUser());
        for (String path : driverInfo.getLibraries()) {
            driver.addDriverLibrary(path, DBPDriverLibrary.FileType.jar);
        }
        driver.setModified(true);
        genericProvider.addDriver(driver);
        connectionInfo.setDriver(driver);
    } else if (matchedDrivers.size() == 1) {
        // Use the only found driver
        driver = matchedDrivers.get(0);
        connectionInfo.setDriver(driver);
    } else {
        // Let user to choose correct driver
        driver = ObjectListDialog.selectObject(getShell(), "Choose driver for connection '" + connectionInfo.getAlias() + "'", "ImportDriverSelector", matchedDrivers);
        if (driver == null) {
            return false;
        }
        connectionInfo.setDriver(driver);
    }
    if (driver != null) {
        driverClassMap.put(driver.getDriverClassName(), driver);
        return true;
    }
    return false;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) ArrayList(java.util.ArrayList) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor)

Example 9 with DataSourceProviderDescriptor

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

the class DataTypeProviderRegistry method getDataTypeProvider.

////////////////////////////////////////////////////
// DataType providers
@Nullable
public DBDValueHandlerProvider getDataTypeProvider(@NotNull DBPDataSource dataSource, @NotNull DBSTypedObject typedObject) {
    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();
    // First try to find type provider for specific datasource type
    for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
        if (!dtProvider.isGlobal() && dtProvider.supportsDataSource(dataSource, dsProvider) && dtProvider.supportsType(typedObject)) {
            return dtProvider.getInstance();
        }
    }
    // Find in global providers
    for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
        if (dtProvider.isGlobal() && dtProvider.supportsType(typedObject)) {
            return dtProvider.getInstance();
        }
    }
    return null;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) Nullable(org.jkiss.code.Nullable)

Example 10 with DataSourceProviderDescriptor

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

the class WorkbenchInitializerCreateSampleDatabase method createSampleDatabase.

private void createSampleDatabase(IProject project) {
    DataSourceRegistry dsRegistry = DBeaverCore.getInstance().getProjectRegistry().getDataSourceRegistry(project);
    DataSourceDescriptor dataSource = 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 = this.getClass().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.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) DataSourceRegistry(org.jkiss.dbeaver.registry.DataSourceRegistry) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

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