Search in sources :

Example 96 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project dbeaver by dbeaver.

the class ConnectionWizard method testConnection.

public void testConnection() {
    DataSourceDescriptor dataSource = getPageSettings().getActiveDataSource();
    DataSourceDescriptor testDataSource = new DataSourceDescriptor(dataSource);
    saveSettings(testDataSource);
    // Generate new ID to avoid session conflicts in QM
    testDataSource.setId(DataSourceDescriptor.generateNewId(dataSource.getDriver()));
    testDataSource.getPreferenceStore().setValue(ModelPreferences.META_SEPARATE_CONNECTION, false);
    try {
        final ConnectionTester op = new ConnectionTester(testDataSource);
        try {
            getContainer().run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    // Wait for job to finish
                    op.ownerMonitor = RuntimeUtils.makeMonitor(monitor);
                    op.schedule();
                    while (op.getState() == Job.WAITING || op.getState() == Job.RUNNING) {
                        if (monitor.isCanceled()) {
                            op.cancel();
                            throw new InterruptedException();
                        }
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            break;
                        }
                    }
                    if (op.getConnectError() != null) {
                        throw new InvocationTargetException(op.getConnectError());
                    }
                    if (op.getConnectStatus() == Status.CANCEL_STATUS) {
                        throw new InterruptedException();
                    }
                }
            });
            String message = "";
            if (!CommonUtils.isEmpty(op.productName)) {
                message += "Server: " + op.productName + " " + op.productVersion + "\n";
            }
            if (!CommonUtils.isEmpty(op.driverName)) {
                message += "Driver: " + op.driverName + " " + op.driverVersion + "\n";
            }
            if (!CommonUtils.isEmpty(message)) {
                message += "\n";
            }
            message += NLS.bind(CoreMessages.dialog_connection_wizard_start_connection_monitor_connected, op.connectTime);
            MessageDialog.openInformation(getShell(), CoreMessages.dialog_connection_wizard_start_connection_monitor_success, message);
        } catch (InterruptedException ex) {
            DBUserInterface.getInstance().showError(CoreMessages.dialog_connection_wizard_start_dialog_interrupted_title, CoreMessages.dialog_connection_wizard_start_dialog_interrupted_message);
        } catch (InvocationTargetException ex) {
            DBUserInterface.getInstance().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
        }
    } finally {
        testDataSource.dispose();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDataSourceConnectionTester(org.jkiss.dbeaver.ui.IDataSourceConnectionTester) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 97 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project dbeaver by dbeaver.

the class ContentEditor method doSaveAs.

@Override
public void doSaveAs() {
    Shell shell = getSite().getShell();
    final File saveFile = DialogUtils.selectFileForSave(shell, getPartName());
    if (saveFile == null) {
        return;
    }
    try {
        getSite().getWorkbenchWindow().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    getEditorInput().saveToExternalFile(saveFile, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        DBUserInterface.getInstance().showError("Can't save content", "Can't save content to file '" + saveFile.getAbsolutePath() + "'", e.getTargetException());
    } catch (InterruptedException e) {
    // do nothing
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 98 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project yamcs-studio by yamcs.

the class SchemaService method reLoad.

/**
 * Reload schema opi.
 */
public void reLoad() {
    schemaWidgetsMap.clear();
    final IPath schemaOPI = PreferencesHelper.getSchemaOPIPath();
    if (schemaOPI == null || schemaOPI.isEmpty()) {
        return;
    }
    if (Display.getCurrent() != null) {
        // in UI thread, show progress dialog
        IRunnableWithProgress job = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Connecting to " + schemaOPI, IProgressMonitor.UNKNOWN);
                loadSchema(schemaOPI);
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(true, false, job);
        } catch (Exception e) {
            ErrorHandlerUtil.handleError("Failed to load schema", e);
        }
    } else
        loadSchema(schemaOPI);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 99 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project dbeaver by dbeaver.

the class DatabaseConsumerSettings method loadNode.

public void loadNode(IRunnableContext runnableContext) {
    if (containerNode == null && !CommonUtils.isEmpty(containerNodePath)) {
        if (!CommonUtils.isEmpty(containerNodePath)) {
            try {
                runnableContext.run(true, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            DBNNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByPath(new DefaultProgressMonitor(monitor), containerNodePath);
                            if (node instanceof DBNDatabaseNode) {
                                containerNode = (DBNDatabaseNode) node;
                            }
                        } catch (DBException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
                checkContainerConnection(runnableContext);
            } catch (InvocationTargetException e) {
                log.error("Error getting container node", e.getTargetException());
            } catch (InterruptedException e) {
            // ignore
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 100 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project erlide_eclipse by erlang.

the class ProjectCreator method createProject.

public IProject createProject() throws CoreException {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject newProjectHandle = workspace.getRoot().getProject(name);
    if (newProjectHandle.exists()) {
        throw new CoreException(Status.OK_STATUS);
    }
    final IProjectDescription description = workspace.newProjectDescription(name);
    description.setLocationURI(location);
    // // update the referenced project if provided
    if (referencedProjects != null) {
        description.setReferencedProjects(referencedProjects);
    }
    // create the new project operation
    final IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException {
            final CreateProjectOperation op1 = new CreateProjectOperation(description, WizardMessages.NewProject_windowTitle);
            try {
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // Making this undoable would be a bad idea
                op1.execute(monitor, notifier);
                newProjectHandle.open(monitor);
                description.setNatureIds(new String[] { ErlangCore.NATURE_ID });
                newProjectHandle.setDescription(description, null);
                final BuilderTool builder = info.getBuilder();
                ErlangNature.setErlangProjectBuilder(newProjectHandle, builder);
                createBuilderConfig(builder);
                createFolders(newProjectHandle, Lists.newArrayList(info.getOutputDir()), monitor);
                createFolders(newProjectHandle, info.getSourceDirs(), monitor);
                createFolders(newProjectHandle, info.getIncludeDirs(), monitor);
                createConfig(newProjectHandle, info.getConfigType(), monitor);
                final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(newProjectHandle);
                erlProject.setConfigType(info.getConfigType());
                final BuilderProperties builderProperties = new BuilderProperties();
                builderProperties.setBuilderTool(builder);
                builderProperties.setCompileTarget(info.getBuilderData().get("compile"));
                builderProperties.setCleanTarget(info.getBuilderData().get("clean"));
                erlProject.setBuilderProperties(builderProperties);
                erlProject.setProperties(info);
            } catch (final Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // run the new project creation operation
    try {
        context.run(false, true, op);
    } catch (final InterruptedException e) {
        return null;
    } catch (final InvocationTargetException e) {
        final Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            final CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING, NLS.bind(WizardMessages.NewProject_caseVariantExistsError, newProjectHandle.getName()), cause));
            } else {
                status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), WizardMessages.NewProject_errorMessage, cause));
            }
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, WizardMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            final StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ErlideUIPlugin.PLUGIN_ID, 0, NLS.bind(WizardMessages.NewProject_internalError, t.getMessage()), t));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, WizardMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
        return null;
    }
    return newProjectHandle;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) StatusAdapter(org.eclipse.ui.statushandlers.StatusAdapter) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) BuilderProperties(org.erlide.engine.model.builder.BuilderProperties) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) BuilderTool(org.erlide.engine.model.builder.BuilderTool)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)417 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)397 InvocationTargetException (java.lang.reflect.InvocationTargetException)386 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)194 CoreException (org.eclipse.core.runtime.CoreException)123 ArrayList (java.util.ArrayList)86 IStatus (org.eclipse.core.runtime.IStatus)67 IOException (java.io.IOException)65 List (java.util.List)54 Status (org.eclipse.core.runtime.Status)53 IFile (org.eclipse.core.resources.IFile)51 File (java.io.File)47 Shell (org.eclipse.swt.widgets.Shell)44 IProject (org.eclipse.core.resources.IProject)40 PartInitException (org.eclipse.ui.PartInitException)32 IPath (org.eclipse.core.runtime.IPath)26 Display (org.eclipse.swt.widgets.Display)26 IResource (org.eclipse.core.resources.IResource)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 Path (org.eclipse.core.runtime.Path)23