Search in sources :

Example 11 with UIJob

use of org.eclipse.ui.progress.UIJob in project bndtools by bndtools.

the class BndEditor method doAutoResolveOnSave.

private void doAutoResolveOnSave(IProgressMonitor monitor) {
    final Shell shell = getEditorSite().getShell();
    final IFile file = ResourceUtil.getFile(getEditorInput());
    if (file == null) {
        MessageDialog.openError(shell, "Resolution Error", "Unable to run resolution because the file is not in the workspace. NB.: the file will still be saved.");
        reallySave(monitor);
        return;
    }
    // Create resolver job and pre-validate
    final ResolveJob job = new ResolveJob(model);
    IStatus validation = job.validateBeforeRun();
    if (!validation.isOK()) {
        String message = "Unable to run the resolver. NB.: the file will still be saved.";
        ErrorDialog.openError(shell, "Resolution Validation Problem", message, validation, IStatus.ERROR | IStatus.WARNING);
        reallySave(monitor);
        return;
    }
    // Add operation to perform at the end of resolution (i.e. display
    // results and actually save the file)
    final UIJob completionJob = new UIJob(shell.getDisplay(), "Display Resolution Results") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            ResolutionResult result = job.getResolutionResult();
            ResolutionWizard wizard = new ResolutionWizard(model, file, result);
            if (result.getOutcome() != ResolutionResult.Outcome.Resolved) /*|| !result.getResolve().getOptionalResources().isEmpty() */
            {
                WizardDialog dialog = new WizardDialog(shell, wizard);
                if (dialog.open() != Window.OK) {
                    if (!wizard.performFinish()) {
                        MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
                    }
                }
            } else {
                if (!wizard.performFinish()) {
                    MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
                }
            }
            reallySave(monitor);
            return Status.OK_STATUS;
        }
    };
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            completionJob.schedule();
        }
    });
    // Start job
    job.setUser(true);
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ResolutionWizard(org.bndtools.core.resolve.ui.ResolutionWizard) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ResolveJob(org.bndtools.core.resolve.ResolveJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 UIJob (org.eclipse.ui.progress.UIJob)11 IStatus (org.eclipse.core.runtime.IStatus)3 GridData (org.eclipse.swt.layout.GridData)3 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)1 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)1 MalformedURLException (java.net.MalformedURLException)1 ResolutionResult (org.bndtools.core.resolve.ResolutionResult)1 ResolveJob (org.bndtools.core.resolve.ResolveJob)1 ResolutionWizard (org.bndtools.core.resolve.ui.ResolutionWizard)1 IFile (org.eclipse.core.resources.IFile)1 Job (org.eclipse.core.runtime.jobs.Job)1 Action (org.eclipse.jface.action.Action)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1