]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
87bccb75605b90e79f08a2a58a25ef8ea621dd55
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010, 2012 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.listeners;\r
13 \r
14 import org.eclipse.core.commands.Command;\r
15 import org.eclipse.core.commands.State;\r
16 import org.eclipse.ui.PlatformUI;\r
17 import org.eclipse.ui.commands.ICommandService;\r
18 import org.eclipse.ui.contexts.IContextActivation;\r
19 import org.simantics.simulation.experiment.ExperimentState;\r
20 import org.simantics.simulation.experiment.IExperimentListener;\r
21 import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
22 import org.simantics.sysdyn.ui.handlers.ToggleSimulation;\r
23 import org.simantics.sysdyn.ui.handlers.game.ReloadGameExperimentHandler;\r
24 import org.simantics.sysdyn.ui.handlers.game.StepHandler;\r
25 import org.simantics.sysdyn.ui.handlers.simulationPlayback.PlaybackExperimentHandler;\r
26 import org.simantics.sysdyn.ui.handlers.simulationPlayback.PlaybackResetHandler;\r
27 \r
28 public class SysdynExperimentListener  implements IExperimentListener {\r
29 \r
30     IContextActivation contextActivation;\r
31 \r
32     @Override\r
33     public void stateChanged(final ExperimentState state) {\r
34         PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
35 \r
36             @Override\r
37             public void run() {\r
38                 ICommandService commandService =\r
39                     (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
40                 Command command = commandService.getCommand(ToggleSimulation.COMMAND);\r
41                 State buttonState = command.getState(ToggleSimulation.STATE);\r
42                                 \r
43                 switch(state) {\r
44                 case DISPOSED:\r
45                     buttonState.setValue(false); \r
46                     break;\r
47                 }\r
48                 commandService.refreshElements(command.getId(), null); \r
49                 commandService.refreshElements(RunBasicExperiment.COMMAND, null);\r
50                 commandService.refreshElements(PlaybackExperimentHandler.COMMAND, null);\r
51                 commandService.refreshElements(PlaybackResetHandler.COMMAND, null);\r
52                 commandService.refreshElements(StepHandler.COMMAND, null);\r
53                 commandService.refreshElements(ReloadGameExperimentHandler.COMMAND, null);\r
54             }\r
55             \r
56         });\r
57     }\r
58 \r
59 }\r