Search in sources :

Example 11 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverClassFindJob method findDriverClasses.

private void findDriverClasses(IProgressMonitor monitor) {
    java.util.List<File> libFiles = new ArrayList<>();
    java.util.List<URL> libURLs = new ArrayList<>();
    for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
        File libFile = lib.getLocalFile();
        if (libFile != null && libFile.exists() && !libFile.isDirectory() && lib.getType() == DBPDriverLibrary.FileType.jar) {
            libFiles.add(libFile);
            try {
                libURLs.add(libFile.toURI().toURL());
            } catch (MalformedURLException e) {
                log.debug(e);
            }
        } else {
            final Collection<DriverDescriptor.DriverFileInfo> files = driver.getLibraryFiles(lib);
            if (files != null) {
                for (DriverDescriptor.DriverFileInfo file : files) {
                    if (file.getFile() != null && file.getFile().exists()) {
                        libFiles.add(file.getFile());
                    }
                }
            }
        }
    }
    ClassLoader findCL = new URLClassLoader(libURLs.toArray(new URL[libURLs.size()]));
    for (File libFile : libFiles) {
        if (monitor.isCanceled()) {
            break;
        }
        findDriverClasses(monitor, findCL, libFile);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) URL(java.net.URL) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 12 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverDependencies method resolveDependencies.

private void resolveDependencies(DBRProgressMonitor monitor, DependencyNode ownerNode, Map<String, DependencyNode> libMap) throws IOException {
    Collection<? extends DBPDriverLibrary> dependencies = ownerNode.library.getDependencies(monitor);
    if (dependencies != null && !dependencies.isEmpty()) {
        for (DBPDriverLibrary dep : dependencies) {
            DependencyNode node = new DependencyNode(ownerNode, dep);
            DependencyNode prevNode = libMap.get(node.library.getId());
            if (prevNode == null || prevNode.depth > node.depth) {
                // if (node.library.isDownloadable()) {
                libMap.put(node.library.getId(), node);
                // }
                if (prevNode != null) {
                    prevNode.duplicate = true;
                }
            } else {
                node.duplicate = true;
            }
            ownerNode.dependencies.add(node);
        }
        for (DependencyNode node : ownerNode.dependencies) {
            if (!node.duplicate) {
                resolveDependencies(monitor, node, libMap);
            }
        }
    }
}
Also used : DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary)

Example 13 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverEditDialog method createLibrariesTab.

private void createLibrariesTab(TabFolder group) {
    GridData gd;
    Composite libsGroup = new Composite(group, SWT.NONE);
    libsGroup.setLayout(new GridLayout(2, false));
    {
        Composite libsListGroup = new Composite(libsGroup, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        libsListGroup.setLayoutData(gd);
        GridLayout layout = new GridLayout(1, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        libsListGroup.setLayout(layout);
        // Additional libraries list
        libTable = new TreeViewer(libsListGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
        libTable.setContentProvider(new LibContentProvider());
        libTable.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                final Object element = cell.getElement();
                if (element instanceof DBPDriverLibrary) {
                    DBPDriverLibrary lib = (DBPDriverLibrary) element;
                    String displayName = lib.getDisplayName();
                    if (lib.getPreferredVersion() != null) {
                        displayName += " [" + lib.getPreferredVersion() + "]";
                    }
                    cell.setText(displayName);
                    File localFile = lib.getLocalFile();
                    if (localFile != null && !localFile.exists()) {
                        cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
                    } else if (!driver.isLibraryResolved(lib)) {
                        cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
                    } else {
                        cell.setForeground(null);
                    }
                    cell.setImage(DBeaverIcons.getImage(lib.getIcon()));
                } else {
                    cell.setText(element.toString());
                    cell.setImage(DBeaverIcons.getImage(UIIcon.JAR));
                }
            }
        });
        libTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
        libTable.getControl().addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                changeLibSelection();
            }
        });
        // Find driver class
        boolean isReadOnly = !provider.isDriversManagable();
        Composite findClassGroup = new Composite(libsListGroup, SWT.TOP);
        findClassGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        layout = new GridLayout(3, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        findClassGroup.setLayout(layout);
        UIUtils.createControlLabel(findClassGroup, CoreMessages.dialog_edit_driver_label_driver_class);
        classListCombo = new Combo(findClassGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
        classListCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        classListCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selIndex = classListCombo.getSelectionIndex();
                if (selIndex >= 0) {
                    driverClassText.setText(classListCombo.getItem(selIndex));
                }
            }
        });
        classListCombo.setEnabled(!isReadOnly);
        findClassButton = new Button(findClassGroup, SWT.PUSH);
        findClassButton.setText(CoreMessages.dialog_edit_driver_button_bind_class);
        findClassButton.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    DriverClassFindJob classFinder = new DriverClassFindJob(driver, "java/sql/Driver", true);
                    new ProgressMonitorDialog(getShell()).run(true, true, classFinder);
                    if (classListCombo != null && !classListCombo.isDisposed()) {
                        java.util.List<String> classNames = classFinder.getDriverClassNames();
                        classListCombo.setItems(classNames.toArray(new String[classNames.size()]));
                        classListCombo.setListVisible(true);
                    }
                } catch (InvocationTargetException e) {
                    log.error(e.getTargetException());
                } catch (InterruptedException e) {
                    log.error(e);
                }
            }
        });
        findClassButton.setEnabled(!isReadOnly);
    }
    Composite libsControlGroup = new Composite(libsGroup, SWT.TOP);
    libsControlGroup.setLayout(new GridLayout(1, true));
    libsControlGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_add_file, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addLibraryFiles();
        }
    });
    UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_add_folder, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addLibraryFolder();
        }
    });
    UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_add_artifact, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addMavenArtifact();
        }
    });
    updateVersionButton = UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_update_version, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            driver.updateFiles();
            changeLibContent();
        }
    });
    detailsButton = UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_details, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            new DriverLibraryDetailsDialog(getShell(), driver, getSelectedLibrary()).open();
        }
    });
    detailsButton.setEnabled(false);
    deleteButton = UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_delete, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) libTable.getSelection();
            if (selection != null && !selection.isEmpty()) {
                if (UIUtils.confirmAction(getShell(), "Delete library", "Are you sure you want to delete selected libraries?")) {
                    for (Object obj : selection.toArray()) {
                        if (obj instanceof DriverLibraryAbstract) {
                            driver.removeDriverLibrary((DriverLibraryAbstract) obj);
                        }
                    }
                }
            }
            changeLibContent();
        }
    });
    deleteButton.setEnabled(false);
    /*
        upButton = UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_up, new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                DriverLibraryAbstract selectedLib = getSelectedLibrary();
                int selIndex = libList.indexOf(selectedLib);
                Collections.swap(libList, selIndex, selIndex - 1);
                changeLibContent();
                changeLibSelection();
            }
        });
        upButton.setEnabled(false);

        downButton = UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_down, new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                DriverLibraryAbstract selectedLib = getSelectedLibrary();
                int selIndex = libList.indexOf(selectedLib);
                Collections.swap(libList, selIndex, selIndex + 1);
                changeLibContent();
                changeLibSelection();
            }
        });
        downButton.setEnabled(false);
*/
    UIUtils.createHorizontalLine(libsControlGroup);
    UIUtils.createToolButton(libsControlGroup, CoreMessages.dialog_edit_driver_button_classpath, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ViewClasspathDialog cpDialog = new ViewClasspathDialog(getShell());
            cpDialog.open();
        }
    });
    changeLibContent();
    TabItem libsTab = new TabItem(group, SWT.NONE);
    libsTab.setText(CoreMessages.dialog_edit_driver_tab_name_driver_libraries);
    libsTab.setToolTipText(CoreMessages.dialog_edit_driver_tab_tooltip_driver_libraries);
    libsTab.setControl(libsGroup);
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) DriverClassFindJob(org.jkiss.dbeaver.registry.driver.DriverClassFindJob) DriverLibraryAbstract(org.jkiss.dbeaver.registry.driver.DriverLibraryAbstract) GridLayout(org.eclipse.swt.layout.GridLayout) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) java.util(java.util) GridData(org.eclipse.swt.layout.GridData) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) File(java.io.File)

Example 14 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverEditDialog method resetLibraries.

private void resetLibraries(boolean original) {
    // Set libraries
    Collection<DBPDriverLibrary> newLibList = CommonUtils.copyList(original ? driver.getOrigFiles() : origLibList);
    for (DBPDriverLibrary lib : newLibList) {
        lib.setDisabled(false);
        driver.addDriverLibrary(lib);
    }
    for (DBPDriverLibrary lib : CommonUtils.copyList(driver.getDriverLibraries())) {
        if (!newLibList.contains(lib)) {
            driver.removeDriverLibrary(lib);
        }
    }
}
Also used : DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary)

Example 15 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverLibraryDetailsDialog method createDependenciesTab.

private void createDependenciesTab(TabFolder tabs) {
    Composite paramsGroup = new Composite(tabs, SWT.NONE);
    paramsGroup.setLayout(new GridLayout(1, false));
    final Set<DBPDriverLibrary> libList = Collections.singleton(library);
    DriverDependencies dependencies = new DriverDependencies(libList);
    final DriverDependenciesTree depsTree = new DriverDependenciesTree(paramsGroup, DBeaverUI.getDefaultRunnableContext(), dependencies, driver, libList, false);
    depsTree.resolveLibraries();
    DBeaverUI.asyncExec(new Runnable() {

        @Override
        public void run() {
            depsTree.resizeTree();
        }
    });
    TabItem depsTab = new TabItem(tabs, SWT.NONE);
    depsTab.setText(CoreMessages.dialog_edit_driver_tab_depencencies);
    depsTab.setToolTipText(CoreMessages.dialog_edit_driver_tab_depencencies_tooltip);
    depsTab.setControl(paramsGroup);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) DriverDependencies(org.jkiss.dbeaver.registry.driver.DriverDependencies) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary)

Aggregations

DBPDriverLibrary (org.jkiss.dbeaver.model.connection.DBPDriverLibrary)23 File (java.io.File)8 IOException (java.io.IOException)6 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DBException (org.jkiss.dbeaver.DBException)3 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)3 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JarFile (java.util.jar.JarFile)2