]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/ExperimentListener.java
6f5f6015782b9fa840a88306b754821f2f0984c0
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / ExperimentListener.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.simulation.ui;
13
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;
21
22 public class ExperimentListener implements IExperimentListener {
23
24     IContextActivation contextActivation;
25
26     @Override
27     public void stateChanged(final ExperimentState state) {
28         
29         if(!PlatformUI.isWorkbenchRunning()) return;   
30         
31         PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
32
33             @Override
34             public void run() {
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()); 
40                                 
41                 switch(state) {
42                 case RUNNING:
43                         //System.out.println("RUNNING");
44                         buttonState.setValue(true); 
45                     break;
46                 case STOPPED:
47                 default:
48                         //System.out.println("STOPPED");
49                         buttonState.setValue(false);
50                     break;
51                 }
52                 service.refreshElements(command.getId(), null); 
53                 
54                 /*IContextService contextService =
55                     (IContextService)PlatformUI.getWorkbench()
56                     .getActiveWorkbenchWindow().getService(IContextService.class);
57                 if(contextActivation != null)                                     
58                     contextService.deactivateContext(contextActivation);
59                 switch(state) {
60                 case RUNNING:
61                     contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentRunning");
62                     break;
63                 case STOPPED:
64                     contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentStopped");
65                     break;
66                 default:
67                     contextActivation = null;
68                     break;
69
70                 } */               
71             }
72             
73         });
74     }
75
76 }