X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.simulation.ui%2Fsrc%2Forg%2Fsimantics%2Fsimulation%2Fui%2Fhandlers%2Fe4%2FSaveState.java;h=89bdfbe7fae8e33954c998c59e623b719cafe79f;hp=ae4502d53ca7b7cc253545349ee68e9116bc8add;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/SaveState.java b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/SaveState.java index ae4502d53..89bdfbe7f 100644 --- a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/SaveState.java +++ b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/SaveState.java @@ -1,81 +1,81 @@ -/******************************************************************************* - * 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(); - } - } - } - -} +/******************************************************************************* + * 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(); + } + } + } + +}