model = new DiagramModel(project);
final IDiagram modelRef = model;
// Creating the model
IProgressMonitor pm = Job.getJobManager().createProgressGroup();
pm.beginTask("Compute Model", IProgressMonitor.UNKNOWN);
final ILock lock = Job.getJobManager().newLock();
Job createModeJob = new Job("Create Model") {
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
lock.acquire();
// return ModelFactory.computeBottomUpDependenciesModel(modelRef, monitor);
return ModelFactory.computeModel(modelRef, dependenciesProvider, monitor);
} finally {
lock.release();
}
}
};
createModeJob.setUser(true);
createModeJob.setProgressGroup(pm, IProgressMonitor.UNKNOWN);
createModeJob.setThread(new Thread());
createModeJob.schedule();
// Creates job : Computing model connection's costs
final IDiagram workingModel = model;
Job simplifyModelJob = new Job("Simplify Model") {
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
lock.acquire();
// IStatus computePathCostSatus = Status.OK_STATUS;
IStatus computePathCostSatus = ModelFactory.computePathCost(workingModel, monitor);
if (!Status.OK_STATUS.equals(computePathCostSatus)) {
return computePathCostSatus;
}
IStatus editorStatus = null;
// Open Editor within UI thread.
if (Display.getCurrent() == null) {
// Not in UI Thread
class OpenEditor implements Runnable {
IStatus status;
public void run() {
status = openEditor(workingModel);
}
}
Display display = PlatformUI.getWorkbench().getDisplay();
OpenEditor openEditor = new OpenEditor();
display.syncExec(openEditor);
editorStatus = openEditor.status;
} else {
// In UI Thread
editorStatus = openEditor(workingModel);
}
monitor.done();
return editorStatus;
} finally {
lock.release();
}
}
};
simplifyModelJob.setUser(true);
simplifyModelJob.setProgressGroup(pm, IProgressMonitor.UNKNOWN);
simplifyModelJob.setThread(new Thread());
simplifyModelJob.schedule();
pm.done();
}