]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/ui/dialogs/SingleValue.java
1 package org
.argeo
.eclipse
.ui
.dialogs
;
3 import org
.eclipse
.jface
.dialogs
.Dialog
;
4 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
5 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
6 import org
.eclipse
.swt
.SWT
;
7 import org
.eclipse
.swt
.graphics
.Point
;
8 import org
.eclipse
.swt
.layout
.GridData
;
9 import org
.eclipse
.swt
.layout
.GridLayout
;
10 import org
.eclipse
.swt
.widgets
.Composite
;
11 import org
.eclipse
.swt
.widgets
.Control
;
12 import org
.eclipse
.swt
.widgets
.Display
;
13 import org
.eclipse
.swt
.widgets
.Label
;
14 import org
.eclipse
.swt
.widgets
.Shell
;
15 import org
.eclipse
.swt
.widgets
.Text
;
17 /** Dialog to change the current user password */
18 public class SingleValue
extends TitleAreaDialog
{
21 private final String title
, message
, label
;
22 private final Boolean multiline
;
24 public static String
ask(String label
, String message
) {
25 SingleValue svd
= new SingleValue(label
, message
);
26 if (svd
.open() == Dialog
.OK
)
27 return svd
.getString();
32 public static Long
askLong(String label
, String message
) {
33 SingleValue svd
= new SingleValue(label
, message
);
34 if (svd
.open() == Dialog
.OK
)
40 public static Double
askDouble(String label
, String message
) {
41 SingleValue svd
= new SingleValue(label
, message
);
42 if (svd
.open() == Dialog
.OK
)
43 return svd
.getDouble();
48 public SingleValue(String label
, String message
) {
49 this(Display
.getDefault().getActiveShell(), label
, message
, label
,
53 public SingleValue(Shell parentShell
, String title
, String message
,
54 String label
, Boolean multiline
) {
57 this.message
= message
;
59 this.multiline
= multiline
;
62 protected Point
getInitialSize() {
63 return new Point(300, 250);
66 protected Control
createDialogArea(Composite parent
) {
67 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
68 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
69 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
70 composite
.setLayout(new GridLayout(2, false));
71 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
72 valueT
= createLT(composite
, label
);
74 setMessage(message
, IMessageProvider
.NONE
);
80 protected void okPressed() {
81 value
= valueT
.getText();
85 /** Creates label and text. */
86 protected Text
createLT(Composite parent
, String label
) {
87 new Label(parent
, SWT
.NONE
).setText(label
);
88 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.BORDER
89 | (multiline ? SWT
.MULTI
: SWT
.NONE
));
90 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
94 protected void configureShell(Shell shell
) {
95 super.configureShell(shell
);
99 public String
getString() {
103 public Long
getLong() {
104 return Long
.valueOf(getString());
107 public Double
getDouble() {
108 return Double
.valueOf(getString());