]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/Run.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / Run.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.handlers;\r
13 \r
14 import java.util.Map;\r
15 \r
16 import org.eclipse.core.commands.AbstractHandler;\r
17 import org.eclipse.core.commands.Command;\r
18 import org.eclipse.core.commands.ExecutionEvent;\r
19 import org.eclipse.core.commands.ExecutionException;\r
20 import org.eclipse.core.commands.State;\r
21 import org.eclipse.ui.PlatformUI;\r
22 import org.eclipse.ui.commands.ICommandService;\r
23 import org.eclipse.ui.commands.IElementUpdater;\r
24 import org.eclipse.ui.menus.UIElement;\r
25 import org.simantics.simulation.experiment.ExperimentUtil;\r
26 import org.simantics.simulation.ui.Activator;\r
27 \r
28 public class Run extends AbstractHandler implements IElementUpdater {\r
29 \r
30     @Override\r
31     public Object execute(ExecutionEvent event) throws ExecutionException {\r
32         ICommandService service =\r
33             (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
34         Command command = service.getCommand("org.simantics.simulation.ui.run");\r
35         State state = command.getState("org.simantics.simulation.ui.run.state");\r
36 \r
37         ExperimentUtil.simulate(!(Boolean)state.getValue());\r
38         return null;\r
39     }\r
40 \r
41     @SuppressWarnings("rawtypes")\r
42     @Override\r
43     public void updateElement(UIElement element, Map parameters) {\r
44         ICommandService commandService =\r
45             (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
46         Command command = commandService.getCommand("org.simantics.simulation.ui.run");\r
47         boolean checked = (Boolean) command.getState("org.simantics.simulation.ui.run.state").getValue();\r
48         element.setChecked(checked);\r
49         if (checked) {\r
50             element.setIcon(Activator.PAUSE_ICON);\r
51             element.setHoverIcon(Activator.PAUSE_HOVER_ICON);\r
52             element.setTooltip("Pause");\r
53         } else {\r
54             element.setIcon(Activator.PLAY_ICON);\r
55             element.setHoverIcon(Activator.PLAY_HOVER_ICON);\r
56             element.setTooltip("Run");\r
57         }\r
58     }\r
59 \r
60 }\r