Example usage for org.eclipse.jface.operation IRunnableWithProgress run

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress run.

Prototype

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;

Source Link

Document

Runs this operation.

Usage

From source file:org.springframework.ide.eclipse.gettingstarted.guides.wizard.GuideImportWizardModel.java

License:Open Source License

/**
 * Performs the final step of the wizard when user clicks on Finish button.
 * @throws InterruptedException /*from w  w w .  j a v a  2s  . com*/
 * @throws InvocationTargetException 
 */
public boolean performFinish(IProgressMonitor mon) throws InvocationTargetException, InterruptedException {
    //The import will be carried out with whatever the currently selected values are
    // in all the input fields / variables / widgets.
    GettingStartedGuide g = guide.getValue();
    BuildType bt = buildType.getValue();
    Set<String> codesetNames = codesets.getValue();

    mon.beginTask("Import guide content", codesetNames.size() + 1);
    try {
        for (String name : codesetNames) {
            CodeSet cs = g.getCodeSet(name);
            if (cs == null) {
                //Ignore 'invalid' codesets. This is a bit of a hack so that we can retain selected codeset names
                //  across guide selection changes. To do that we remember 'selected' cs names even if they
                //  aren't valid for the current guide. That way the checkbox state stays consistent
                //  when switching between guides (otherwise 'invalid' names would have to be cleared when switching to
                //  a guide). 
                mon.worked(1);
            } else {
                IRunnableWithProgress oper = bt.getImportStrategy()
                        .createOperation(ImportUtils.importConfig(g, cs));
                oper.run(new SubProgressMonitor(mon, 1));
            }
        }
        if (enableOpenHomePage.getValue()) {
            URL url = homePage.getValue();
            if (url != null) {
                WebDashboardPage.openUrl(url.toString());
            }
        }
        return true;
    } catch (UIThreadDownloadDisallowed e) {
        //This shouldn't be possible... Finish button won't be enabled unless all is validated. 
        //This implies the content has been downloaded (can't be validated otherwise).
        GettingStartedActivator.log(e);
        return false;
    } finally {
        mon.done();
    }
}

From source file:org.springframework.ide.eclipse.gettingstarted.tests.BuildReferenceAppTest.java

License:Open Source License

@Override
protected void runTest() throws Throwable {
    setAutoBuilding(false);/* w ww.  j  av  a  2  s.com*/
    try {
        System.out.println("=== reference app build test ===");
        System.out.println("name   : " + item.getName());
        System.out.println("type    : " + buildtype);
        System.out.println();

        String projectName = item.getName();
        CodeSet codeset = item.getCodeSet();
        IRunnableWithProgress importOp = buildtype.getImportStrategy().createOperation(importConfig(
                /*location*/
                Platform.getLocation().append(projectName),
                /*name*/
                projectName,
                /*codeset*/
                codeset));

        importOp.run(new NullProgressMonitor());

        //TODO: we are not checking if there are extra projects beyond the expected one.
        IProject project = getProject(projectName);
        assertNoErrors(project);
    } catch (Throwable e) {
        //Shorter stacktrace for somewhat nicer looking test failures on bamboo
        throw ExceptionUtil.getDeepestCause(e);
    }
}

From source file:org.springframework.ide.eclipse.gettingstarted.tests.ZBuildGuidesTest.java

License:Open Source License

@Override
protected void runTest() throws Throwable {
    try {/*from ww w .j a  v a2 s.  c om*/
        System.out.println("=== codeset build test ===");
        System.out.println("guide   : " + guide.getName());
        System.out.println("codeset : " + codeset.getName());
        System.out.println("type    : " + buildType);
        System.out.println();

        String projectName = guide.getName() + "-" + codeset.getName();
        IRunnableWithProgress importOp = buildType.getImportStrategy()
                .createOperation(ImportUtils.importConfig(guide, codeset));

        importOp.run(new NullProgressMonitor());

        //TODO: we are not checking if there are extra projects beyond the expected one.
        IProject project = getProject(projectName);
        assertNoErrors(project);
    } catch (Throwable e) {
        //Shorter stacktrace for somewhat nicer looking test failures on bamboo
        throw ExceptionUtil.getDeepestCause(e);
    }

}

From source file:org.springframework.ide.eclipse.wizard.gettingstarted.boot.NewSpringBootWizardModel.java

License:Open Source License

public void performFinish(IProgressMonitor mon) throws InvocationTargetException, InterruptedException {
    mon.beginTask("Importing " + baseUrl.getValue(), 4);
    DownloadManager downloader = null;/*from  w w w. ja  v a 2s.  c  om*/
    try {
        downloader = new DownloadManager().allowUIThread(allowUIThread);

        DownloadableItem zip = new DownloadableItem(newURL(downloadUrl.getValue()), downloader);
        String projectNameValue = projectName.getValue();
        CodeSet cs = CodeSet.fromZip(projectNameValue, zip, new Path("/"));

        IRunnableWithProgress oper = getImportStrategy()
                .createOperation(ImportUtils.importConfig(new Path(location.getValue()), projectNameValue, cs));
        oper.run(new SubProgressMonitor(mon, 3));

        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNameValue);
        addToWorkingSets(project, new SubProgressMonitor(mon, 1));

    } catch (IOException e) {
        throw new InvocationTargetException(e);
    } finally {
        if (downloader != null) {
            downloader.dispose();
        }
        mon.done();
    }
}

From source file:org.springframework.ide.eclipse.wizard.gettingstarted.guides.GSImportWizardModel.java

License:Open Source License

/**
 * Performs the final step of the wizard when user clicks on Finish button.
 * @throws InterruptedException//from  w ww  .  j  av  a 2s  .  com
 * @throws InvocationTargetException
 */
public boolean performFinish(IProgressMonitor mon) throws InvocationTargetException, InterruptedException {
    //The import will be carried out with whatever the currently selected values are
    // in all the input fields / variables / widgets.
    GSContent g = guide.getValue();
    BuildType bt = buildType.getValue();
    Set<String> codesetNames = codesets.getValue();

    mon.beginTask("Import guide content", codesetNames.size() + 1);
    try {
        for (String name : codesetNames) {
            CodeSet cs = g.getCodeSet(name);
            if (cs == null) {
                //Ignore 'invalid' codesets. This is a bit of a hack so that we can retain selected codeset names
                //  across guide selection changes. To do that we remember 'selected' cs names even if they
                //  aren't valid for the current guide. That way the checkbox state stays consistent
                //  when switching between guides (otherwise 'invalid' names would have to be cleared when switching to
                //  a guide).
                mon.worked(1);
            } else {
                IRunnableWithProgress oper = bt.getImportStrategy()
                        .createOperation(ImportUtils.importConfig(g, cs));
                oper.run(new SubProgressMonitor(mon, 1));
            }
        }
        if (enableOpenHomePage.getValue()) {
            openHomePage();
        }
        return true;
    } catch (UIThreadDownloadDisallowed e) {
        //This shouldn't be possible... Finish button won't be enabled unless all is validated.
        //This implies the content has been downloaded (can't be validated otherwise).
        WizardPlugin.log(e);
        return false;
    } finally {
        mon.done();
    }
}

From source file:org.springsource.ide.eclipse.commons.frameworks.core.util.JobUtil.java

License:Open Source License

/**
 * Runs a job in the background through a progress service that provides UI
 * progress. Because the progress service provides UI progress, the initial
 * launching of the services is done from the UI thread BEFORE the
 * background job is started . A progress service is required and cannot be
 * null.//  www . j  a  va 2s.  co  m
 * 
 */
public static void runBackgroundJobWithUIProgress(final IRunnableWithProgress runnableWithProgress,
        final IRunnableContext progressService, final String jobLabel) throws Exception {
    // This outer runnable launches the background job
    final IRunnableWithProgress outerRunnable = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
            // Fork outside UI thread
            Job job = new Job(jobLabel) {
                @Override
                public IStatus run(IProgressMonitor monitor) {
                    SubMonitor subMonitor = SubMonitor.convert(monitor);
                    subMonitor.setTaskName(jobLabel);
                    try {
                        runnableWithProgress.run(subMonitor);
                    } catch (Throwable e) {
                        FrameworkCoreActivator.log(e);
                    } finally {
                        subMonitor.done();
                    }
                    return Status.OK_STATUS;
                }

            };
            job.schedule();
        }
    };

    // Progress services needs to be launched in UI thread.
    Exception[] error = new Exception[1];
    Display.getDefault().syncExec(() -> {
        try {
            progressService.run(true, true, outerRunnable);
        } catch (InvocationTargetException e) {
            error[0] = e;
        } catch (InterruptedException e) {
            error[0] = e;
        }
    });

    if (error[0] != null) {
        throw error[0];
    }
}

From source file:org.springsource.ide.eclipse.commons.gettingstarted.tests.BuildReferenceAppTest.java

License:Open Source License

@Override
protected void runTest() throws Throwable {
    setAutoBuilding(false);//from w  w  w.j  a  v a  2s .c o m
    try {
        System.out.println("=== reference app build test ===");
        System.out.println("name   : " + item.getName());
        System.out.println("type    : " + buildtype);
        System.out.println();

        String projectName = item.getName();
        CodeSet codeset = item.getCodeSet();
        IRunnableWithProgress importOp = buildtype.getImportStrategy().createOperation(importConfig(
                /*location*/
                Platform.getLocation().append(projectName),
                /*name*/
                projectName,
                /*codeset*/
                codeset));

        importOp.run(new NullProgressMonitor());

        //TODO: we are not checking if there are extra projects beyond the expected one.
        IProject project = StsTestUtil.getProject(projectName);
        assertNoErrors(project);
    } catch (Throwable e) {
        //Shorter stacktrace for somewhat nicer looking test failures on bamboo
        throw ExceptionUtil.getDeepestCause(e);
    }
}

From source file:org.springsource.ide.eclipse.commons.gettingstarted.tests.ZBuildGuidesTest.java

License:Open Source License

@Override
protected void runTest() throws Throwable {
    //System.out.println(">>> Running "+getName());

    try {/*w w w. j a  v a 2 s.  c  om*/
        System.out.println("=== codeset build test ===");
        System.out.println("guide   : " + guide.getName());
        System.out.println("codeset : " + codeset.getName());
        System.out.println("type    : " + buildType);
        System.out.println();

        ImportConfiguration importConf = ImportUtils.importConfig(guide, codeset);
        String projectName = importConf.getProjectName();
        final IRunnableWithProgress importOp = buildType.getImportStrategy().createOperation(importConf);
        //         buildJob(new GradleRunnable("import "+guide.getName() + " " + codeset.getName() + " "+buildType) {
        //            @Override
        //            public void doit(IProgressMonitor mon) throws Exception {
        importOp.run(new NullProgressMonitor());
        //            }
        //         });

        //TODO: we are not checking if there are extra projects beyond the expected one.
        IProject project = getProject(projectName);
        assertNoErrors(project);
    } catch (Throwable e) {
        //Shorter stacktrace for somewhat nicer looking test failures on bamboo
        throw ExceptionUtil.getDeepestCause(e);
    } finally {
        //System.out.println("<<< Running "+getName());
    }
}

From source file:org.switchyard.tools.ui.wizards.Java2WSDLWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final Java2WSDLOptions options = new Java2WSDLOptions();
    options.setLocationURI(_optionsPage.getLocationURI());
    options.setServiceInterface(_optionsPage.getServiceInterface());
    options.setTargetNamespace(_optionsPage.getTargetNamespace());
    options.setUseImportedSchema(_optionsPage.isUseImportedSchema());
    options.setServiceName(_optionsPage.getServiceName());
    options.setWrapped(_optionsPage.isUseWrappedMessages());

    _wsdlFile = ResourcesPlugin.getWorkspace().getRoot()
            .getFile(_filePage.getContainerFullPath().append(_filePage.getFileName()));

    IRunnableWithProgress op = new IRunnableWithProgress() {
        @Override/*from w w  w  . j  av a 2  s  . c o m*/
        public void run(IProgressMonitor monitor) {
            try {
                CreateWSDLFromJavaOperation op = new CreateWSDLFromJavaOperation(options, getWSDLFile());
                op.run(monitor);
                final IStatus status = op.getStatus();
                Activator.getDefault().getLog().log(status);
                if (status.getSeverity() > IStatus.INFO) {
                    getContainer().getShell().getDisplay().syncExec(new Runnable() {
                        @Override
                        public void run() {
                            ErrorDialog.openError(getContainer().getShell(), null,
                                    Messages.Java2WSDLWizard_errorMessage_errorWhileGeneratingSchemaFiles,
                                    status);
                        }
                    });
                }
            } catch (final CoreException e) {
                Activator.getDefault().getLog().log(e.getStatus());
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        ErrorDialog.openError(getContainer().getShell(), null,
                                Messages.Java2WSDLWizard_errorMessage_errorWhileGeneratingWSDL, e.getStatus());
                    }
                });
            }
        }
    };

    try {
        getContainer().run(false, false, op);
        selectAndReveal(getWSDLFile());
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.fillInStackTrace();
    }

    return true;
}

From source file:org.symbian.tools.tmw.internal.util.DelegateRunnable.java

License:Open Source License

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    monitor.beginTask("Preparing project", runnables.size() * 20);
    for (IRunnableWithProgress runnable : runnables) {
        runnable.run(new SubProgressMonitor(monitor, 20));
    }//from   w ww .  j  a  v  a  2  s  .c o m
    monitor.done();
}