]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/SingleValue.java
05c4eaf104418e39e1841964081cd1efbd081724
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
.argeo
.eclipse
.ui
.EclipseUiUtils
;
19 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
20 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
21 import org
.eclipse
.jface
.window
.Window
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.graphics
.Point
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Display
;
29 import org
.eclipse
.swt
.widgets
.Label
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
31 import org
.eclipse
.swt
.widgets
.Text
;
33 /** Dialog retrieve a single value. */
34 public class SingleValue
extends TitleAreaDialog
{
35 private static final long serialVersionUID
= 2843538207460082349L;
39 private final String title
, message
, label
;
40 private final Boolean multiline
;
42 public static String
ask(String label
, String message
) {
43 SingleValue svd
= new SingleValue(label
, message
);
44 if (svd
.open() == Window
.OK
)
45 return svd
.getString();
50 public static Long
askLong(String label
, String message
) {
51 SingleValue svd
= new SingleValue(label
, message
);
52 if (svd
.open() == Window
.OK
)
58 public static Double
askDouble(String label
, String message
) {
59 SingleValue svd
= new SingleValue(label
, message
);
60 if (svd
.open() == Window
.OK
)
61 return svd
.getDouble();
66 public SingleValue(String label
, String message
) {
67 this(Display
.getDefault().getActiveShell(), label
, message
, label
,
71 public SingleValue(Shell parentShell
, String title
, String message
,
72 String label
, Boolean multiline
) {
75 this.message
= message
;
77 this.multiline
= multiline
;
80 protected Point
getInitialSize() {
82 return new Point(450, 350);
85 return new Point(400, 270);
88 protected Control
createDialogArea(Composite parent
) {
89 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
90 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
91 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
92 composite
.setLayoutData(EclipseUiUtils
.fillAll());
93 GridLayout layout
= new GridLayout(2, false);
94 layout
.marginWidth
= layout
.marginHeight
= 20;
95 composite
.setLayout(layout
);
97 valueT
= createLT(composite
, label
);
99 setMessage(message
, IMessageProvider
.NONE
);
106 protected void okPressed() {
107 value
= valueT
.getText();
111 /** Creates label and text. */
112 protected Text
createLT(Composite parent
, String label
) {
113 new Label(parent
, SWT
.NONE
).setText(label
);
116 text
= new Text(parent
, SWT
.LEAD
| SWT
.BORDER
| SWT
.MULTI
);
117 text
.setLayoutData(EclipseUiUtils
.fillAll());
119 text
= new Text(parent
, SWT
.LEAD
| SWT
.BORDER
| SWT
.SINGLE
);
120 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, true));
125 protected void configureShell(Shell shell
) {
126 super.configureShell(shell
);
127 shell
.setText(title
);
130 public String
getString() {
134 public Long
getLong() {
135 return Long
.valueOf(getString());
138 public Double
getDouble() {
139 return Double
.valueOf(getString());