1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in 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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.simulation.ui;
\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
22 public class ExperimentListener implements IExperimentListener {
\r
24 IContextActivation contextActivation;
\r
27 public void stateChanged(final ExperimentState state) {
\r
29 if(!PlatformUI.isWorkbenchRunning()) return;
\r
31 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
\r
35 ICommandService service =
\r
36 (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
\r
37 Command command = service.getCommand("org.simantics.simulation.ui.run");
\r
38 State buttonState = command.getState("org.simantics.simulation.ui.run.state");
\r
39 buttonState.setValue(!(Boolean) buttonState.getValue());
\r
43 //System.out.println("RUNNING");
\r
44 buttonState.setValue(true);
\r
48 //System.out.println("STOPPED");
\r
49 buttonState.setValue(false);
\r
52 service.refreshElements(command.getId(), null);
\r
54 /*IContextService contextService =
\r
55 (IContextService)PlatformUI.getWorkbench()
\r
56 .getActiveWorkbenchWindow().getService(IContextService.class);
\r
57 if(contextActivation != null)
\r
58 contextService.deactivateContext(contextActivation);
\r
61 contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentRunning");
\r
64 contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentStopped");
\r
67 contextActivation = null;
\r