]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
e4155b670233537d3c1a8abd940fef67ce865d08
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.handlers.simulationPlayback;\r
13 \r
14 import java.util.Map;\r
15 \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
26 \r
27 public class PlaybackResetHandler extends AbstractHandler implements IElementUpdater {\r
28 \r
29     public static final String COMMAND = "org.simantics.sysdyn.ui.playbackReset";\r
30 \r
31     \r
32     @Override\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
37             return null;\r
38         SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;\r
39         spe.resetPlayback();\r
40         return null;\r
41     }\r
42 \r
43     @SuppressWarnings("rawtypes")\r
44     @Override\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
50             return;\r
51         SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;      \r
52 \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
57         } else {\r
58             this.setBaseEnabled(true);\r
59         }\r
60 \r
61     }\r
62 \r
63 }\r