]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
.dialogs
;
18 import org
.eclipse
.jface
.dialogs
.Dialog
;
19 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
20 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Point
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Control
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
30 import org
.eclipse
.swt
.widgets
.Text
;
32 /** Dialog retrieve a single value. */
33 public class SingleValue
extends TitleAreaDialog
{
34 private static final long serialVersionUID
= 2843538207460082349L;
38 private final String title
, message
, label
;
39 private final Boolean multiline
;
41 public static String
ask(String label
, String message
) {
42 SingleValue svd
= new SingleValue(label
, message
);
43 if (svd
.open() == Dialog
.OK
)
44 return svd
.getString();
49 public static Long
askLong(String label
, String message
) {
50 SingleValue svd
= new SingleValue(label
, message
);
51 if (svd
.open() == Dialog
.OK
)
57 public static Double
askDouble(String label
, String message
) {
58 SingleValue svd
= new SingleValue(label
, message
);
59 if (svd
.open() == Dialog
.OK
)
60 return svd
.getDouble();
65 public SingleValue(String label
, String message
) {
66 this(Display
.getDefault().getActiveShell(), label
, message
, label
,
70 public SingleValue(Shell parentShell
, String title
, String message
,
71 String label
, Boolean multiline
) {
74 this.message
= message
;
76 this.multiline
= multiline
;
79 protected Point
getInitialSize() {
80 return new Point(300, 250);
83 protected Control
createDialogArea(Composite parent
) {
84 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
85 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
86 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
87 composite
.setLayout(new GridLayout(2, false));
88 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
89 valueT
= createLT(composite
, label
);
91 setMessage(message
, IMessageProvider
.NONE
);
98 protected void okPressed() {
99 value
= valueT
.getText();
103 /** Creates label and text. */
104 protected Text
createLT(Composite parent
, String label
) {
105 new Label(parent
, SWT
.NONE
).setText(label
);
106 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.BORDER
107 | (multiline ? SWT
.MULTI
: SWT
.NONE
));
108 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
112 protected void configureShell(Shell shell
) {
113 super.configureShell(shell
);
114 shell
.setText(title
);
117 public String
getString() {
121 public Long
getLong() {
122 return Long
.valueOf(getString());
125 public Double
getDouble() {
126 return Double
.valueOf(getString());