]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/SingleValue.java
2 * Copyright (C) 2007-2012 Mathieu Baudier
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
{
36 private final String title
, message
, label
;
37 private final Boolean multiline
;
39 public static String
ask(String label
, String message
) {
40 SingleValue svd
= new SingleValue(label
, message
);
41 if (svd
.open() == Dialog
.OK
)
42 return svd
.getString();
47 public static Long
askLong(String label
, String message
) {
48 SingleValue svd
= new SingleValue(label
, message
);
49 if (svd
.open() == Dialog
.OK
)
55 public static Double
askDouble(String label
, String message
) {
56 SingleValue svd
= new SingleValue(label
, message
);
57 if (svd
.open() == Dialog
.OK
)
58 return svd
.getDouble();
63 public SingleValue(String label
, String message
) {
64 this(Display
.getDefault().getActiveShell(), label
, message
, label
,
68 public SingleValue(Shell parentShell
, String title
, String message
,
69 String label
, Boolean multiline
) {
72 this.message
= message
;
74 this.multiline
= multiline
;
77 protected Point
getInitialSize() {
78 return new Point(300, 250);
81 protected Control
createDialogArea(Composite parent
) {
82 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
83 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
84 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
85 composite
.setLayout(new GridLayout(2, false));
86 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
87 valueT
= createLT(composite
, label
);
89 setMessage(message
, IMessageProvider
.NONE
);
96 protected void okPressed() {
97 value
= valueT
.getText();
101 /** Creates label and text. */
102 protected Text
createLT(Composite parent
, String label
) {
103 new Label(parent
, SWT
.NONE
).setText(label
);
104 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.BORDER
105 | (multiline ? SWT
.MULTI
: SWT
.NONE
));
106 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
110 protected void configureShell(Shell shell
) {
111 super.configureShell(shell
);
112 shell
.setText(title
);
115 public String
getString() {
119 public Long
getLong() {
120 return Long
.valueOf(getString());
123 public Double
getDouble() {
124 return Double
.valueOf(getString());