1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2012 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.listeners;
\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
28 public class SysdynExperimentListener implements IExperimentListener {
\r
30 IContextActivation contextActivation;
\r
33 public void stateChanged(final ExperimentState state) {
\r
34 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
\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
45 buttonState.setValue(false);
\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