]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/SetDuration.java
71e72c9e8e7086ac3482951cf157ed78fd863cba
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / e4 / 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.e4;
13
14 import org.eclipse.e4.core.di.annotations.Execute;
15 import org.eclipse.e4.core.services.events.IEventBroker;
16 import org.eclipse.e4.ui.internal.workbench.E4Workbench;
17 import org.eclipse.jface.dialogs.InputDialog;
18 import org.eclipse.ui.PlatformUI;
19 import org.osgi.service.prefs.BackingStoreException;
20 import org.simantics.simulation.SimulationEvents;
21 import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
22 import org.simantics.simulation.ui.preferences.SimulationPreferences;
23 import org.simantics.utils.ui.ExceptionUtils;
24 import org.simantics.utils.ui.validators.DoubleValidator;
25
26 public class SetDuration {
27
28     private IEventBroker eventBroker;
29     
30     public SetDuration() {
31         eventBroker = E4Workbench.getServiceContext().get(IEventBroker.class);
32     }
33     
34     @Execute
35     public void execute() {
36         SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
37
38         InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
39                 "Set Simulation Step Duration", "Simulation step duration in seconds", "" + prefs.stepDuration, new DoubleValidator());
40         if (dialog.open() == InputDialog.OK) {
41             final double duration = Double.parseDouble(dialog.getValue());
42             try {
43                 SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
44                 eventBroker.post(SimulationEvents.TOPIC_STEP_DURATION, duration);
45             } catch (BackingStoreException e) {
46                 ExceptionUtils.logAndShowError(e);
47             }
48         }
49     }
50
51 }