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;
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.Command;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.jface.dialogs.InputDialog;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.commands.ICommandService;
21 import org.osgi.service.prefs.BackingStoreException;
22 import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
23 import org.simantics.simulation.ui.preferences.SimulationPreferences;
24 import org.simantics.utils.ui.ExceptionUtils;
25 import org.simantics.utils.ui.validators.DoubleValidator;
27 public class SetDuration extends AbstractHandler {
30 public Object execute(ExecutionEvent event) throws ExecutionException {
31 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
33 InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
34 "Set Simulation Step Duration", "Simulation step duration in seconds", "" + prefs.stepDuration, new DoubleValidator());
35 if (dialog.open() == InputDialog.OK) {
36 final double duration = Double.parseDouble(dialog.getValue());
38 SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
39 } catch (BackingStoreException e) {
40 ExceptionUtils.logAndShowError(e);
43 // Update tool-tip for Step command
44 ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
45 Command command = service.getCommand("org.simantics.simulation.ui.step");
46 service.refreshElements(command.getId(), null);
48 // IExperimentManager manager = SimanticsUI.getProject2().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
49 // IExperiment experiment = manager.getActiveExperiment();
50 // if (experiment instanceof IDynamicExperiment)
51 // ((IDynamicExperiment) experiment).simulateDuration(duration);