public void run()
{
final Shell shell = findDisplay().getActiveShell();
Job job = new Job("Resolving dependencies")
{
@Override
protected IStatus run(IProgressMonitor monitor)
{
monitor.beginTask("", IProgressMonitor.UNKNOWN);
List<IPackageImport> imports = JavaHelper.findRequiredImports(project,
monitor);
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (imports.isEmpty())
{
info(shell, "No new dependencies found");
}
else
{
Collections.sort(imports, new Comparator<IPackageImport>()
{
public int compare(IPackageImport o1, IPackageImport o2)
{
int i = o1.getPackageName().compareTo(o2.getPackageName());
// shouldn't get more than one import for same package
// but may as well sort if do...
if (i == 0)
{
i = o1.getVersions().getFloor().compareTo(
o2.getVersions().getFloor());
}
return i;
}
});
final ResourceReviewDialog<IPackageImport> dialog = new ResourceReviewDialog<IPackageImport>(
shell, "Review New Dependencies", imports);
shell.getDisplay().asyncExec(new Runnable()
{
public void run()
{
if (!review || dialog.open() == Window.OK)
{
WorkspaceModifyOperation op = new WorkspaceModifyOperation()
{
@Override
protected void execute(IProgressMonitor monitor)
throws CoreException
{
for (IPackageImport pi : dialog.getResources())
{
project.getBundle().getBundleInfo().addImport(
pi);
}
project.save(monitor);
}
};
SigilUI.runWorkspaceOperation(op, shell);
}
}
});
}
return Status.OK_STATUS;
}
};
job.schedule();
IProgressService p = PlatformUI.getWorkbench().getProgressService();
p.showInDialog(shell, job);
}