Search in sources :

Example 1 with DBPNativeClientLocationManager

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager in project dbeaver by serge-rider.

the class ClientHomesSelector method populateHomes.

public void populateHomes(DBPDriver driver, String currentHome, boolean selectDefault) {
    this.driver = driver;
    this.currentHomeId = currentHome;
    this.homesCombo.removeAll();
    this.homeIds.clear();
    Map<String, DBPNativeClientLocation> homes = new LinkedHashMap<>();
    AbstractJob hlJob = new AbstractJob("Find native client homes") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            for (DBPNativeClientLocation ncl : driver.getNativeClientLocations()) {
                homes.put(ncl.getName(), ncl);
            }
            DBPNativeClientLocationManager clientManager = driver.getNativeClientManager();
            if (clientManager != null) {
                for (DBPNativeClientLocation location : clientManager.findLocalClientLocations()) {
                    homes.putIfAbsent(location.getName(), location);
                }
            }
            return Status.OK_STATUS;
        }
    };
    hlJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            UIUtils.syncExec(() -> {
                for (DBPNativeClientLocation location : homes.values()) {
                    homesCombo.add(location.getDisplayName());
                    homeIds.add(location.getName());
                    if (currentHomeId != null && location.getName().equals(currentHomeId)) {
                        homesCombo.select(homesCombo.getItemCount() - 1);
                    }
                }
                if (homesCombo.getItemCount() == 0) {
                    homesCombo.add(UIConnectionMessages.controls_client_home_selector_missing);
                    homeIds.add(null);
                }
                if (selectDefault && homesCombo.getSelectionIndex() == -1) {
                    homesCombo.select(0);
                    currentHomeId = homeIds.get(0);
                }
                homesCombo.add(UIConnectionMessages.controls_client_home_selector_browse);
                displayClientVersion();
                homesCombo.setEnabled(true);
            });
            super.done(event);
        }
    });
    hlJob.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 2 with DBPNativeClientLocationManager

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager in project dbeaver by serge-rider.

the class ClientHomesPanel method selectHome.

private void selectHome(HomeInfo home) {
    removeButton.setEnabled(home != null && !home.isProvided);
    // $NON-NLS-1$
    idText.setText(home == null ? "" : CommonUtils.notEmpty(home.location.getName()));
    // $NON-NLS-1$
    pathText.setText(home == null ? "" : home.location.getPath().getAbsolutePath());
    // $NON-NLS-1$
    nameText.setText(home == null ? "" : CommonUtils.notEmpty(home.location.getDisplayName()));
    if (home != null && !home.isValidated) {
        try {
            UIUtils.runInProgressDialog(monitor -> {
                try {
                    home.location.validateFilesPresence(monitor);
                    home.isValidated = true;
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (InvocationTargetException e) {
            DBWorkbench.getPlatformUI().showError("Client download", "Failed to download client files", e.getTargetException());
        }
    }
    DBPNativeClientLocationManager nativeClientLocationManager = driver.getNativeClientManager();
    if (nativeClientLocationManager != null) {
        // $NON-NLS-1$
        productNameText.setText(home == null ? "" : CommonUtils.notEmpty(nativeClientLocationManager.getProductName(home.location)));
        // $NON-NLS-1$
        productVersionText.setText(home == null ? "" : CommonUtils.notEmpty(nativeClientLocationManager.getProductVersion(home.location)));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with DBPNativeClientLocationManager

use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager in project dbeaver by serge-rider.

the class ClientHomesPanel method addClientHome.

private void addClientHome() {
    DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
    if (lastHomeDirectory != null) {
        directoryDialog.setFilterPath(lastHomeDirectory);
    }
    String homeId = directoryDialog.open();
    if (homeId == null) {
        return;
    }
    lastHomeDirectory = homeId;
    DBPNativeClientLocationManager clientManager = driver.getNativeClientManager();
    if (clientManager != null) {
        createHomeItem(clientManager, new LocalNativeClientLocation(homeId, homeId), false);
    }
}
Also used : DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) LocalNativeClientLocation(org.jkiss.dbeaver.model.connection.LocalNativeClientLocation)

Example 4 with DBPNativeClientLocationManager

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

the class ClientHomesPanel method loadHomes.

public void loadHomes(DBPDriver driver) {
    homesTable.removeAll();
    this.driver = driver;
    selectHome(null);
    DBPNativeClientLocationManager clientManager = this.driver.getNativeClientManager();
    if (clientManager == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        log.debug("Client manager is not supported by driver '" + driver.getName() + "'");
    }
    Set<DBPNativeClientLocation> providedHomes = new LinkedHashSet<>();
    if (clientManager != null) {
        providedHomes.addAll(clientManager.findLocalClientLocations());
    }
    Set<DBPNativeClientLocation> allHomes = new LinkedHashSet<>();
    allHomes.addAll(driver.getNativeClientLocations());
    allHomes.addAll(providedHomes);
    for (DBPNativeClientLocation home : allHomes) {
        TableItem item = createHomeItem(clientManager, home, home instanceof RemoteNativeClientLocation || providedHomes.contains(home));
        if (item != null) {
            HomeInfo homeInfo = (HomeInfo) item.getData();
            if (homeInfo.isDefault) {
                homesTable.setSelection(homesTable.indexOf(item));
                selectHome(homeInfo);
            }
        }
    }
}
Also used : DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) RemoteNativeClientLocation(org.jkiss.dbeaver.registry.driver.RemoteNativeClientLocation)

Example 5 with DBPNativeClientLocationManager

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

the class ClientHomesPanel method selectHome.

private void selectHome(HomeInfo home) {
    removeButton.setEnabled(home != null && !home.isProvided);
    // $NON-NLS-1$
    idText.setText(home == null ? "" : CommonUtils.notEmpty(home.location.getName()));
    // $NON-NLS-1$
    pathText.setText(home == null ? "" : home.location.getPath().getAbsolutePath());
    // $NON-NLS-1$
    nameText.setText(home == null ? "" : CommonUtils.notEmpty(home.location.getDisplayName()));
    if (home != null && !home.isValidated) {
        try {
            UIUtils.runInProgressDialog(monitor -> {
                try {
                    home.location.validateFilesPresence(monitor);
                    home.isValidated = true;
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (InvocationTargetException e) {
            DBWorkbench.getPlatformUI().showError("Client download", "Failed to download client files", e.getTargetException());
        }
    }
    DBPNativeClientLocationManager nativeClientLocationManager = driver.getNativeClientManager();
    if (nativeClientLocationManager != null) {
        // $NON-NLS-1$
        productNameText.setText(home == null ? "" : CommonUtils.notEmpty(nativeClientLocationManager.getProductName(home.location)));
        // $NON-NLS-1$
        productVersionText.setText(home == null ? "" : CommonUtils.notEmpty(nativeClientLocationManager.getProductVersion(home.location)));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DBPNativeClientLocationManager (org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager)10 DBPNativeClientLocation (org.jkiss.dbeaver.model.connection.DBPNativeClientLocation)6 DBException (org.jkiss.dbeaver.DBException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)2 LocalNativeClientLocation (org.jkiss.dbeaver.model.connection.LocalNativeClientLocation)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 RemoteNativeClientLocation (org.jkiss.dbeaver.registry.driver.RemoteNativeClientLocation)2