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);
}
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();
}
Aggregations