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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.simulation.ui.handlers.e4;
\r
14 import org.eclipse.e4.core.di.annotations.Execute;
\r
15 import org.eclipse.e4.core.services.events.IEventBroker;
\r
16 import org.eclipse.e4.ui.internal.workbench.E4Workbench;
\r
17 import org.eclipse.jface.dialogs.InputDialog;
\r
18 import org.eclipse.ui.PlatformUI;
\r
19 import org.osgi.service.prefs.BackingStoreException;
\r
20 import org.simantics.simulation.SimulationEvents;
\r
21 import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
\r
22 import org.simantics.simulation.ui.preferences.SimulationPreferences;
\r
23 import org.simantics.utils.ui.ExceptionUtils;
\r
24 import org.simantics.utils.ui.validators.DoubleValidator;
\r
26 public class SetDuration {
\r
28 private IEventBroker eventBroker;
\r
30 public SetDuration() {
\r
31 eventBroker = E4Workbench.getServiceContext().get(IEventBroker.class);
\r
35 public void execute() {
\r
36 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
\r
38 InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
\r
39 "Set Simulation Step Duration", "Simulation step duration in seconds", "" + prefs.stepDuration, new DoubleValidator());
\r
40 if (dialog.open() == InputDialog.OK) {
\r
41 final double duration = Double.parseDouble(dialog.getValue());
\r
43 SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
\r
44 eventBroker.post(SimulationEvents.TOPIC_STEP_DURATION, duration);
\r
45 } catch (BackingStoreException e) {
\r
46 ExceptionUtils.logAndShowError(e);
\r