1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.handlers.sensitivityAnalysis;
\r
15 import java.util.Map;
\r
17 import org.eclipse.core.commands.AbstractHandler;
\r
18 import org.eclipse.core.commands.Command;
\r
19 import org.eclipse.core.commands.ExecutionEvent;
\r
20 import org.eclipse.core.commands.ExecutionException;
\r
21 import org.eclipse.core.commands.State;
\r
22 import org.eclipse.ui.PlatformUI;
\r
23 import org.eclipse.ui.commands.ICommandService;
\r
24 import org.eclipse.ui.commands.IElementUpdater;
\r
25 import org.eclipse.ui.menus.UIElement;
\r
26 import org.simantics.simulation.experiment.IExperiment;
\r
27 import org.simantics.simulation.project.IExperimentManager;
\r
28 import org.simantics.sysdyn.manager.SysdynExperiment;
\r
29 import org.simantics.sysdyn.ui.utils.HandlerUtils;
\r
30 import org.simantics.ui.SimanticsUI;
\r
33 * Handle for the Toggle Simulation button. When the button is down, the
\r
34 * simulation is run every time the model is changed.
\r
35 * @author Tuomas Miettinen
\r
38 public class ToggleSimulation extends AbstractHandler implements IElementUpdater {
\r
40 public static final String COMMAND = "org.simantics.sysdyn.ui.toggleSensitivityAnalysisSimulation";
\r
41 public static final String STATE = "org.simantics.sysdyn.ui.toggleSensitivityAnalysisSimulation.state";
\r
44 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
45 // Current functionality is normal run experiment
\r
46 HandlerUtils.saveBeforeExperimentRun(event);
\r
48 ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
\r
49 Command command = service.getCommand(COMMAND);
\r
50 State state = command.getState(STATE);
\r
51 Boolean value = (Boolean) state.getValue();
\r
53 state.setValue(value);
\r
54 service.refreshElements(RunSensitivityAnalysisExperiment.COMMAND, null);
\r
56 IExperimentManager manager =
\r
57 SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
58 IExperiment experiment = manager.getActiveExperiment();
\r
59 if(experiment instanceof SysdynExperiment) {
\r
61 ((SysdynExperiment)experiment).toggleSimulation(true);
\r
63 ((SysdynExperiment)experiment).toggleSimulation(false);
\r
70 public static Boolean getState() {
\r
71 ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
\r
72 Command command = service.getCommand(COMMAND);
\r
73 State state = command.getState(STATE);
\r
74 return (Boolean)state.getValue();
\r
77 @SuppressWarnings("rawtypes")
\r
79 public void updateElement(UIElement element, Map parameters) {
\r
80 ICommandService commandService =
\r
81 (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
\r
82 Command command = commandService.getCommand(COMMAND);
\r
83 boolean checked = (Boolean) command.getState(STATE).getValue();
\r
84 element.setChecked(checked);
\r