1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
16 |
|
---|
17 | import org.eclipse.swt.widgets.Dialog;
|
---|
18 | import org.eclipse.swt.widgets.Display;
|
---|
19 | import org.eclipse.swt.widgets.MessageBox;
|
---|
20 | import org.eclipse.swt.widgets.Shell;
|
---|
21 | import org.eclipse.swt.layout.GridLayout;
|
---|
22 | import org.eclipse.swt.widgets.Label;
|
---|
23 | import org.eclipse.swt.SWT;
|
---|
24 | import org.eclipse.swt.widgets.Text;
|
---|
25 | import org.eclipse.swt.layout.GridData;
|
---|
26 | import org.eclipse.swt.widgets.Button;
|
---|
27 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
28 | import org.eclipse.swt.events.SelectionEvent;
|
---|
29 |
|
---|
30 | public class GetObjectNameDialog extends Dialog {
|
---|
31 |
|
---|
32 | String objectName = "";
|
---|
33 |
|
---|
34 | protected Shell shlObjectName;
|
---|
35 | private Text text;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Create the dialog.
|
---|
39 | *
|
---|
40 | * @param parent
|
---|
41 | * @param style
|
---|
42 | */
|
---|
43 | public GetObjectNameDialog(Shell parent, int style) {
|
---|
44 | super(parent, style);
|
---|
45 | setText("SWT Dialog");
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Open the dialog.
|
---|
50 | */
|
---|
51 | public void open() {
|
---|
52 | createContents();
|
---|
53 | shlObjectName.open();
|
---|
54 | shlObjectName.layout();
|
---|
55 | Display display = getParent().getDisplay();
|
---|
56 | while (!shlObjectName.isDisposed()) {
|
---|
57 | if (!display.readAndDispatch()) {
|
---|
58 | display.sleep();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Create contents of the dialog.
|
---|
65 | */
|
---|
66 | private void createContents() {
|
---|
67 | shlObjectName = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
|
---|
68 | shlObjectName.setSize(171, 109);
|
---|
69 | shlObjectName.setText("Object Name");
|
---|
70 | shlObjectName.setLayout(new GridLayout(2, false));
|
---|
71 |
|
---|
72 | Label lblPleaseEnterThe = new Label(shlObjectName, SWT.NONE);
|
---|
73 | lblPleaseEnterThe.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
|
---|
74 | lblPleaseEnterThe.setText("Please enter the object name:");
|
---|
75 |
|
---|
76 | text = new Text(shlObjectName, SWT.BORDER);
|
---|
77 | text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
---|
78 |
|
---|
79 | Button btnOk = new Button(shlObjectName, SWT.NONE);
|
---|
80 | btnOk.addSelectionListener(new SelectionAdapter() {
|
---|
81 | @Override
|
---|
82 | public void widgetSelected(SelectionEvent e) {
|
---|
83 | if (text.getText().equals("")) {
|
---|
84 | MessageBox messageBox = new MessageBox(shlObjectName, SWT.ERROR);
|
---|
85 | messageBox.setText("Error");
|
---|
86 | messageBox.setMessage("No name entered!");
|
---|
87 | return;
|
---|
88 | }
|
---|
89 | objectName = text.getText();
|
---|
90 | shlObjectName.dispose();
|
---|
91 | }
|
---|
92 | });
|
---|
93 | btnOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
94 | btnOk.setText("Ok");
|
---|
95 |
|
---|
96 | Button btnAbort = new Button(shlObjectName, SWT.NONE);
|
---|
97 | btnAbort.addSelectionListener(new SelectionAdapter() {
|
---|
98 | @Override
|
---|
99 | public void widgetSelected(SelectionEvent e) {
|
---|
100 | shlObjectName.dispose();
|
---|
101 | }
|
---|
102 | });
|
---|
103 | btnAbort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
104 | btnAbort.setText("Abort");
|
---|
105 |
|
---|
106 | }
|
---|
107 |
|
---|
108 | public String getObjectName() {
|
---|
109 | return objectName;
|
---|
110 | }
|
---|
111 | }
|
---|