package org.simantics.sysdyn.ui.utils;\r
\r
import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Control;\r
import org.eclipse.swt.widgets.Event;\r
\r
*/\r
public static void acquireFocus(ExecutionEvent event) {\r
if (event.getTrigger() instanceof Event) {\r
- Event trigger = (Event)event.getTrigger();\r
- Control focusControl = trigger.display.getFocusControl();\r
- focusControl.getParent().forceFocus();\r
+ try {\r
+ Event trigger = (Event)event.getTrigger();\r
+ Control focusControl = trigger.display.getFocusControl();\r
+ Composite parent = focusControl.getParent();\r
+ parent.forceFocus();\r
+ } catch (NullPointerException e) {\r
+ // Consecutive getParent.forceFocus()'s cause NullPointerException,\r
+ // if there has been no action on UI between. I don't see many cases\r
+ // where this is an issue and the NPEs are not critical and are thus\r
+ // ignored. \r
+ }\r
}\r
}\r
}\r
import org.eclipse.core.runtime.Platform;\r
import org.eclipse.core.runtime.Status;\r
import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteResultRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
private final SysdynExperiment experiment;\r
private final Session session;\r
private IProgressMonitor monitor;\r
+ private File file;\r
\r
public SaveResultJob(final SysdynExperiment experiment, Session session, final SysdynResult result) {\r
super("Save Result");\r
int resultItemsNumber = sysdynResult.numberOfVariables();\r
monitor.beginTask("Save result", resultItemsNumber * 2); \r
try {\r
- File file = session.syncRequest(new WriteResultRequest<File>() {\r
+ // Create result file\r
+ file = session.syncRequest(new Read<File>() {\r
\r
@Override\r
- public File perform(WriteGraph graph) throws DatabaseException {\r
+ public File perform(ReadGraph graph) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
Resource model = graph.getSingleObject(experiment.getResource(), l0.PartOf);\r
Resource project = graph.getSingleObject(model, l0.PartOf);\r
File projectRoot = new File(root, projectName);\r
if(!projectRoot.isDirectory()) projectRoot.mkdir();\r
File file = new File( projectRoot, UUID.randomUUID().toString() + ".dbb");\r
+ return file;\r
+ }\r
+ });\r
\r
+ // Start the saving operation\r
+ Thread saveThread = experiment.getSaveThread(sysdynResult, file, SaveResultJob.this.monitor);\r
+ saveThread.run();\r
+ \r
+ // Add the result under the experiment within the model browser. \r
+ session.syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource model = graph.getSingleObject(experiment.getResource(), l0.PartOf);\r
String name = NameUtils.findFreshName(graph, "Result", model, l0.ConsistsOf, "%s%d");\r
\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
l0.PartOf, model,\r
sr.Result_resultFile, file.getAbsolutePath());\r
graph.claim(experiment.getResource(), sr.Experiment_result, res);\r
- \r
- return file;\r
}\r
});\r
- // Start the saving operation\r
- Thread saveThread = experiment.getSaveThread(sysdynResult, file, SaveResultJob.this.monitor);\r
- saveThread.run();\r
+\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
} catch (Exception e) {\r