Search in sources :

Example 1 with ResolutionWizard

use of org.bndtools.core.resolve.ui.ResolutionWizard in project bndtools by bndtools.

the class BndEditor method resolveRunBundles.

public Promise<IStatus> resolveRunBundles(IProgressMonitor monitor, boolean onSave) {
    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.");
        reallySave(monitor);
        return Central.promiseFactory().resolved(Status.CANCEL_STATUS);
    }
    Job loadWorkspaceJob = new Job("Loading workspace...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            if (monitor == null)
                monitor = new NullProgressMonitor();
            monitor.beginTask("Loading workspace", 2);
            try {
                Central.getWorkspace();
                monitor.worked(1);
                modelReady.getValue();
                return Status.OK_STATUS;
            } catch (Exception e) {
                return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to initialize workspace.", e);
            } finally {
                monitor.done();
            }
        }
    };
    final UIJob runResolveInUIJob = new UIJob("Resolve") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            // dirty state to the model
            for (Object pageObj : pages) {
                if (pageObj instanceof IFormPage) {
                    IFormPage formPage = (IFormPage) pageObj;
                    IManagedForm form = formPage.getManagedForm();
                    if (form != null) {
                        IFormPart[] formParts = form.getParts();
                        for (IFormPart formPart : formParts) {
                            if (formPart.isDirty())
                                formPart.commit(false);
                        }
                    }
                }
            }
            if (sourcePage.isActive() && sourcePage.isDirty()) {
                sourcePage.commit(false);
            }
            // Create resolver job and pre-validate
            final ResolveJob job = new ResolveJob(model);
            IStatus validation = job.validateBeforeRun();
            if (!validation.isOK()) {
                if (onSave)
                    reallySave(monitor);
                return validation;
            }
            // 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 (onSave) {
                        // We are in auto-resolve-on-save, only show the dialog if there is a problem
                        wizard.setAllowFinishUnresolved(true);
                        wizard.setPreserveRunBundlesUnresolved(true);
                        if (result.getOutcome() != ResolutionResult.Outcome.Resolved) {
                            WizardDialog dialog = new DuringSaveWizardDialog(shell, wizard);
                            dialog.create();
                            dialog.setErrorMessage("Resolve Failed! Saving now will not update the Run Bundles.");
                            if (dialog.open() == Window.OK)
                                reallySave(monitor);
                        } else {
                            wizard.performFinish();
                            reallySave(monitor);
                        }
                    } else {
                        // This is an interactive resolve, always show the dialog
                        boolean dirtyBeforeResolve = isDirty();
                        WizardDialog dialog = new WizardDialog(shell, wizard);
                        if (dialog.open() == Window.OK && !dirtyBeforeResolve) {
                            // save changes immediately if there were no unsaved changes before the resolve
                            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();
            return Status.OK_STATUS;
        }
    };
    runResolveInUIJob.setUser(true);
    return JobUtil.chainJobs(loadWorkspaceJob, runResolveInUIJob);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ResolutionWizard(org.bndtools.core.resolve.ui.ResolutionWizard) IManagedForm(org.eclipse.ui.forms.IManagedForm) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IFormPage(org.eclipse.ui.forms.editor.IFormPage) ResolveJob(org.bndtools.core.resolve.ResolveJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) PartInitException(org.eclipse.ui.PartInitException) BadLocationException(aQute.bnd.properties.BadLocationException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFormPart(org.eclipse.ui.forms.IFormPart) UIJob(org.eclipse.ui.progress.UIJob) Job(org.eclipse.core.runtime.jobs.Job) ResolveJob(org.bndtools.core.resolve.ResolveJob) UIJob(org.eclipse.ui.progress.UIJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 2 with ResolutionWizard

use of org.bndtools.core.resolve.ui.ResolutionWizard 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

ResolutionResult (org.bndtools.core.resolve.ResolutionResult)2 ResolveJob (org.bndtools.core.resolve.ResolveJob)2 ResolutionWizard (org.bndtools.core.resolve.ui.ResolutionWizard)2 IFile (org.eclipse.core.resources.IFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 UIJob (org.eclipse.ui.progress.UIJob)2 BadLocationException (aQute.bnd.properties.BadLocationException)1 IOException (java.io.IOException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 PartInitException (org.eclipse.ui.PartInitException)1 IFormPart (org.eclipse.ui.forms.IFormPart)1 IManagedForm (org.eclipse.ui.forms.IManagedForm)1