]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/SetDuration.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / SetDuration.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 org.eclipse.core.commands.AbstractHandler;\r
15 import org.eclipse.core.commands.Command;\r
16 import org.eclipse.core.commands.ExecutionEvent;\r
17 import org.eclipse.core.commands.ExecutionException;\r
18 import org.eclipse.jface.dialogs.InputDialog;\r
19 import org.eclipse.ui.PlatformUI;\r
20 import org.eclipse.ui.commands.ICommandService;\r
21 import org.osgi.service.prefs.BackingStoreException;\r
22 import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;\r
23 import org.simantics.simulation.ui.preferences.SimulationPreferences;\r
24 import org.simantics.utils.ui.ExceptionUtils;\r
25 import org.simantics.utils.ui.validators.DoubleValidator;\r
26 \r
27 public class SetDuration extends AbstractHandler {\r
28 \r
29     @Override\r
30     public Object execute(ExecutionEvent event) throws ExecutionException {\r
31         SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();\r
32 \r
33         InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),\r
34                 "Set Simulation Step Duration", "Simulation step duration in seconds", "" + prefs.stepDuration, new DoubleValidator());\r
35         if (dialog.open() == InputDialog.OK) {\r
36             final double duration = Double.parseDouble(dialog.getValue());\r
37             try {\r
38                 SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));\r
39             } catch (BackingStoreException e) {\r
40                 ExceptionUtils.logAndShowError(e);\r
41             }\r
42 \r
43             // Update tool-tip for Step command\r
44             ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); \r
45             Command command = service.getCommand("org.simantics.simulation.ui.step");\r
46             service.refreshElements(command.getId(), null); \r
47 \r
48 //            IExperimentManager manager = SimanticsUI.getProject2().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
49 //            IExperiment experiment = manager.getActiveExperiment();\r
50 //            if (experiment instanceof IDynamicExperiment)\r
51 //                ((IDynamicExperiment) experiment).simulateDuration(duration);\r
52         }\r
53 \r
54         return null;\r
55     }\r
56 \r
57 }\r