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.e4;
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;
26 public class SetDuration {
28 private IEventBroker eventBroker;
30 public SetDuration() {
31 eventBroker = E4Workbench.getServiceContext().get(IEventBroker.class);
35 public void execute() {
36 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
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());
43 SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
44 eventBroker.post(SimulationEvents.TOPIC_STEP_DURATION, duration);
45 } catch (BackingStoreException e) {
46 ExceptionUtils.logAndShowError(e);