1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.simulation.ui.handlers.e4;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.core.runtime.jobs.Job;
19 import org.eclipse.e4.core.di.annotations.CanExecute;
20 import org.eclipse.e4.core.di.annotations.Execute;
21 import org.simantics.ObjectIdentitySchedulingRule;
22 import org.simantics.Simantics;
23 import org.simantics.simulation.experiment.IDynamicExperiment;
24 import org.simantics.simulation.experiment.IExperiment;
25 import org.simantics.simulation.project.IExperimentManager;
26 import org.simantics.simulation.ui.Activator;
29 * @author Tuukka Lehtonen
31 public class SaveState {
34 public boolean canExecute() {
35 IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
38 IExperiment experiment = manager.getActiveExperiment();
39 if (experiment == null)
45 public void execute() throws ExecutionException {
46 IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
47 IExperiment experiment = manager.getActiveExperiment();
48 if (experiment instanceof IDynamicExperiment) {
49 Job j = new SaveStateJob((IDynamicExperiment) experiment);
50 j.setRule(new ObjectIdentitySchedulingRule(experiment));
55 static class SaveStateJob extends Job {
56 private final IDynamicExperiment experiment;
58 public SaveStateJob(IDynamicExperiment experiment) {
59 super("Save Experiment State");
60 this.experiment = experiment;
64 protected IStatus run(IProgressMonitor monitor) {
66 monitor.beginTask("", IProgressMonitor.UNKNOWN);
67 experiment.saveState();
68 if (monitor.isCanceled())
69 return Status.CANCEL_STATUS;
70 return Status.OK_STATUS;
71 } catch (Throwable t) {
72 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to save state of dynamic experiment "
73 + experiment + " with ID " + experiment.getIdentifier(), t);
75 //System.out.println("DONE");