]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/ExperimentListener.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / ExperimentListener.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.simulation.ui;\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 \r
22 public class ExperimentListener implements IExperimentListener {\r
23 \r
24     IContextActivation contextActivation;\r
25 \r
26     @Override\r
27     public void stateChanged(final ExperimentState state) {\r
28         \r
29         if(!PlatformUI.isWorkbenchRunning()) return;   \r
30         \r
31         PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
32 \r
33             @Override\r
34             public void run() {\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
40                                 \r
41                 switch(state) {\r
42                 case RUNNING:\r
43                         //System.out.println("RUNNING");\r
44                         buttonState.setValue(true); \r
45                     break;\r
46                 case STOPPED:\r
47                 default:\r
48                         //System.out.println("STOPPED");\r
49                         buttonState.setValue(false);\r
50                     break;\r
51                 }\r
52                 service.refreshElements(command.getId(), null); \r
53                 \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
59                 switch(state) {\r
60                 case RUNNING:\r
61                     contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentRunning");\r
62                     break;\r
63                 case STOPPED:\r
64                     contextActivation = contextService.activateContext("org.simantics.simulation.ui.experimentStopped");\r
65                     break;\r
66                 default:\r
67                     contextActivation = null;\r
68                     break;\r
69 \r
70                 } */               \r
71             }\r
72             \r
73         });\r
74     }\r
75 \r
76 }\r