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

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

Introduction

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

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:ch.wess.ezclipse.tpl.wizards.internal.NewTemplateWizard.java

License:Open Source License

/**
 * When the wizard is finished, the file is create with the specified
 * persistent properties.//from w w w.  j av  a2 s  . co m
 */
@Override
public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    final String nodeId = page.getNodeId();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, nodeId, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), Messages.getString("NewTemplateWizard.0"), realException //$NON-NLS-1$
                .getMessage());
        return false;
    }
    return true;
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.CloudUiUtil.java

License:Open Source License

public static IStatus runForked(final ICoreRunnable coreRunner, IWizard wizard) {
    try {//from   w w w . ja  v a2  s .co  m
        IRunnableWithProgress runner = new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                try {
                    coreRunner.run(monitor);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        wizard.getContainer().run(true, false, runner);
    } catch (InvocationTargetException e) {
        IStatus status;
        if (e.getCause() instanceof CoreException) {
            status = new Status(IStatus.ERROR, DockerFoundryServerUiPlugin.PLUGIN_ID,
                    NLS.bind(Messages.CloudUiUtil_ERROR_FORK_OP_FAILED, e.getCause().getMessage()), e);
        } else {
            status = new Status(IStatus.ERROR, DockerFoundryServerUiPlugin.PLUGIN_ID,
                    NLS.bind(Messages.CloudUiUtil_ERROR_FORK_UNEXPECTED, e.getMessage()), e);
        }
        DockerFoundryServerUiPlugin.getDefault().getLog().log(status);
        IWizardPage page = wizard.getContainer().getCurrentPage();
        if (page instanceof DialogPage) {
            ((DialogPage) page).setErrorMessage(status.getMessage());
        }
        return status;
    } catch (InterruptedException e) {
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.CloudUiUtil.java

License:Open Source License

public static void runForked(final ICoreRunnable coreRunner, IRunnableContext progressService)
        throws OperationCanceledException, CoreException {
    try {/*from  w ww  . j a  v a2 s .co m*/
        IRunnableWithProgress runner = new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
                try {
                    coreRunner.run(monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }

        };
        progressService.run(true, true, runner);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            throw (CoreException) e.getCause();
        } else {
            DockerFoundryServerUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                    DockerFoundryServerUiPlugin.PLUGIN_ID, "Unexpected exception", e)); //$NON-NLS-1$
        }
    } catch (InterruptedException e) {
        throw new OperationCanceledException();
    }
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.wizards.CloudUrlWizard.java

License:Open Source License

protected boolean validateURL() {

    final Exception[] exception = new Exception[1];
    final Boolean[] shouldProceed = new Boolean[1];
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            shouldProceed[0] = launchURLValidation(exception, monitor);
        }// w  w  w  .ja v a 2s . c  o m
    };

    try {
        // Must both fork and set cancellable to true in order to enable
        // cancellation of long-running validations
        getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        exception[0] = e;
    } catch (InterruptedException e) {
        exception[0] = e;
    }
    if (!shouldProceed[0]) {
        String errorMessage = getErrorMessage(exception[0], url);
        shouldProceed[0] = MessageDialog.openQuestion(getShell(), Messages.CloudUrlWizard_ERROR_KEEP_TITLE,
                errorMessage + Messages.CloudUrlWizard_ERROR_KEEP_BODY);
    }
    return shouldProceed[0];

}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.wizards.MappedURLsWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    page.setErrorMessage(null);//from www  . j  av a  2s. co m

    final IStatus[] result = new IStatus[1];

    IRunnableWithProgress runnable = null;

    page.setMessage(Messages.MappedURLsWizard_TEXT_UPDATE_URL);

    // If the app module is not deployed, set the URIs in the deployment
    // descriptor.
    if (!applicationModule.isDeployed()) {
        runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                try {
                    DeploymentInfoWorkingCopy wc = applicationModule.resolveDeploymentInfoWorkingCopy(monitor);
                    wc.setUris(page.getURLs());
                    wc.save();
                } catch (CoreException e) {
                    result[0] = e.getStatus();
                }
            }
        };
    } else {
        runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                try {
                    cloudServer.getBehaviour().operations().mappedUrlsUpdate(appName, page.getURLs())
                            .run(monitor);
                } catch (CoreException e) {
                    result[0] = e.getStatus();
                }
            }
        };
    }

    try {
        getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        result[0] = DockerFoundryPlugin.getErrorStatus(e);
    } catch (InterruptedException e) {
        result[0] = DockerFoundryPlugin.getErrorStatus(e);
    }

    if (result[0] != null && !result[0].isOK()) {
        page.setErrorMessage(NLS.bind(Messages.MappedURLsWizard_ERROR_CHANGE_URL, result[0].getMessage()));
        return false;
    } else {
        return true;
    }

}

From source file:cn.edu.pku.ogeditor.wizards.ShapesCreationWizard.java

License:Open Source License

public boolean performFinish() {
    // TODO //  w  ww  .j  av a 2s .  co  m
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                // TODO 
                doFinish(monitor);
            }
        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    return true;
}

From source file:cn.ieclipse.pde.signer.wizard.CommonSignWizard.java

License:Apache License

@Override
public boolean performFinish() {
    try {//from   w  ww . j a va 2  s.  c om
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                sign(monitor);
            }
        };
        getContainer().run(false, true, runnable);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:co.edu.javeriana.midas.generator.ui.popupMenus.AcceleoGenerateMiDASCodeGeneratorAction.java

License:Open Source License

/**{@inheritDoc}
 *
 * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction)
 * @generated//from  ww  w.j  ava2  s . com
 */
public void run(IAction action) {
    if (files != null) {
        IRunnableWithProgress operation = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                try {
                    Iterator<IFile> filesIt = files.iterator();
                    while (filesIt.hasNext()) {
                        IFile model = (IFile) filesIt.next();
                        URI modelURI = URI.createPlatformResourceURI(model.getFullPath().toString(), true);
                        try {
                            IContainer target = model.getProject().getFolder("models"); //TODO: Review folder
                            GenerateAll generator = new GenerateAll(modelURI, target, getArguments());
                            generator.doGenerate(monitor);
                        } catch (IOException e) {
                            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                            Activator.getDefault().getLog().log(status);
                        } finally {
                            model.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
                        }
                    }
                } catch (CoreException e) {
                    IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                    Activator.getDefault().getLog().log(status);
                }
            }
        };
        try {
            PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
        } catch (InvocationTargetException e) {
            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
            Activator.getDefault().getLog().log(status);
        } catch (InterruptedException e) {
            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
            Activator.getDefault().getLog().log(status);
        }
    }
}

From source file:com.aerospike.project.wizards.NewAerospikeProjectWizard.java

License:Apache License

protected boolean generateJavaProject() {
    URL url = this.getClass().getResource("project.stg");
    final STGroup projectSTG = new STGroupFile(url.getPath());
    final String projectName = page.getProjectName();
    final String author = page.getAuthor();
    final String email = page.getEmail();
    final String artifactId = page.getArtifiactId();
    final String version = page.getVersion();
    final String packageString = page.getPackage();
    final String mainClass = page.getMainClassName();
    final String seedNode = page.getSeedNode();
    final String port = page.getPortString();
    final boolean generateMain = page.getGenerateMain();
    final boolean generateJUnit = page.getGenerateJUnit();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                //Create the project
                IProject project = createProject(projectName, monitor);
                project.setPersistentProperty(CoreActivator.SEED_NODE_PROPERTY, seedNode);
                project.setPersistentProperty(CoreActivator.PORT_PROPERTY, port);
                project.setPersistentProperty(CoreActivator.UDF_DIRECTORY, null);
                project.setPersistentProperty(CoreActivator.AQL_GENERATION_DIRECTORY, null);
                //make a java project
                IJavaProject javaProject = JavaCore.create(project);
                // create the classpath entries
                List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
                IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime
                        .getExecutionEnvironmentsManager();
                IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager
                        .getExecutionEnvironments();
                for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) {
                    // We will look for JavaSE-1.6 as the JRE container to add to our classpath
                    if ("JavaSE-1.6".equals(iExecutionEnvironment.getId())) {
                        entries.add(JavaCore
                                .newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment)));
                        break;
                    } else if ("JavaSE-1.5".equals(iExecutionEnvironment.getId())) {
                        entries.add(JavaCore
                                .newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment)));
                        break;
                    }//from   www. java 2  s  .com
                }
                IClasspathEntry mavenEntry = JavaCore.newContainerEntry(
                        new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"), new IAccessRule[0],
                        new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                                "org.eclipse.jst.component.dependency", "/WEB-INF/lib") },
                        false);
                entries.add(mavenEntry);
                javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
                // create source folders
                IFolder srcMainJava = project.getFolder("src/main/java");
                createFolder(srcMainJava);
                IFolder srcMainResource = project.getFolder("src/main/resource");
                createFolder(srcMainResource);
                IFolder srcTestJava = project.getFolder("src/test/java");
                createFolder(srcTestJava);
                IFolder srcTestResource = project.getFolder("src/test/resource");
                createFolder(srcTestResource);
                // create aerospike folders
                IFolder srcUDF = project.getFolder(store.getString(PreferenceConstants.UDF_PATH));
                createFolder(srcUDF);
                IFolder srcGenerated = project.getFolder(store.getString(PreferenceConstants.GENERATION_PATH));
                createFolder(srcGenerated);
                IFolder srcAql = project.getFolder("aql");
                createFolder(srcAql);
                //
                IPackageFragmentRoot mainJava = javaProject.getPackageFragmentRoot(srcMainJava);
                IPackageFragmentRoot mainResource = javaProject.getPackageFragmentRoot(srcMainResource);
                IPackageFragmentRoot testJava = javaProject.getPackageFragmentRoot(srcTestJava);
                IPackageFragmentRoot testResource = javaProject.getPackageFragmentRoot(srcTestResource);
                IPackageFragmentRoot mainGenerated = javaProject.getPackageFragmentRoot(srcGenerated);
                IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
                IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 5];
                System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
                newEntries[oldEntries.length] = JavaCore.newSourceEntry(mainJava.getPath());
                newEntries[oldEntries.length + 1] = JavaCore.newSourceEntry(mainResource.getPath());
                newEntries[oldEntries.length + 2] = JavaCore.newSourceEntry(testJava.getPath());
                newEntries[oldEntries.length + 3] = JavaCore.newSourceEntry(testResource.getPath());
                newEntries[oldEntries.length + 4] = JavaCore.newSourceEntry(mainGenerated.getPath());
                javaProject.setRawClasspath(newEntries, monitor);
                // create the pom.xml
                ST template = projectSTG.getInstanceOf("pom");
                template.add("name", projectName);
                template.add("artifactId", artifactId);
                template.add("version", version);
                template.add("author", author);
                template.add("email", email);
                template.add("mainClass", mainClass);
                template.add("package", packageString);
                createFile(project, null, "pom.xml", monitor, template);
                // create the log4J.properties
                template = projectSTG.getInstanceOf("log4J");
                template.add("package", packageString);
                template.add("mainClass", mainClass);
                createFile(project, srcMainJava, "log4j.properties", monitor, template);
                // create the .gitignore
                template = projectSTG.getInstanceOf("ignore");
                createFile(project, null, ".gitignore", monitor, template);
                // create the README
                template = projectSTG.getInstanceOf("readme");
                template.add("name", projectName);
                createFile(project, null, "README.md", monitor, template);
                // create package
                // create JUnit
                if (generateJUnit) {
                    IPackageFragment pack = javaProject.getPackageFragmentRoot(srcTestJava)
                            .createPackageFragment(packageString, false, null);
                    template = projectSTG.getInstanceOf("junit");
                    template.add("name", mainClass + "Test");
                    template.add("package", packageString);
                    template.add("classUnderTest", mainClass);
                    pack.createCompilationUnit(mainClass + "Test" + ".java", template.render(), false, monitor);
                }
                // create main class
                IPackageFragment pack = javaProject.getPackageFragmentRoot(srcMainJava)
                        .createPackageFragment(packageString, false, null);
                template = projectSTG.getInstanceOf("mainClass");
                template.add("name", mainClass);
                template.add("package", packageString);
                template.add("author", author);
                template.add("seedNode", seedNode);
                template.add("port", port);
                final ICompilationUnit cu = pack.createCompilationUnit(mainClass + ".java", template.render(),
                        false, monitor);
                // open editor on main class
                monitor.setTaskName("Opening file for editing...");
                getShell().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage();
                        try {
                            IEditorPart editor = IDE.openEditor(page, (IFile) cu.getResource(), true);
                        } catch (PartInitException e) {
                        }
                    }
                });

            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.aliyun.odps.eclipse.create.wizard.NewOdpsProjectWizard.java

License:Apache License

@Override
public boolean performFinish() {
    try {/*w  ww . j  av a  2  s .co  m*/
        PlatformUI.getWorkbench().getProgressService().runInUI(this.getContainer(),
                new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) {
                        try {
                            monitor.beginTask("Create ODPS Project", 300);

                            javaPage.getRunnable().run(new SubProgressMonitor(monitor, 100));

                            // if( firstPage.generateDriver.getSelection())
                            // {
                            // newDriverPage.setPackageFragmentRoot(javaPage.getNewJavaProject().getAllPackageFragmentRoots()[0],
                            // false);
                            // newDriverPage.getRunnable().run(new
                            // SubProgressMonitor(monitor,100));
                            // }

                            IProject project = javaPage.getNewJavaProject().getResource().getProject();
                            IProjectDescription description = project.getDescription();
                            String[] existingNatures = description.getNatureIds();
                            String[] natures = new String[existingNatures.length + 1];
                            for (int i = 0; i < existingNatures.length; i++) {
                                natures[i + 1] = existingNatures[i];
                            }

                            natures[0] = ProjectNature.NATURE_ID;
                            description.setNatureIds(natures);

                            project.setPersistentProperty(
                                    new QualifiedName(Activator.PLUGIN_ID, "ODPS.runtime.path"),
                                    firstPage.getCurrentConsolePath());
                            project.setDescription(description, new NullProgressMonitor());

                            String[] natureIds = project.getDescription().getNatureIds();
                            for (int i = 0; i < natureIds.length; i++) {
                                log.fine("Nature id # " + i + " > " + natureIds[i]);
                            }

                            try {
                                ProjectUtils.addODPSNature(project, monitor, firstPage.getCurrentConsolePath());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            monitor.worked(100);
                            monitor.done();

                            BasicNewProjectResourceWizard.updatePerspective(config);

                            loadOdpsProject();
                        } catch (CoreException e) {
                            // TODO Auto-generated catch block
                            log.log(Level.SEVERE, "CoreException thrown.", e);
                        } catch (InvocationTargetException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }, null);
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return true;
}