-/*******************************************************************************\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.e4;\r
-\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.core.runtime.jobs.Job;\r
-import org.eclipse.e4.core.di.annotations.CanExecute;\r
-import org.eclipse.e4.core.di.annotations.Execute;\r
-import org.simantics.ObjectIdentitySchedulingRule;\r
-import org.simantics.Simantics;\r
-import org.simantics.simulation.experiment.IDynamicExperiment;\r
-import org.simantics.simulation.experiment.IExperiment;\r
-import org.simantics.simulation.project.IExperimentManager;\r
-import org.simantics.simulation.ui.Activator;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class SaveState {\r
-\r
- @CanExecute\r
- public boolean canExecute() {\r
- IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
- if (manager == null)\r
- return false;\r
- IExperiment experiment = manager.getActiveExperiment();\r
- if (experiment == null)\r
- return false;\r
- return true;\r
- }\r
- \r
- @Execute\r
- public void execute() throws ExecutionException {\r
- IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
- IExperiment experiment = manager.getActiveExperiment();\r
- if (experiment instanceof IDynamicExperiment) {\r
- Job j = new SaveStateJob((IDynamicExperiment) experiment);\r
- j.setRule(new ObjectIdentitySchedulingRule(experiment));\r
- j.schedule();\r
- }\r
- }\r
-\r
- static class SaveStateJob extends Job {\r
- private final IDynamicExperiment experiment;\r
-\r
- public SaveStateJob(IDynamicExperiment experiment) {\r
- super("Save Experiment State");\r
- this.experiment = experiment;\r
- }\r
-\r
- @Override\r
- protected IStatus run(IProgressMonitor monitor) {\r
- try {\r
- monitor.beginTask("", IProgressMonitor.UNKNOWN);\r
- experiment.saveState();\r
- if (monitor.isCanceled())\r
- return Status.CANCEL_STATUS;\r
- return Status.OK_STATUS;\r
- } catch (Throwable t) {\r
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to save state of dynamic experiment "\r
- + experiment + " with ID " + experiment.getIdentifier(), t);\r
- } finally {\r
- //System.out.println("DONE");\r
- monitor.done();\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.simulation.ui.handlers.e4;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.simantics.ObjectIdentitySchedulingRule;
+import org.simantics.Simantics;
+import org.simantics.simulation.experiment.IDynamicExperiment;
+import org.simantics.simulation.experiment.IExperiment;
+import org.simantics.simulation.project.IExperimentManager;
+import org.simantics.simulation.ui.Activator;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class SaveState {
+
+ @CanExecute
+ public boolean canExecute() {
+ IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
+ if (manager == null)
+ return false;
+ IExperiment experiment = manager.getActiveExperiment();
+ if (experiment == null)
+ return false;
+ return true;
+ }
+
+ @Execute
+ public void execute() throws ExecutionException {
+ IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
+ IExperiment experiment = manager.getActiveExperiment();
+ if (experiment instanceof IDynamicExperiment) {
+ Job j = new SaveStateJob((IDynamicExperiment) experiment);
+ j.setRule(new ObjectIdentitySchedulingRule(experiment));
+ j.schedule();
+ }
+ }
+
+ static class SaveStateJob extends Job {
+ private final IDynamicExperiment experiment;
+
+ public SaveStateJob(IDynamicExperiment experiment) {
+ super("Save Experiment State");
+ this.experiment = experiment;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask("", IProgressMonitor.UNKNOWN);
+ experiment.saveState();
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+ return Status.OK_STATUS;
+ } catch (Throwable t) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to save state of dynamic experiment "
+ + experiment + " with ID " + experiment.getIdentifier(), t);
+ } finally {
+ //System.out.println("DONE");
+ monitor.done();
+ }
+ }
+ }
+
+}