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:com.google.dart.tools.update.core.internal.jobs.InstallUpdateAction.java

License:Open Source License

private void applyUpdate() throws InvocationTargetException, InterruptedException {

    new ProgressMonitorDialog(getShell()) {
        @Override/*from ww  w. j  a  v a 2  s.  c o  m*/
        protected void configureShell(Shell shell) {
            shell.setText(UpdateJobMessages.InstallUpdateAction_progress_mon_title);
        }
    }.run(true, false, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                doApplyUpdate(monitor);
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            }
        }

    });
}

From source file:com.google.devtools.depan.platform.eclipse.ui.wizards.AbstractNewDocumentWizard.java

License:Apache License

/**
 * This method is called when 'Finish' button is pressed in the wizard.
 * The new document generation is performed in a separate thread.
 */// w w  w .j  a  v  a  2s .  co m
@Override
public boolean performFinish() {
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            performNewDocument(monitor);
        }
    };

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

From source file:com.google.eclipse.javascript.jstestdriver.ui.launch.config.JsTestDriverLaunchTab.java

License:Apache License

private void getConfigurationFiles(final IProject project, final GetConfigurationFilesCallback callback) {
    try {// w w  w. j a v a2s  . c  o  m
        PlatformUI.getWorkbench().getProgressService().run(true, false, new IRunnableWithProgress() {
            @SuppressWarnings("unused")
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Retrieving configuration files for " + project.getName(),
                        IProgressMonitor.UNKNOWN);
                synchronized (projectPathToAbsolutePath) {
                    projectPathToAbsolutePath.clear();
                    try {
                        projectPathToAbsolutePath.putAll(configurationProvider.getConfigurations(project));

                        Set<String> displayPaths = projectPathToAbsolutePath.keySet();
                        final String[] paths = displayPaths.toArray(new String[displayPaths.size()]);
                        Arrays.sort(paths);
                        monitor.done();
                        Display.getDefault().asyncExec(new Runnable() {
                            @Override
                            public void run() {
                                callback.done(paths);
                            }
                        });
                    } catch (CoreException e) {
                        IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString());
                        ErrorDialog.openError(Display.getCurrent().getActiveShell(), "JS Test Driver",
                                "JsTestDriver Error", status);
                    }
                }
            }
        });
    } catch (InvocationTargetException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
}

From source file:com.google.gdt.eclipse.designer.actions.deploy.DeployModuleAction.java

License:Open Source License

@Override
protected void runWithSelectedModule() throws Exception {
    final DeployDialog deployDialog = new DeployDialog(DesignerPlugin.getShell(), Activator.getDefault(),
            m_selectedModule);//from ww  w .j a v a  2s  .c  o  m
    if (deployDialog.open() != Window.OK) {
        return;
    }
    //
    IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask("Deployment of module '" + m_selectedModule.getId() + "'", 1);
                // create script
                {
                    monitor.worked(1);
                    createBuildScript(deployDialog);
                }
                // execute script
                {
                    IProject project = m_selectedModule.getProject();
                    IFolder targetFolder = m_selectedModule.getModuleFolder();
                    File buildFile = targetFolder.getFile("build.xml").getLocation().toFile();
                    AntHelper antHelper = new AntHelper(buildFile, project.getLocation().toFile());
                    antHelper.execute(monitor);
                }
            } catch (Throwable e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(DesignerPlugin.getShell());
    progressMonitorDialog.run(true, false, runnableWithProgress);
}

From source file:com.google.gdt.eclipse.gph.egit.wizard.CloneRepositoryWizardPage.java

License:Open Source License

protected IRunnableWithProgress createCloneRunnable() {
    final String repoStr = getCurrentRepo();
    final File parentDir = getDestinationDirectory();

    return new IRunnableWithProgress() {
        @Override//  w w w .j a  v a  2s. c o  m
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

            URIish urlish = null;

            try {
                urlish = new URIish(repoStr);
            } catch (URISyntaxException exception) {
                throw new InvocationTargetException(exception);
            }

            int timeout = org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore()
                    .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);

            CloneOperation cloneOperation = new CloneOperation(urlish, true, null, parentDir, null, // "refs/heads/trunk", "refs/heads/master"?
                    "origin", timeout);

            UserPasswordCredentials credentials = new UserPasswordCredentials(
                    wizard.getGPHProject().getUser().getUserName(),
                    wizard.getGPHProject().getUser().getRepoPassword());
            cloneOperation.setCredentialsProvider(
                    new UsernamePasswordCredentialsProvider(credentials.getUser(), credentials.getPassword()));

            cloneOperation.run(monitor);

            RepositoryUtil util = Activator.getDefault().getRepositoryUtil();

            util.addConfiguredRepository(cloneOperation.getGitDir());
        }
    };
}

From source file:com.google.gdt.eclipse.gph.egit.wizard.ImportProjectsWizardPage.java

License:Open Source License

/**
 * Update the list of projects based on path. Method declared public only for
 * test suite.//from   w w  w .j  av  a 2  s.  c o m
 * 
 * @param path
 */
public void updateProjectsList(final File directory) {
    // on an empty path empty selectedProjects
    if (directory == null || !directory.exists()) {
        setMessage("Invalid directory for the repository clone.");
        selectedProjects = new ProjectRecord[0];
        projectsList.refresh(true);
        projectsList.setCheckedElements(selectedProjects);
        setPageComplete(projectsList.getCheckedElements().length > 0);
        lastPath = directory;
        return;
    }

    long modified = directory.lastModified();

    if (directory.equals(lastPath) && lastModified == modified) {
        // since the file/folder was not modified and the path did not
        // change, no refreshing is required
        return;
    }

    lastPath = directory;
    lastModified = modified;

    try {
        getContainer().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Searching for projects", 100);
                selectedProjects = new ProjectRecord[0];
                Collection<File> files = new ArrayList<File>();
                monitor.worked(10);
                if (directory.isDirectory()) {

                    if (!collectProjectFilesFromDirectory(files, directory, null, monitor)) {
                        return;
                    }
                    Iterator<File> filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask("Processing results");
                    while (filesIterator.hasNext()) {
                        File file = filesIterator.next();
                        selectedProjects[index] = new ProjectRecord(file);
                        index++;
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }

        });
    } catch (InvocationTargetException e) {
        EGitCheckoutProviderPlugin.logError(e.getMessage(), e);
    } catch (InterruptedException e) {
        // Nothing to do if the user interrupts.
    }

    projectsList.refresh(true);
    ProjectRecord[] projects = getProjectRecords();
    boolean displayWarning = false;
    for (int i = 0; i < projects.length; i++) {
        if (projects[i].hasConflicts) {
            displayWarning = true;
            projectsList.setGrayed(projects[i], true);
        } else {
            projectsList.setChecked(projects[i], true);
        }
    }

    if (displayWarning) {
        setMessage("Some projects cannot be imported because they already exist in the workspace", WARNING);
    } else {
        setMessage("Select a directory to search for existing Eclipse projects.");
    }
    setPageComplete(projectsList.getCheckedElements().length > 0);
    if (selectedProjects.length == 0) {
        setMessage("No projects are found to import", WARNING);
    }
}

From source file:com.google.gdt.eclipse.gph.install.P2InstallerWizardPage.java

License:Open Source License

@Override
public boolean performFinish() {
    final IStatus[] status = new IStatus[1];

    try {/*from  w  w  w.ja v a2  s . c o  m*/
        getContainer().run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                status[0] = installManager.resolveP2Information(monitor);
            }
        });
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof OperationCanceledException) {
            return false;
        } else {
            ProjectHostingUIPlugin.logError(e);
            tellTheUserTheyreWedged(ProjectHostingUIPlugin.createStatus("Error during installation.", e));
            return false;
        }
    } catch (InterruptedException e) {
        return false;
    }

    if (status[0] != null) {
        if (status[0].getSeverity() == IStatus.CANCEL) {
            return false;
        } else if (!status[0].isOK()) {
            ProjectHostingUIPlugin.logStatus(status[0]);

            tellTheUserTheyreWedged(status[0]);

            return false;
        }
    }

    installManager.runP2Install();

    return true;
}

From source file:com.google.gdt.eclipse.gph.wizards.SelectHostedProjectWizardPage.java

License:Open Source License

private void populateProjectViewer() {
    final List<GPHProject> projects = new ArrayList<GPHProject>();

    try {/*w ww.j  a  v  a 2 s .  c om*/
        getWizard().getContainer().run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Connecting to Project Hosting...", IProgressMonitor.UNKNOWN);
                try {
                    retrieveProjects(projects);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });

        displayProjects(projects);
    } catch (InterruptedException ie) {
        // The user canceled.

    } catch (InvocationTargetException e) {
        Throwable target = e.getTargetException();

        if (target instanceof OperationCanceledException) {
            // ignore
        } else if (target instanceof CoreException) {
            ProjectHostingUIPlugin.logError(target);
            ErrorDialog.openError(getShell(), "Connection Error", "Unable to connect to Project Hosting.",
                    ((CoreException) target).getStatus());
        } else {
            ProjectHostingUIPlugin.logError(target);
            ErrorDialog.openError(getShell(), "Connection Error", "Unable to connect to Project Hosting.",
                    ProjectHostingUIPlugin.createStatus(target));
        }
    }
}

From source file:com.google.gdt.eclipse.managedapis.ui.ApiListingPage.java

License:Open Source License

private void doUpdateListing() {
    if (!updated) {
        updated = true;/*from  w w  w  .j  a  v a2 s.  com*/

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

        try {
            getContainer().run(true, true, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {

                    monitor.beginTask("Retrieving API listings...", IProgressMonitor.UNKNOWN);

                    // Can also pass the monitor into this method -
                    statusResult[0] = viewer.updateListing(new NullProgressMonitor());

                    monitor.done();
                }
            });

            if (statusResult[0] != null && !statusResult[0].isOK()) {
                ManagedApiPlugin.getDefault().getLog().log(statusResult[0]);

                setErrorMessage("Error contacting the API service");
            }
        } catch (InvocationTargetException e) {
            String message = e.getMessage();

            if (e.getCause() != null) {
                message = e.getCause().getMessage();
            }

            if (message == null) {
                setErrorMessage("Error contacting the API service");
            } else {
                setErrorMessage("Error contacting the API service: " + message);
            }
        } catch (InterruptedException e) {
            // The user canceled - close the dialog.
            ((WizardDialog) getContainer()).close();
        }
    }
}

From source file:com.google.gwt.eclipse.core.wizards.AbstractNewFileWizard.java

License:Open Source License

private IFile createNewFile() {
    // Get the file creation parameters
    final IPath newFilePath = getNormalizedFilePath();
    final IFile newFileHandle = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFile(newFilePath);
    final InputStream initialContents = getInitialContents();

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            CreateFileOperation op = new CreateFileOperation(newFileHandle, null, initialContents,
                    IDEWorkbenchMessages.WizardNewFileCreationPage_title);
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor,
                        WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(),
                                    IDEWorkbenchMessages.WizardNewFileCreationPage_errorTitle, null,
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            IDEWorkbenchPlugin.log(getClass(), "createNewFile()", e.getCause());
                            MessageDialog.openError(getContainer().getShell(),
                                    IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                                    NLS.bind(
                                            IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                                            e.getCause().getMessage()));
                        }// w  w w .  j a  v a  2  s. c  om
                    }
                });
            }
        }
    };
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // Execution Exceptions are handled above but we may still get
        // unexpected runtime errors.
        IDEWorkbenchPlugin.log(getClass(), "createNewFile()", e.getTargetException());
        MessageDialog.openError(getContainer().getShell(),
                IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                        e.getTargetException().getMessage()));

        return null;
    }

    return newFileHandle;
}