]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
* Add the saved simulation results under the experiment _after_ the respective Record...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 22 Jan 2013 14:13:17 +0000 (14:13 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 22 Jan 2013 14:13:17 +0000 (14:13 +0000)
* Catching NPEs that are thrown if any "repeat" button is pressed consecutively (refs #4007).

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26663 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/HandlerUtils.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SaveResultJob.java

index 4482d14ac5baff6f1496caf7c65ff62728f753be..6d5497ed34675272ee6ee1d475ba5c0a814962d1 100644 (file)
@@ -1,6 +1,7 @@
 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
@@ -20,9 +21,17 @@ public class HandlerUtils {
      */\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
index 859bbc7a50deff3ab871edbff05bc055147c1ff9..04beb102d1a30d14b7f8993ec30cfa2ecf57b40c 100644 (file)
@@ -19,12 +19,14 @@ import org.eclipse.core.runtime.IStatus;
 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
@@ -40,6 +42,7 @@ public class SaveResultJob extends Job {
     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
@@ -54,10 +57,11 @@ public class SaveResultJob extends Job {
         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
@@ -67,7 +71,21 @@ public class SaveResultJob extends Job {
                     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
@@ -77,13 +95,9 @@ public class SaveResultJob extends Job {
                             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