this.mainWindow = mainWindow;
this.domain = model;
}
public void run() {
final Model problem = this.domain;
long solutionSleep = Long.parseLong(ConfigurationManager.settings.get("solution_sleep"));
//int lastState = problem.getState();
asyncRunnable = new Runnable() {
public void run() {
IStructuredSelection selection = (IStructuredSelection) mainWindow.getProblemBrowserTree().getTreeViewer().getSelection();
if (selection.getFirstElement() == problem) {
if (problem instanceof ResourceAllocation) {
mainWindow.getRAPerspective().setSummaryText(((ResourceAllocation)domain).getSummary());
((ResourceAllocation)problem).updateSummary();
}
}
// FIX: update only on Model state change
mainWindow.getProblemBrowserTree().getTreeViewer().update(problem, null);
}
};
while ((!this.domain.isSolved()) && (!this.domain.isFailed())) {
mainWindow.getShell().getDisplay().asyncExec(asyncRunnable);
if (stop) {
return;
}
try {
sleep(solutionSleep * 1000);
}
catch (Exception e) {
ClientLogManager.addClientLog("Exception in " + this.getName() + ":\n\t" + e.toString(), true);
}
}
try {
final String finalTextSolution = new String(domain.getSolution().get(domain.getName()));
final String log = new String(domain.getLog());
mainWindow.getShell().getDisplay().asyncExec(
new Runnable() {
public void run() {
IStructuredSelection selection =
(IStructuredSelection)mainWindow.getProblemBrowserTree().getTreeViewer().getSelection();
String success = "";
if (selection.getFirstElement() == problem) {
if (problem instanceof ResourceAllocation) {
ResourceAllocation raProblem = ((ResourceAllocation)problem);
ResourceAllocationPerspective perspective = mainWindow.getRAPerspective();
raProblem.setState(Model.ACKNOWLEDGED);
perspective.setSummaryText(raProblem.getSummary());
perspective.setSolutionText(finalTextSolution);
perspective.setSolutionTables((ResourceAllocation)problem);
perspective.setServerOutputText(log);
perspective.getAlgSelector().setEnabled(false);
perspective.getOptionsGroup().setEnabled(false);
}
}
if (!problem.isFailed()) {
success = "Excercise " + domain.getName()
+ " [#" + domain.getUniqueID() + "]" + " solved!";
}
else {
System.out.println("SHOULD NOT SEE ME: SolutionMonitorThread:95");
success = "Excercise " + domain.getName()
+ " [#" + domain.getUniqueID() + "]"+ " is failed to solve!";
}
ClientLogManager.addUserLog(success, (problem.isFailed() ? true: false));
mainWindow.getEventCentral().updateActionStates();
mainWindow.getProblemBrowserTree().getTreeViewer().refresh();
}