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.aptana.deploy.engineyard.ui.wizard.EngineYardDeployWizard.java

License:Open Source License

protected IRunnableWithProgress createEngineYardDeployRunnable(EngineYardDeployWizardPage page) {
    IRunnableWithProgress runnable;/*from w  w  w. j  av a  2  s.c  o m*/

    runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                public void run() {
                    CommandElement command;
                    command = getCommand(BUNDLE_ENGINEYARD, "Deploy App"); //$NON-NLS-1$
                    command.execute();
                }
            });
        }

    };
    return runnable;
}

From source file:com.aptana.deploy.ftp.ui.wizard.FTPDeployWizard.java

License:Open Source License

protected IRunnableWithProgress createFTPDeployRunnable(FTPDeployWizardPage page) {
    if (!page.completePage()) {
        return null;
    }/*from  w w w. ja  v  a 2  s . co m*/
    final IConnectionPoint destinationConnectionPoint = page.getConnectionPoint();
    final boolean isAutoSyncSelected = page.isAutoSyncSelected();
    final SyncDirection direction = page.getSyncDirection();
    final IWorkbenchPart activePart = UIUtils.getActivePart();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, 100);
            try {
                ISiteConnection site = null;
                ISiteConnection[] sites = SiteConnectionUtils.findSites(selectedContainer,
                        destinationConnectionPoint);
                if (sites.length == 0) {
                    // creates the site to link the project with the FTP connection
                    IConnectionPoint sourceConnectionPoint = SyncUtils
                            .findOrCreateConnectionPointFor(selectedContainer);
                    CoreIOPlugin.getConnectionPointManager().addConnectionPoint(sourceConnectionPoint);
                    site = SiteConnectionUtils.createSite(
                            MessageFormat.format("{0} <-> {1}", selectedContainer.getName(), //$NON-NLS-1$
                                    destinationConnectionPoint.getName()),
                            sourceConnectionPoint, destinationConnectionPoint);
                    SyncingPlugin.getSiteConnectionManager().addSiteConnection(site);
                } else if (sites.length == 1) {
                    // the site to link the project with the FTP connection already exists
                    site = sites[0];
                } else {
                    // multiple FTP connections are associated with the project; finds the last one
                    // try for last remembered site first
                    String lastConnection = DeployPreferenceUtil.getDeployEndpoint(selectedContainer);
                    if (lastConnection != null) {
                        site = SiteConnectionUtils.getSiteWithDestination(lastConnection, sites);
                    }
                }

                if (isAutoSyncSelected) {
                    BaseSyncAction action = null;
                    switch (direction) {
                    case UPLOAD:
                        action = new UploadAction();
                        break;
                    case DOWNLOAD:
                        action = new DownloadAction();
                        break;
                    case BOTH:
                        action = new SynchronizeProjectAction();
                    }
                    action.setActivePart(null, activePart);
                    action.setSelection(new StructuredSelection(selectedContainer));
                    action.setSelectedSite(site);
                    action.run(null);
                }
            } finally {
                sub.done();
            }
        }
    };
    return runnable;
}

From source file:com.aptana.deploy.heroku.ui.wizard.HerokuDeployWizard.java

License:Open Source License

protected IRunnableWithProgress createHerokuDeployRunnable(HerokuDeployWizardPage page) {
    IRunnableWithProgress runnable;/*w  w w .  j  a v a 2  s  .com*/
    final String appName = page.getAppName();
    final boolean publishImmediately = page.publishImmediately();

    // persists the auto-publish setting
    IEclipsePreferences prefs = (EclipseUtil.instanceScope()).getNode(HerokuPlugin.getPluginIdentifier());
    prefs.putBoolean(IPreferenceConstants.HEROKU_AUTO_PUBLISH, publishImmediately);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
    }

    runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, 100);
            try {
                // Initialize git repo for project if necessary
                IGitRepositoryManager manager = GitPlugin.getDefault().getGitRepositoryManager();
                GitRepository repo = manager.createOrAttach(getProject(), sub.newChild(20));
                // TODO What if we didn't create the repo right now, but it is "dirty"?
                // Now do an initial commit
                repo.index().refresh(sub.newChild(15));
                repo.index().stageFiles(repo.index().changedFiles());
                repo.index().commit(Messages.DeployWizard_AutomaticGitCommitMessage);
                sub.worked(10);

                // Run commands to create/deploy
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    public void run() {
                        CommandElement command;
                        if (publishImmediately) {
                            command = getCommand(BUNDLE_HEROKU, "Create and Deploy App"); //$NON-NLS-1$
                        } else {
                            command = getCommand(BUNDLE_HEROKU, "Create App"); //$NON-NLS-1$
                        }
                        // TODO What if command is null!?
                        if (command != null) {
                            // Send along the app name
                            CommandContext context = command.createCommandContext();
                            context.put("HEROKU_APP_NAME", appName); //$NON-NLS-1$
                            command.execute(context);
                        }
                    }
                });
            } catch (CoreException ce) {
                throw new InvocationTargetException(ce);
            } finally {
                sub.done();
            }
        }

    };
    return runnable;
}

From source file:com.aptana.deploy.heroku.ui.wizard.HerokuDeployWizard.java

License:Open Source License

protected IRunnableWithProgress createHerokuSignupRunnable(HerokuSignupPage page) {
    IRunnableWithProgress runnable;//w ww  .  j a  v  a 2 s. c  o  m
    final String userID = page.getUserID();
    runnable = new IRunnableWithProgress() {

        /**
         * Send a ping to aptana.com with email address for referral tracking
         * 
         * @throws IOException
         */
        private String sendPing(IProgressMonitor monitor) throws IOException {
            HttpURLConnection connection = null;
            try {
                final String HOST = "http://toolbox.aptana.com"; //$NON-NLS-1$
                StringBuilder builder = new StringBuilder(HOST);
                builder.append("/webhook/heroku?request_id="); //$NON-NLS-1$
                builder.append(URLEncoder.encode(PingStartup.getApplicationId(), IOUtil.UTF_8));
                builder.append("&email="); //$NON-NLS-1$
                builder.append(URLEncoder.encode(userID, IOUtil.UTF_8));
                builder.append("&type=signuphook"); //$NON-NLS-1$

                URL url = new URL(builder.toString());
                connection = (HttpURLConnection) url.openConnection();
                connection.setUseCaches(false);
                connection.setAllowUserInteraction(false);
                int responseCode = connection.getResponseCode();
                if (responseCode != HttpURLConnection.HTTP_OK) {
                    // Log an error
                    IdeLog.logError(HerokuPlugin.getDefault(), MessageFormat.format(
                            Messages.DeployWizard_FailureToGrabHerokuSignupJSError, builder.toString()));
                } else {
                    return IOUtil.read(connection.getInputStream());
                }
            } finally {
                if (connection != null) {
                    connection.disconnect();
                }
            }
            return ""; //$NON-NLS-1$
        }

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, 100);
            try {
                String javascriptToInject = sendPing(sub.newChild(40));
                openSignup(javascriptToInject, sub.newChild(60));
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }

        /**
         * Open the Heroku signup page.
         * 
         * @param monitor
         * @throws Exception
         */
        private void openSignup(final String javascript, IProgressMonitor monitor) throws Exception {
            final String BROWSER_ID = "heroku-signup"; //$NON-NLS-1$
            final URL url = new URL("https://api.heroku.com/signup/aptana3"); //$NON-NLS-1$

            final int style = IWorkbenchBrowserSupport.NAVIGATION_BAR | IWorkbenchBrowserSupport.LOCATION_BAR
                    | IWorkbenchBrowserSupport.STATUS;
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    openSignupURLinEclipseBrowser(url, style, BROWSER_ID, javascript);
                }
            });
        }
    };
    return runnable;
}

From source file:com.aptana.editor.js.preferences.NodePreferencePage.java

License:Open Source License

private void downloadNodeJS() {
    final ProgressMonitorDialog downloadProgressMonitor = new ProgressMonitorDialog(UIUtils.getActiveShell());
    try {//from  w ww  .  ja v a2s  .c  o m
        downloadProgressMonitor.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    final INodeJS node = getDetectedPath();
                    IStatus status = node.downloadSource(monitor);
                    if (status.isOK()) {
                        // Set the path in the editor field
                        Control control = NodePreferencePage.this.getControl();
                        if (control != null && !control.isDisposed()) {
                            UIUtils.runInUIThread(new Runnable() {

                                public void run() {
                                    sourceEditor.setStringValue(node.getSourcePath().toOSString());
                                }
                            });
                        }

                    }
                } catch (Exception e) {
                    IdeLog.logError(JSPlugin.getDefault(), "Error while downloading NodeJS sources", e); //$NON-NLS-1$
                }

            }
        });
    } catch (Exception e) {
        IdeLog.logError(JSPlugin.getDefault(), e);
    }
    // setStringValue(value)
}

From source file:com.aptana.git.ui.internal.preferences.GithubAccountPageProvider.java

License:Open Source License

private boolean login(boolean test) {
    final String username = usernameText.getText();
    final String password = passwordText.getText();
    if (StringUtil.isEmpty(username)) {
        if (test) {
            MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_InvalidInputTitle,
                    Messages.GithubAccountPageProvider_EmptyUsername);
            return false;
        }/*from  www. j a  v  a 2s.  c o  m*/
        return true;
    }
    if (StringUtil.isEmpty(password)) {
        if (test) {
            MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_InvalidInputTitle,
                    Messages.GithubAccountPageProvider_EmptyPassword);
            return false;
        }
        return true;
    }

    setUILocked(true);
    firePreValidationStartEvent();
    try {
        ModalContext.run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.GithubAccountPageProvider_ValidatingCredentials,
                        IProgressMonitor.UNKNOWN);
                try {
                    IStatus status = getGithubManager().login(username, password);
                    if (status.isOK()) {
                        // successful; now re-layout to show the logout components
                        UIUtils.getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                updateUserText();
                                layout();
                            }
                        });
                        fireLoggedInEvent();
                    } else {
                        throw new InvocationTargetException(new CoreException(status));
                    }
                } finally {
                    if (!monitor.isCanceled()) {
                        monitor.done();
                    }
                }
            }
        }, true, getProgressMonitor(), UIUtils.getDisplay());
    } catch (InvocationTargetException e) {
        if (main != null && !main.isDisposed()) {
            MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_LoginFailed,
                    e.getTargetException().getMessage());
        }
        return false;
    } catch (Exception e) {
        IdeLog.logError(GitUIPlugin.getDefault(), e);
    } finally {
        setUILocked(false);
        firePostValidationEndEvent();
    }

    return true;
}

From source file:com.aptana.git.ui.internal.sharing.SharingWizard.java

License:Open Source License

public boolean performFinish() {
    final ConnectProviderOperation op = new ConnectProviderOperation(existingPage.getProjects());
    try {/*w  w  w.jav  a  2s  . c  o m*/
        getContainer().run(true, false, new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    op.run(monitor);
                } catch (CoreException ce) {
                    throw new InvocationTargetException(ce);
                }
            }
        });
        return true;
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            e = e.getCause();
        }
        final IStatus status;
        if (e instanceof CoreException) {
            status = ((CoreException) e).getStatus();
            e = status.getException();
        } else {
            status = new Status(IStatus.ERROR, GitPlugin.getPluginId(), 1, Messages.SharingWizard_failed, e);
        }
        IdeLog.logError(GitUIPlugin.getDefault(), Messages.SharingWizard_failed, e, IDebugScopes.DEBUG);
        ErrorDialog.openError(getContainer().getShell(), getWindowTitle(), Messages.SharingWizard_failed,
                status, status.getSeverity());
        return false;
    }
}

From source file:com.aptana.git.ui.internal.wizards.CloneWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final String sourceURI = cloneSource.getSource();
    final String dest = cloneSource.getDestination();
    try {//ww  w.  j a  v a 2 s. com
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                CloneJob job = new CloneJob(sourceURI, dest);
                IStatus status = job.run(monitor);
                if (!status.isOK()) {
                    if (status instanceof ProcessStatus) {
                        ProcessStatus ps = (ProcessStatus) status;
                        String stderr = ps.getStdErr();
                        throw new InvocationTargetException(new CoreException(
                                new Status(status.getSeverity(), status.getPlugin(), stderr)));
                    }
                    throw new InvocationTargetException(new CoreException(status));
                }
            }
        });
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            CoreException ce = (CoreException) e.getCause();
            MessageDialog.openError(getShell(), Messages.CloneWizard_CloneFailedTitle, ce.getMessage());
        } else {
            IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
        }
    } catch (InterruptedException e) {
        IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
    }
    return true;
}

From source file:com.aptana.git.ui.internal.wizards.GithubForkWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final IGithubManager ghManager = GitPlugin.getDefault().getGithubManager();
    final String owner = cloneSource.getOwner();
    final String repoName = cloneSource.getRepoName();
    // TODO Allow selecting a destination org to fork to!
    final String organization = null; // cloneSource.getOrganization();
    final String dest = cloneSource.getDestination();
    try {// w  w w.  j a va  2 s.  c o m
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.subTask(Messages.GithubForkWizard_ForkSubTaskName);
                    IGithubRepository repo = ghManager.fork(owner, repoName, organization);

                    // Now clone the repo!
                    CloneJob job = new CloneJob(repo.getSSHURL(), dest);
                    IStatus status = job.run(monitor);
                    if (!status.isOK()) {
                        if (status instanceof ProcessStatus) {
                            ProcessStatus ps = (ProcessStatus) status;
                            String stderr = ps.getStdErr();
                            throw new InvocationTargetException(new CoreException(
                                    new Status(status.getSeverity(), status.getPlugin(), stderr)));
                        }
                        throw new InvocationTargetException(new CoreException(status));
                    }

                    // Add upstream remote pointing at parent!
                    Set<IProject> projects = job.getCreatedProjects();
                    if (!CollectionsUtil.isEmpty(projects)) {
                        monitor.subTask(Messages.GithubForkWizard_UpstreamSubTaskName);
                        IProject project = projects.iterator().next();
                        IGitRepositoryManager grManager = GitPlugin.getDefault().getGitRepositoryManager();
                        GitRepository clonedRepo = grManager.getAttached(project);
                        if (clonedRepo != null) {
                            IGithubRepository parentRepo = repo.getParent();
                            clonedRepo.addRemote("upstream", parentRepo.getSSHURL(), false); //$NON-NLS-1$
                        }
                    }
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            CoreException ce = (CoreException) e.getCause();
            MessageDialog.openError(getShell(), Messages.GithubForkWizard_FailedForkErr, ce.getMessage());
        } else {
            IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
        }
    } catch (InterruptedException e) {
        IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
    }
    return true;
}

From source file:com.aptana.ide.core.ui.preferences.ProjectNaturesPage.java

License:Open Source License

/**
 * @see PreferencePage#performOk/*  ww w .j a v  a2 s  . c  o m*/
 */
public boolean performOk() {
    if (!modified && !isPrimaryModified()) {
        return true;
    }
    // get checked natures
    Object[] checked = listViewer.getCheckedElements();
    final ArrayList<String> natureIds = new ArrayList<String>();
    for (int i = 0; i < checked.length; i++) {
        if (checked[i] instanceof String) {
            natureIds.add(checked[i].toString());
        } else {
            handle(new InvocationTargetException(
                    new IllegalStateException(NLS.bind("invalid element \"{0}\" in nature list", checked[i])))); //$NON-NLS-1$
            return false;
        }
    }
    // Locate and promote the primary item to the top of the list
    natureIds.remove(primaryNature);
    if (primaryNature != null) {
        natureIds.add(0, primaryNature);
    }

    // set nature ids
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                IProjectDescription description = project.getDescription();
                description.setNatureIds(natureIds.toArray(new String[natureIds.size()]));
                // Use IResource.AVOID_NATURE_CONFIG to avoid any warning about the natures.
                // We have to use it since not all of the Natures that are defined in the system
                // are valid and some are forced into the project in a non-standard way.
                project.setDescription(description, IResource.AVOID_NATURE_CONFIG, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        // This will block until the progress is done
        new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // Ignore interrupted exceptions
    } catch (InvocationTargetException e) {
        handle(e);
        return false;
    }
    resetProject();
    return true;
}