1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.simulation.ui;
14 import org.eclipse.core.commands.Command;
15 import org.eclipse.core.commands.State;
16 import org.eclipse.ui.PlatformUI;
17 import org.eclipse.ui.commands.ICommandService;
18 import org.eclipse.ui.contexts.IContextActivation;
19 import org.simantics.simulation.experiment.ExperimentState;
20 import org.simantics.simulation.experiment.IExperimentListener;
22 public class ExperimentListener implements IExperimentListener {
24 IContextActivation contextActivation;
27 public void stateChanged(final ExperimentState state) {
29 if(!PlatformUI.isWorkbenchRunning()) return;
31 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
35 ICommandService service =
36 (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
37 Command command = service.getCommand("org.simantics.simulation.ui.run");
38 State buttonState = command.getState("org.simantics.simulation.ui.run.state");
39 buttonState.setValue(!(Boolean) buttonState.getValue());
43 //System.out.println("RUNNING");
44 buttonState.setValue(true);
48 //System.out.println("STOPPED");
49 buttonState.setValue(false);
52 service.refreshElements(command.getId(), null);
54 /*IContextService contextService =
55 (IContextService)PlatformUI.getWorkbench()
56 .getActiveWorkbenchWindow().getService(IContextService.class);
57 if(contextActivation != null)
58 contextService.deactivateContext(contextActivation);
61 contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentRunning");
64 contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentStopped");
67 contextActivation = null;