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