]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.swt/src/org/argeo/cms/swt/dialogs/SingleValueDialog.java
Start integrating GCR and JCR (not yet working)
[lgpl/argeo-commons.git] / org.argeo.cms.swt / src / org / argeo / cms / swt / dialogs / SingleValueDialog.java
1 package org.argeo.cms.swt.dialogs;
2
3 import org.eclipse.jface.window.Window;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.layout.GridData;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.Control;
8 import org.eclipse.swt.widgets.Display;
9 import org.eclipse.swt.widgets.Shell;
10 import org.eclipse.swt.widgets.Text;
11
12 /** A dialog asking a for a single value. */
13 public class SingleValueDialog extends CmsMessageDialog {
14 private Text valueT;
15 private String value;
16 private String defaultValue;
17
18 public SingleValueDialog(Shell parentShell, String message) {
19 super(parentShell, message, QUESTION);
20 }
21
22 public SingleValueDialog(Shell parentShell, String message, String defaultValue) {
23 super(parentShell, message, QUESTION);
24 this.defaultValue = defaultValue;
25 }
26
27 @Override
28 protected Control createInputArea(Composite parent) {
29 valueT = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.SINGLE);
30 valueT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
31 if (defaultValue != null)
32 valueT.setText(defaultValue);
33 return valueT;
34 }
35
36 @Override
37 protected void okPressed() {
38 value = valueT.getText();
39 super.okPressed();
40 }
41
42 public String getString() {
43 return value;
44 }
45
46 public Long getLong() {
47 return Long.valueOf(getString());
48 }
49
50 public Double getDouble() {
51 return Double.valueOf(getString());
52 }
53
54 public static String ask(String message) {
55 return ask(message, null);
56 }
57
58 public static String ask(String message, String defaultValue) {
59 SingleValueDialog svd = new SingleValueDialog(Display.getCurrent().getActiveShell(), message, defaultValue);
60 if (svd.open() == Window.OK)
61 return svd.getString();
62 else
63 return null;
64 }
65
66 public static Long askLong(String message) {
67 SingleValueDialog svd = new SingleValueDialog(Display.getCurrent().getActiveShell(), message);
68 if (svd.open() == Window.OK)
69 return svd.getLong();
70 else
71 return null;
72 }
73
74 public static Double askDouble(String message) {
75 SingleValueDialog svd = new SingleValueDialog(Display.getCurrent().getActiveShell(), message);
76 if (svd.open() == Window.OK)
77 return svd.getDouble();
78 else
79 return null;
80 }
81
82 }