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.handlers;
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;
28 public class Run extends AbstractHandler implements IElementUpdater {
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");
37 ExperimentUtil.simulate(!(Boolean)state.getValue());
41 @SuppressWarnings("rawtypes")
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);
50 element.setIcon(Activator.PAUSE_ICON);
51 element.setHoverIcon(Activator.PAUSE_HOVER_ICON);
52 element.setTooltip("Pause");
54 element.setIcon(Activator.PLAY_ICON);
55 element.setHoverIcon(Activator.PLAY_HOVER_ICON);
56 element.setTooltip("Run");