]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - argeo/cms/swt/dialogs/SingleValueDialog.java
1 package org
.argeo
.cms
.swt
.dialogs
;
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
;
12 /** A dialog asking a for a single value. */
13 public class SingleValueDialog
extends CmsMessageDialog
{
16 private String defaultValue
;
18 public SingleValueDialog(Shell parentShell
, String message
) {
19 super(parentShell
, message
, QUESTION
);
22 public SingleValueDialog(Shell parentShell
, String message
, String defaultValue
) {
23 super(parentShell
, message
, QUESTION
);
24 this.defaultValue
= defaultValue
;
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
);
37 protected void okPressed() {
38 value
= valueT
.getText();
42 public String
getString() {
46 public Long
getLong() {
47 return Long
.valueOf(getString());
50 public Double
getDouble() {
51 return Double
.valueOf(getString());
54 public static String
ask(String message
) {
55 return ask(message
, null);
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();
66 public static Long
askLong(String message
) {
67 SingleValueDialog svd
= new SingleValueDialog(Display
.getCurrent().getActiveShell(), message
);
68 if (svd
.open() == Window
.OK
)
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();