]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5357
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 2 Oct 2014 15:19:37 +0000 (15:19 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 2 Oct 2014 15:19:37 +0000 (15:19 +0000)
Preventing unexpected NPE from SaveHistoryHandler.execute()

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

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java

index f4a103c01add0d117ca383f0a0988ff1275954f3..dde222be1a25e9479333b0bd9012f71878b4a8eb 100644 (file)
@@ -20,6 +20,9 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
 import org.eclipse.jface.window.Window;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.MessageBox;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.PlatformUI;\r
 import org.simantics.Simantics;\r
@@ -45,7 +48,6 @@ import org.simantics.sysdyn.manager.MemoryResult;
 import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
 import org.simantics.sysdyn.manager.SysdynResult;\r
 import org.simantics.sysdyn.ui.utils.HandlerUtils;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.Pair;\r
        \r
 public class SaveHistoryHandler extends AbstractHandler {\r
@@ -55,7 +57,7 @@ public class SaveHistoryHandler extends AbstractHandler {
         HandlerUtils.saveBeforeExperimentRun(event);\r
         \r
         IExperimentManager manager = \r
-            SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+            Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
         IExperiment experiment = manager.getActiveExperiment();\r
         if(experiment instanceof SysdynGameExperimentBase) {\r
             final SysdynGameExperimentBase exp = (SysdynGameExperimentBase)experiment;\r
@@ -67,6 +69,15 @@ public class SaveHistoryHandler extends AbstractHandler {
                        if(r instanceof MemoryResult) {\r
                                MemoryResult gr = (MemoryResult)r;\r
                                SimulationResult sr = gr.getSimulationResult();\r
+                               if (sr == null) {\r
+                                   \r
+                                   MessageBox messageDialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_WARNING | SWT.OK);\r
+                                   messageDialog.setText("No Simulation History");\r
+                                   messageDialog.setMessage("There is no simulation history available, please simulate first!");\r
+\r
+                                   messageDialog.open();\r
+                                   return null;\r
+                               }\r
                                for(DataSet ds : sr.getVariableDataSets()) {\r
                                        map.put(ds, new Pair<String,ImageDescriptor>(ds.name, null));\r
                                }\r