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.ide.core.ui.preferences.ProjectNaturesPage.java

License:Open Source License

/**
 * Ask to reset the project (e.g. Close and Open) to apply the changes.
 *///from   w  w  w.  j a  va  2s . c o m
protected void resetProject() {
    boolean reset = MessageDialog.openQuestion(getControl().getShell(),
            EPLMessages.ProjectNaturesPage_ResetTitle, EPLMessages.ProjectNaturesPage_ResetMessage);
    if (reset) {
        IRunnableWithProgress close = new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                // Use the CloseResourceAction to provide a file saving dialog in case the project has some unsaved
                // files
                UIJob job = new UIJob(EPLMessages.ProjectNaturesPage_Job_CloseProject) {
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        CloseResourceAction closeAction = new CloseResourceAction(
                                Display.getDefault().getActiveShell());
                        closeAction.selectionChanged(new StructuredSelection(new Object[] { project }));
                        closeAction.run();
                        monitor.done();
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
                try {
                    job.join();
                } catch (InterruptedException e) {
                    IdeLog.logError(Activator.getDefault(), EPLMessages.ProjectNaturesPage_ERR_CloseProject, e);
                }
                monitor.done();
            }
        };
        try {
            // This will block until the progress is done
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, close);
        } catch (InterruptedException e) {
            // Ignore interrupted exceptions
        } catch (InvocationTargetException e) {
            handle(e);
        }

        IRunnableWithProgress open = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    project.open(monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            // This will block until the progress is done
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, open);
        } catch (InterruptedException e) {
            // Ignore interrupted exceptions
        } catch (InvocationTargetException e) {
            handle(e);
        }
    }
}

From source file:com.aptana.ide.editor.erb.wizards.ERBNewFileWizard.java

License:Open Source License

public boolean performFinish() {
    SimpleNewWizardPage page = (SimpleNewWizardPage) getPages()[0];
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();/*w  w  w  . j  a v  a2  s . c om*/
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), com.aptana.ide.editors.wizards.Messages.SimpleNewFileWizard_Error,
                realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.aptana.ide.editors.wizards.SimpleNewFileWizard.java

License:Open Source License

/**
 * This method is called when 'Finish' button is pressed in
 * the wizard. We will create an operation and run it
 * using wizard as execution context./* w  w  w .  ja  va 2  s .  c om*/
 * @return boolean
 */
public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, 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.SimpleNewFileWizard_Error, realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.aptana.ide.rcp.IDEWorkbenchAdvisor.java

License:Open Source License

/**
 * Disconnect from the core workspace.//from www  .  ja  v a2  s.  c  o  m
 */
private void disconnectFromWorkspace() {
    // save the workspace
    final MultiStatus status = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
            IDEWorkbenchMessages.ProblemSavingWorkbench, null);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            try {
                status.merge(ResourcesPlugin.getWorkspace().save(true, monitor));
            } catch (CoreException e) {
                status.merge(e.getStatus());
            }
        }
    };
    try {
        new ProgressMonitorJobsDialog(null).run(true, false, runnable);
    } catch (InvocationTargetException e) {
        status.merge(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
                IDEWorkbenchMessages.InternalError, e.getTargetException()));
    } catch (InterruptedException e) {
        status.merge(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
                IDEWorkbenchMessages.InternalError, e));
    }
    ErrorDialog.openError(null, IDEWorkbenchMessages.ProblemsSavingWorkspace, null, status,
            IStatus.ERROR | IStatus.WARNING);
    if (!status.isOK()) {
        IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ProblemsSavingWorkspace, status);
    }
}

From source file:com.aptana.ide.ui.ftp.dialogs.FTPConnectionPointPropertyDialog.java

License:Open Source License

public boolean testConnection(ConnectionContext context, final IConnectionRunnable connectRunnable) {
    // WORKAROUND: getting contents after the control is disabled will return empty string if not called here
    hostText.getText();/*from w  w  w  .j  av a 2s . com*/
    loginCombo.getText();
    passwordText.getText();
    remotePathText.getText();
    lockUI(true);
    ((GridData) progressMonitorPart.getLayoutData()).exclude = false;
    layoutShell();
    try {
        final IBaseRemoteConnectionPoint connectionPoint = isNew ? ftpConnectionPoint
                : (IBaseRemoteConnectionPoint) CoreIOPlugin.getConnectionPointManager()
                        .cloneConnectionPoint(ftpConnectionPoint);
        savePropertiesTo(connectionPoint);
        if (context == null) {
            context = new ConnectionContext();
            context.setBoolean(ConnectionContext.QUICK_CONNECT, true);
        }
        context.setBoolean(ConnectionContext.NO_PASSWORD_PROMPT, true);
        CoreIOPlugin.setConnectionContext(connectionPoint, context);

        ModalContext.run(new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    try {
                        if (connectRunnable != null) {
                            connectRunnable.beforeConnect(connectionPoint);
                        }
                        connectionPoint.connect(monitor);
                        if (connectRunnable != null) {
                            connectRunnable.afterConnect(connectionPoint, monitor);
                        }
                    } finally {
                        try {
                            connectionPoint.disconnect(monitor);
                        } catch (CoreException e) {
                            IdeLog.logImportant(Activator.getDefault(), StringUtils.EMPTY, e);
                        }
                    }
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        }, true, progressMonitorPart, getShell().getDisplay());

        return connectionTested = true;
    } catch (InterruptedException e) {
    } catch (InvocationTargetException e) {
        showErrorDialog(e.getTargetException());
    } catch (CoreException e) {
        showErrorDialog(e);
    } finally {
        if (!progressMonitorPart.isDisposed()) {
            ((GridData) progressMonitorPart.getLayoutData()).exclude = true;
            layoutShell();
            lockUI(false);
        }
    }
    return false;
}

From source file:com.aptana.ide.ui.io.properties.FileInfoPropertyPage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    // first try to adapt to IFileStore directly
    final IFileStore fileStore = Utils.getFileStore(getElement());
    if (fileStore == null) {
        Label label = new Label(parent, SWT.NONE);
        label.setText(IDEWorkbenchMessages.ResourceInfoPage_noResource);
        return label;
    }// ww w  .  j a  v a  2 s  . c om
    try {
        if (getElement().getAdapter(File.class) != null) {
            fFileInfo = fileStore.fetchInfo(EFS.NONE, new NullProgressMonitor());
        } else {
            final IFileInfo[] result = new IFileInfo[1];
            ProgressMonitorDialog dlg = new ProgressMonitorDialog(parent.getShell());
            try {
                dlg.run(true, true, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            result[0] = fileStore.fetchInfo(IExtendedFileStore.DETAILED, monitor);
                        } catch (CoreException e) {
                            throw new InvocationTargetException(e, e.getLocalizedMessage());
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (InvocationTargetException e) {
                throw (CoreException) e.getTargetException();
            } catch (InterruptedException e) {
                e.getCause();
            }
            fFileInfo = result[0];
        }
    } catch (CoreException e) {
        UIUtils.showErrorMessage(Messages.FileInfoPropertyPage_FailedToFetchInfo, e);
    }
    if (fFileInfo == null) {
        Label label = new Label(parent, SWT.NONE);
        label.setText(IDEWorkbenchMessages.ResourceInfoPage_noResource);
        return label;
    }

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.swtDefaults().margins(0, 0).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite basicInfo = createBasicInfoGroup(composite, fileStore, fFileInfo);
    basicInfo.setLayoutData(GridDataFactory.fillDefaults().create());

    Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite state = createStateGroup(composite, fileStore, fFileInfo);
    state.setLayoutData(GridDataFactory.fillDefaults().create());

    if (fFileInfo instanceof IExtendedFileInfo) {
        IExtendedFileInfo extendedInfo = (IExtendedFileInfo) fFileInfo;
        Composite owner = createOwnerGroup(composite, extendedInfo);
        owner.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 10).create());

        Composite permissions = createPermissionsGroup(composite, extendedInfo);
        permissions.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 5).create());

    }

    /*
     * TODO new Label(composite, SWT.NONE); // a vertical spacer encodingEditor = new EncodingFieldEditor("",
     * fileInfo.isDirectory() ? IDEWorkbenchMessages.ResourceInfo_fileEncodingTitle :
     * IDEWorkbenchMessages.WorkbenchPreference_encoding, composite); encodingEditor.setPreferenceStore(null);
     * encodingEditor.setPage(this); encodingEditor.load(); encodingEditor.setPropertyChangeListener(new
     * IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if
     * (event.getProperty().equals(FieldEditor.IS_VALID)) { setValid(encodingEditor.isValid()); } } }); if
     * (fileInfo.isDirectory()) { lineDelimiterEditor = new LineDelimiterEditor(composite, resource.getProject());
     * lineDelimiterEditor.doLoad(); }
     */

    Dialog.applyDialogFont(composite);

    return composite;
}

From source file:com.aptana.ide.update.eclipse36.P2Eclipse36PluginManager.java

License:Open Source License

private static IInstallableUnit[] getInstallationUnits(final IPlugin[] plugins, final String profileId)
        throws PluginManagerException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, plugins.length * 4);
            sub.setTaskName(P2Eclipse36Messages.P2PluginManager_Locating_selected_features_job_title);
            try {
                for (IPlugin plugin : plugins) {
                    URI siteURL = plugin.getURL().toURI();

                    IMetadataRepositoryManager manager = getMetadataRepositoryManager();
                    IMetadataRepository repo = manager.loadRepository(siteURL, sub.newChild(1));
                    if (repo == null) {
                        throw new ProvisionException(
                                P2Eclipse36Messages.P2PluginManager_ERR_MSG_Metadata_repo_not_found + siteURL);
                    }//www  . j a v a  2  s  . c om
                    if (!manager.isEnabled(siteURL)) {
                        manager.setEnabled(siteURL, true);
                    }

                    IArtifactRepositoryManager artifactManager = getArtifactRepositoryManager();
                    IArtifactRepository artifactRepo = artifactManager.loadRepository(siteURL, sub.newChild(1));
                    if (artifactRepo == null) {
                        throw new ProvisionException(
                                P2Eclipse36Messages.P2PluginManager_ERR_MSG_Artifact_repo_not_found + siteURL);
                    }
                    if (!artifactManager.isEnabled(siteURL)) {
                        artifactManager.setEnabled(siteURL, true);
                    }

                    IQuery<IInstallableUnit> query = QueryUtil.createIUQuery(getFeatureGroupName(plugin));
                    query = QueryUtil.createLatestQuery(query);
                    IQueryResult<IInstallableUnit> roots = repo.query(query, sub.newChild(2));

                    if (roots.isEmpty()) {
                        if (monitor.isCanceled()) {
                            return;
                        }

                        IProfile profile = getProfile(profileId);
                        if (profile == null) {
                            profile = getFirstProfile();
                        }
                        roots = profile.query(query, sub.newChild(2));
                    }
                    units.addAll(roots.toUnmodifiableSet());
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        throw new PluginManagerException(P2Eclipse36Messages.ProfileModificationAction_UnexpectedError,
                e.getCause());
    }
    return units.toArray(new IInstallableUnit[units.size()]);
}

From source file:com.aptana.ide.update.internal.manager.P2Eclipse35PluginManager.java

License:Open Source License

private static IInstallableUnit[] getInstallationUnits(final IPlugin[] plugins, final String profileId)
        throws PluginManagerException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, plugins.length * 4);
            sub.setTaskName(P2Eclipse35Messages.P2PluginManager_Locating_selected_features_job_title);
            try {
                for (IPlugin plugin : plugins) {
                    URI siteURL = plugin.getURL().toURI();

                    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(
                            P2Eclipse35Activator.getContext(), IMetadataRepositoryManager.class.getName());
                    IMetadataRepository repo = manager.loadRepository(siteURL, new NullProgressMonitor());
                    if (repo == null) {
                        throw new ProvisionException(
                                P2Eclipse35Messages.P2PluginManager_ERR_MSG_Metadata_repo_not_found + siteURL);
                    }//from w ww . j a  v a 2  s.  c o  m
                    if (!manager.isEnabled(siteURL)) {
                        manager.setEnabled(siteURL, true);
                    }
                    sub.worked(1);

                    IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) ServiceHelper
                            .getService(P2Eclipse35Activator.getContext(),
                                    IArtifactRepositoryManager.class.getName());
                    IArtifactRepository artifactRepo = artifactManager.loadRepository(siteURL,
                            new NullProgressMonitor());
                    if (artifactRepo == null) {
                        throw new ProvisionException(
                                P2Eclipse35Messages.P2PluginManager_ERR_MSG_Artifact_repo_not_found + siteURL);
                    }
                    if (!artifactManager.isEnabled(siteURL)) {
                        artifactManager.setEnabled(siteURL, true);
                    }
                    sub.worked(1);

                    InstallableUnitQuery query = new InstallableUnitQuery(getFeatureGroupName(plugin),
                            VersionRange.emptyRange);
                    Collector roots = repo.query(query, new LatestIUVersionCollector(), monitor);

                    if (roots.size() <= 0) {
                        if (monitor.isCanceled()) {
                            return;
                        }

                        IProfile profile = ProvisioningUtil.getProfile(profileId);
                        roots = profile.query(query, roots, monitor);
                    }
                    units.addAll(roots.toCollection());
                    sub.worked(2);
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        throw new PluginManagerException(P2Eclipse35Messages.ProfileModificationAction_UnexpectedError,
                e.getCause());
    }
    return units.toArray(new IInstallableUnit[units.size()]);
}

From source file:com.aptana.ide.update.internal.manager.P2PluginManager.java

private static IInstallableUnit[] getInstallationUnits(final IPlugin[] plugins, final String profileId)
        throws PluginManagerException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException

        {//from  w  ww .  j ava  2 s  .c  om
            SubMonitor sub = SubMonitor.convert(monitor, plugins.length * 4);
            sub.setTaskName(Messages.P2PluginManager_Locating_selected_features_job_title);
            try {
                for (int i = 0; i < plugins.length; i++) {
                    IPlugin plugin = plugins[i];
                    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper
                            .getService(P2Activator.getContext(), IMetadataRepositoryManager.class.getName());
                    IMetadataRepository repo = manager.loadRepository(plugin.getURL(),
                            new NullProgressMonitor());
                    if (repo == null) {
                        throw new ProvisionException(
                                Messages.P2PluginManager_ERR_MSG_Metadata_repo_not_found + plugin.getURL());
                    }
                    if (!manager.isEnabled(plugin.getURL()))
                        manager.setEnabled(plugin.getURL(), true);
                    sub.worked(1);

                    IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) ServiceHelper
                            .getService(P2Activator.getContext(), IArtifactRepositoryManager.class.getName());
                    IArtifactRepository artifactRepo = artifactManager.loadRepository(plugin.getURL(),
                            new NullProgressMonitor());
                    if (artifactRepo == null) {
                        throw new ProvisionException(
                                Messages.P2PluginManager_ERR_MSG_Artifact_repo_not_found + plugin.getURL());
                    }
                    if (!artifactManager.isEnabled(plugin.getURL()))
                        artifactManager.setEnabled(plugin.getURL(), true);
                    sub.worked(1);

                    InstallableUnitQuery query = new InstallableUnitQuery(getFeatureGroupName(plugin),
                            VersionRange.emptyRange);
                    Collector roots = repo.query(query, new LatestIUVersionCollector(), monitor);

                    if (roots.size() <= 0) {
                        if (monitor.isCanceled())
                            return;

                        IProfile profile = ProvisioningHelper.getProfile(profileId);
                        roots = profile.query(query, roots, monitor);
                    }
                    units.addAll(roots.toCollection());
                    sub.worked(2);
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        throw new PluginManagerException(Messages.ProfileModificationAction_UnexpectedError, e.getCause());
    }
    return units.toArray(new IInstallableUnit[units.size()]);
}

From source file:com.aptana.ide.update.internal.manager.P2PluginManager.java

private static ProvisioningPlan getInstallationProvisioningPlan(final IInstallableUnit[] ius,
        final String profileId) {
    final ProvisioningPlan[] plan = new ProvisioningPlan[1];
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            try {
                plan[0] = InstallAction.computeProvisioningPlan(ius, profileId, monitor);
            } catch (ProvisionException e) {
                ProvUI.handleException(e, Messages.ProfileModificationAction_UnexpectedError,
                        StatusManager.BLOCK | StatusManager.LOG);
            }/* w  w  w .jav a2s.c o m*/
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        ProvUI.handleException(e.getCause(), Messages.ProfileModificationAction_UnexpectedError,
                StatusManager.BLOCK | StatusManager.LOG);
    }
    return plan[0];
}