1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.handlers.simulationPlayback;
\r
14 import java.util.Map;
\r
16 import org.eclipse.core.commands.AbstractHandler;
\r
17 import org.eclipse.core.commands.ExecutionEvent;
\r
18 import org.eclipse.core.commands.ExecutionException;
\r
19 import org.eclipse.ui.commands.IElementUpdater;
\r
20 import org.eclipse.ui.menus.UIElement;
\r
21 import org.simantics.simulation.experiment.ExperimentState;
\r
22 import org.simantics.simulation.experiment.IExperiment;
\r
23 import org.simantics.simulation.project.IExperimentManager;
\r
24 import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;
\r
25 import org.simantics.ui.SimanticsUI;
\r
27 public class PlaybackResetHandler extends AbstractHandler implements IElementUpdater {
\r
29 public static final String COMMAND = "org.simantics.sysdyn.ui.playbackReset";
\r
33 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
34 IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
35 IExperiment experiment = manager.getActiveExperiment();
\r
36 if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment))
\r
38 SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;
\r
39 spe.resetPlayback();
\r
43 @SuppressWarnings("rawtypes")
\r
45 public void updateElement(UIElement element, Map parameters) {
\r
46 IExperimentManager manager =
\r
47 SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
48 IExperiment experiment = manager.getActiveExperiment();
\r
49 if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment))
\r
51 SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;
\r
53 ExperimentState state = experiment.getState();
\r
54 if(state == ExperimentState.RUNNING && !spe.isPlaybackRunning()) {
\r
55 // RUNNING == simulation, not playback
\r
56 this.setBaseEnabled(false);
\r
58 this.setBaseEnabled(true);
\r