Search in sources :

Example 1 with UIConfirmation

use of org.jkiss.dbeaver.ui.UIConfirmation in project dbeaver by dbeaver.

the class NavigatorHandlerRefresh method refreshNavigator.

public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
    Job refreshJob = new AbstractJob("Refresh navigator object(s)") {

        public Throwable error;

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (error != null) {
                        DBUserInterface.getInstance().showError("Refresh", "Error refreshing node", error);
                    }
                }
            });
            Set<DBNNode> refreshedSet = new HashSet<>();
            for (DBNNode node : refreshObjects) {
                if (node.isDisposed() || node.isLocked()) {
                    // Skip locked nodes
                    continue;
                }
                // Check this node was already refreshed
                if (!refreshedSet.isEmpty()) {
                    boolean skip = false;
                    for (DBNNode refreshed : refreshedSet) {
                        if (node == refreshed || node.isChildOf(refreshed)) {
                            skip = true;
                            break;
                        }
                    }
                    if (skip) {
                        continue;
                    }
                }
                // Check for dirty editor (some local changes) and ask for confirmation
                if (node instanceof DBNDatabaseFolder && !(node.getParentNode() instanceof DBNDatabaseFolder) && node.getParentNode() instanceof DBNDatabaseNode) {
                    // USe parent if this node is a folder
                    node = node.getParentNode();
                }
                IEditorPart nodeEditor = NavigatorHandlerObjectOpen.findEntityEditor(DBeaverUI.getActiveWorkbenchWindow(), node);
                if (nodeEditor != null && nodeEditor.isDirty()) {
                    if (!new UIConfirmation() {

                        @Override
                        protected Boolean runTask() {
                            return ConfirmationDialog.showConfirmDialog(null, DBeaverPreferences.CONFIRM_ENTITY_REVERT, ConfirmationDialog.QUESTION, nodeEditor.getTitle()) == IDialogConstants.YES_ID;
                        }
                    }.execute()) {
                        continue;
                    }
                }
                setName("Refresh '" + node.getNodeName() + "'...");
                try {
                    DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
                    if (refreshed != null) {
                        refreshedSet.add(refreshed);
                    }
                } catch (Throwable ex) {
                    error = ex;
                }
            }
            return Status.OK_STATUS;
        }
    };
    refreshJob.setUser(true);
    refreshJob.schedule();
}
Also used : UIConfirmation(org.jkiss.dbeaver.ui.UIConfirmation) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IEditorPart(org.eclipse.ui.IEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) Job(org.eclipse.core.runtime.jobs.Job) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with UIConfirmation

use of org.jkiss.dbeaver.ui.UIConfirmation in project dbeaver by dbeaver.

the class SQLQueryJob method fillStatementParameters.

private boolean fillStatementParameters(final List<SQLQueryParameter> parameters) {
    boolean allSet = true;
    for (SQLQueryParameter param : parameters) {
        if (param.getValue() == null) {
            allSet = false;
        }
        String paramName = param.getTitle();
        if (scriptContext.hasVariable(paramName)) {
            Object varValue = scriptContext.getVariable(paramName);
            String strValue;
            if (varValue instanceof String) {
                strValue = SQLUtils.quoteString(getExecutionContext().getDataSource(), (String) varValue);
            } else {
                strValue = varValue == null ? null : varValue.toString();
            }
            param.setValue(strValue);
        }
    }
    if (allSet) {
        return true;
    }
    boolean okPressed = new UIConfirmation() {

        @Override
        public Boolean runTask() {
            SQLQueryParameterBindDialog dialog = new SQLQueryParameterBindDialog(partSite.getShell(), parameters);
            return (dialog.open() == IDialogConstants.OK_ID);
        }
    }.execute();
    if (okPressed) {
        // Save values back to script context
        for (SQLQueryParameter param : parameters) {
            if (param.isNamed() && scriptContext.hasVariable(param.getTitle())) {
                String strValue = param.getValue();
                scriptContext.setVariable(param.getTitle(), SQLUtils.unQuoteString(getExecutionContext().getDataSource(), strValue));
            }
        }
    }
    return okPressed;
}
Also used : UIConfirmation(org.jkiss.dbeaver.ui.UIConfirmation)

Example 3 with UIConfirmation

use of org.jkiss.dbeaver.ui.UIConfirmation in project dbeaver by dbeaver.

the class DriverDownloadAutoPage method downloadLibraryFiles.

private void downloadLibraryFiles(final DBRProgressMonitor monitor) throws InterruptedException {
    if (!getWizard().getDriver().acceptDriverLicenses()) {
        return;
    }
    boolean processUnsecure = false;
    List<DBPDriverDependencies.DependencyNode> nodes = getWizard().getDependencies().getLibraryList();
    for (int i = 0, filesSize = nodes.size(); i < filesSize; ) {
        final DBPDriverLibrary lib = nodes.get(i).library;
        if (!processUnsecure && !lib.isSecureDownload(monitor)) {
            boolean process = new UIConfirmation() {

                @Override
                protected Boolean runTask() {
                    MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
                    messageBox.setText(CoreMessages.dialog_driver_download_auto_page_driver_security_warning);
                    messageBox.setMessage(NLS.bind(CoreMessages.dialog_driver_download_auto_page_driver_security_warning_msg, lib.getDisplayName(), lib.getExternalURL(monitor)));
                    int response = messageBox.open();
                    return (response == SWT.YES);
                }
            }.execute();
            if (process) {
                processUnsecure = true;
            } else {
                break;
            }
        }
        int result = IDialogConstants.OK_ID;
        try {
            lib.downloadLibraryFile(monitor, getWizard().isForceDownload(), NLS.bind(CoreMessages.dialog_driver_download_auto_page_download_rate, (i + 1), filesSize));
        } catch (final IOException e) {
            if (lib.getType() == DBPDriverLibrary.FileType.license) {
                result = IDialogConstants.OK_ID;
            } else {
                result = new UITask<Integer>() {

                    @Override
                    protected Integer runTask() {
                        DownloadErrorDialog dialog = new DownloadErrorDialog(null, lib.getDisplayName(), CoreMessages.dialog_driver_download_auto_page_download_failed_msg, e);
                        return dialog.open();
                    }
                }.execute();
            }
        }
        switch(result) {
            case IDialogConstants.CANCEL_ID:
            case IDialogConstants.ABORT_ID:
                return;
            case IDialogConstants.RETRY_ID:
                continue;
            case IDialogConstants.OK_ID:
            case IDialogConstants.IGNORE_ID:
                i++;
                break;
        }
    }
    getWizard().getDriver().setModified(true);
// DataSourceProviderRegistry.getInstance().saveDrivers();
}
Also used : UIConfirmation(org.jkiss.dbeaver.ui.UIConfirmation) IOException(java.io.IOException) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary)

Example 4 with UIConfirmation

use of org.jkiss.dbeaver.ui.UIConfirmation in project dbeaver by serge-rider.

the class DriverDownloadAutoPage method downloadLibraryFiles.

private void downloadLibraryFiles(final DBRProgressMonitor monitor) throws InterruptedException {
    if (!acceptDriverLicenses()) {
        return;
    }
    boolean processUnsecure = false;
    List<DBPDriverDependencies.DependencyNode> nodes = getWizard().getDependencies().getLibraryList();
    for (int i = 0, filesSize = nodes.size(); i < filesSize; ) {
        final DBPDriverLibrary lib = nodes.get(i).library;
        if (!processUnsecure && !lib.isSecureDownload(monitor)) {
            boolean process = new UIConfirmation() {

                @Override
                protected Boolean runTask() {
                    MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
                    messageBox.setText(UIConnectionMessages.dialog_driver_download_auto_page_driver_security_warning);
                    messageBox.setMessage(NLS.bind(UIConnectionMessages.dialog_driver_download_auto_page_driver_security_warning_msg, lib.getDisplayName(), lib.getExternalURL(monitor)));
                    int response = messageBox.open();
                    return (response == SWT.YES);
                }
            }.execute();
            if (process) {
                processUnsecure = true;
            } else {
                break;
            }
        }
        int result = IDialogConstants.OK_ID;
        try {
            lib.downloadLibraryFile(monitor, getWizard().isForceDownload(), NLS.bind(UIConnectionMessages.dialog_driver_download_auto_page_download_rate, (i + 1), filesSize));
        } catch (final IOException e) {
            if (lib.getType() == DBPDriverLibrary.FileType.license) {
                result = IDialogConstants.OK_ID;
            } else {
                result = new UITask<Integer>() {

                    @Override
                    protected Integer runTask() {
                        DownloadErrorDialog dialog = new DownloadErrorDialog(null, lib.getDisplayName(), UIConnectionMessages.dialog_driver_download_auto_page_download_failed_msg, e);
                        return dialog.open();
                    }
                }.execute();
            }
        }
        switch(result) {
            case IDialogConstants.CANCEL_ID:
            case IDialogConstants.ABORT_ID:
                return;
            case IDialogConstants.RETRY_ID:
                continue;
            case IDialogConstants.OK_ID:
            case IDialogConstants.IGNORE_ID:
                i++;
                break;
        }
    }
    ((DriverDescriptor) getWizard().getDriver()).setModified(true);
// DataSourceProviderRegistry.getInstance().saveDrivers();
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) UIConfirmation(org.jkiss.dbeaver.ui.UIConfirmation) IOException(java.io.IOException) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary)

Aggregations

UIConfirmation (org.jkiss.dbeaver.ui.UIConfirmation)4 IOException (java.io.IOException)2 DBPDriverLibrary (org.jkiss.dbeaver.model.connection.DBPDriverLibrary)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 IEditorPart (org.eclipse.ui.IEditorPart)1 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)1