]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/SetDuration.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / SetDuration.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 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;
26
27 public class SetDuration extends AbstractHandler {
28
29     @Override
30     public Object execute(ExecutionEvent event) throws ExecutionException {
31         SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
32
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());
37             try {
38                 SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
39             } catch (BackingStoreException e) {
40                 ExceptionUtils.logAndShowError(e);
41             }
42
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); 
47
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);
52         }
53
54         return null;
55     }
56
57 }