]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/Dispose.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / Dispose.java
diff --git a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/Dispose.java b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/Dispose.java
new file mode 100644 (file)
index 0000000..6712038
--- /dev/null
@@ -0,0 +1,61 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.simulation.ui.handlers;\r
+\r
+import java.lang.reflect.InvocationTargetException;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.SubMonitor;\r
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;\r
+import org.eclipse.jface.operation.IRunnableWithProgress;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.project.IProject;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class Dispose extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        IProject project = SimanticsUI.getProject();\r
+        IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        final IExperiment experiment = manager.getActiveExperiment();\r
+        if (experiment == null)\r
+            return null;\r
+\r
+        try {\r
+            new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, false, new IRunnableWithProgress() {\r
+                @Override\r
+                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {\r
+                    SubMonitor mon = SubMonitor.convert(monitor, "Shutdown experiment...", 10000);\r
+                    try {\r
+                        experiment.shutdown(mon.newChild(10000));\r
+                    } finally {\r
+                        monitor.done();\r
+                    }\r
+                }\r
+            });\r
+        } catch (InvocationTargetException e) {\r
+            ExceptionUtils.logAndShowError(e.getCause());\r
+        } catch (InterruptedException e) {\r
+            ExceptionUtils.logAndShowError(e.getCause());\r
+        }\r
+\r
+        return null;\r
+    }\r
+\r
+}\r