1 package org.simantics.simulation.ui.handlers.e4;
3 import java.text.ParseException;
5 import org.eclipse.jface.dialogs.InputDialog;
6 import org.eclipse.osgi.util.NLS;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Control;
11 import org.eclipse.swt.widgets.Shell;
12 import org.eclipse.swt.widgets.Text;
13 import org.simantics.simulation.experiment.SimulationTimeUtil;
16 * @author Tuukka Lehtonen
18 public class TimeInputDialog extends InputDialog {
20 private Text statusText;
22 public TimeInputDialog(Shell parentShell, String dialogTitle, String topic, String initialValue) {
23 super(parentShell, dialogTitle, message(topic), initialValue, new TimeValidator());
27 protected Control createDialogArea(Composite parent) {
28 Composite composite = (Composite) super.createDialogArea(parent);
30 statusText = new Text(composite, SWT.READ_ONLY | SWT.WRAP);
31 statusText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
32 | GridData.HORIZONTAL_ALIGN_FILL));
38 protected void validateInput() {
39 super.validateInput();
42 double t = (double) SimulationTimeUtil.getTimeFormat().parseObject(getText().getText());
43 statusText.setText(statusMessage(t));
44 } catch (ParseException e) {
45 statusText.setText("");
49 private static String message(String topic) {
50 return NLS.bind("Give {0} in seconds or timestamp format ([Yy] [Dd] HH:mm:ss.ddd)", topic);
53 private static String statusMessage(double time) {
55 "Specified time is {0} s ({1})",
56 SimulationTimeUtil.formatSeconds(time),
57 SimulationTimeUtil.formatHMSS(time));