]> git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/org.argeo.cms.swt/src/org/argeo/eclipse/ui/dialogs/SingleValue.java
Prepare next development cycle
[lgpl/argeo-commons.git] / eclipse / org.argeo.cms.swt / src / org / argeo / eclipse / ui / dialogs / SingleValue.java
1 package org.argeo.eclipse.ui.dialogs;
2
3 import org.argeo.eclipse.ui.EclipseUiUtils;
4 import org.eclipse.jface.dialogs.IMessageProvider;
5 import org.eclipse.jface.dialogs.TitleAreaDialog;
6 import org.eclipse.jface.window.Window;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.graphics.Point;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13 import org.eclipse.swt.widgets.Display;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.swt.widgets.Text;
17
18 /**
19 * Dialog to retrieve a single value.
20 *
21 * @deprecated Use CMS dialogs instead.
22 */
23 @Deprecated
24 public class SingleValue extends TitleAreaDialog {
25 private static final long serialVersionUID = 2843538207460082349L;
26
27 private Text valueT;
28 private String value;
29 private final String title, message, label;
30 private final Boolean multiline;
31
32 public static String ask(String label, String message) {
33 SingleValue svd = new SingleValue(label, message);
34 if (svd.open() == Window.OK)
35 return svd.getString();
36 else
37 return null;
38 }
39
40 public static Long askLong(String label, String message) {
41 SingleValue svd = new SingleValue(label, message);
42 if (svd.open() == Window.OK)
43 return svd.getLong();
44 else
45 return null;
46 }
47
48 public static Double askDouble(String label, String message) {
49 SingleValue svd = new SingleValue(label, message);
50 if (svd.open() == Window.OK)
51 return svd.getDouble();
52 else
53 return null;
54 }
55
56 public SingleValue(String label, String message) {
57 this(Display.getDefault().getActiveShell(), label, message, label, false);
58 }
59
60 public SingleValue(Shell parentShell, String title, String message, String label, Boolean multiline) {
61 super(parentShell);
62 this.title = title;
63 this.message = message;
64 this.label = label;
65 this.multiline = multiline;
66 }
67
68 protected Point getInitialSize() {
69 if (multiline)
70 return new Point(450, 350);
71
72 else
73 return new Point(400, 270);
74 }
75
76 protected Control createDialogArea(Composite parent) {
77 Composite dialogarea = (Composite) super.createDialogArea(parent);
78 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
79 Composite composite = new Composite(dialogarea, SWT.NONE);
80 composite.setLayoutData(EclipseUiUtils.fillAll());
81 GridLayout layout = new GridLayout(2, false);
82 layout.marginWidth = layout.marginHeight = 20;
83 composite.setLayout(layout);
84
85 valueT = createLT(composite, label);
86
87 setMessage(message, IMessageProvider.NONE);
88
89 parent.pack();
90 valueT.setFocus();
91 return composite;
92 }
93
94 @Override
95 protected void okPressed() {
96 value = valueT.getText();
97 super.okPressed();
98 }
99
100 /** Creates label and text. */
101 protected Text createLT(Composite parent, String label) {
102 new Label(parent, SWT.NONE).setText(label);
103 Text text;
104 if (multiline) {
105 text = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.MULTI);
106 text.setLayoutData(EclipseUiUtils.fillAll());
107 } else {
108 text = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.SINGLE);
109 text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
110 }
111 return text;
112 }
113
114 protected void configureShell(Shell shell) {
115 super.configureShell(shell);
116 shell.setText(title);
117 }
118
119 public String getString() {
120 return value;
121 }
122
123 public Long getLong() {
124 return Long.valueOf(getString());
125 }
126
127 public Double getDouble() {
128 return Double.valueOf(getString());
129 }
130 }