From ae80099dba20409392bc3afcfa4ac21ed15f3d13 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 2 Oct 2014 15:19:37 +0000 Subject: [PATCH] refs #5357 Preventing unexpected NPE from SaveHistoryHandler.execute() git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30359 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/handlers/SaveHistoryHandler.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java index f4a103c0..dde222be 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveHistoryHandler.java @@ -20,6 +20,9 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.simantics.Simantics; @@ -45,7 +48,6 @@ import org.simantics.sysdyn.manager.MemoryResult; import org.simantics.sysdyn.manager.SysdynGameExperimentBase; import org.simantics.sysdyn.manager.SysdynResult; import org.simantics.sysdyn.ui.utils.HandlerUtils; -import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Pair; public class SaveHistoryHandler extends AbstractHandler { @@ -55,7 +57,7 @@ public class SaveHistoryHandler extends AbstractHandler { HandlerUtils.saveBeforeExperimentRun(event); IExperimentManager manager = - SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); IExperiment experiment = manager.getActiveExperiment(); if(experiment instanceof SysdynGameExperimentBase) { final SysdynGameExperimentBase exp = (SysdynGameExperimentBase)experiment; @@ -67,6 +69,15 @@ public class SaveHistoryHandler extends AbstractHandler { if(r instanceof MemoryResult) { MemoryResult gr = (MemoryResult)r; SimulationResult sr = gr.getSimulationResult(); + if (sr == null) { + + MessageBox messageDialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_WARNING | SWT.OK); + messageDialog.setText("No Simulation History"); + messageDialog.setMessage("There is no simulation history available, please simulate first!"); + + messageDialog.open(); + return null; + } for(DataSet ds : sr.getVariableDataSets()) { map.put(ds, new Pair(ds.name, null)); } -- 2.47.1