source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/GetObjectNameDialog.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
  • Property svn:mime-type set to text/plain
File size: 3.1 KB
Line 
1package de.ugoe.cs.autoquest.ui.swt;
2
3import org.eclipse.swt.widgets.Dialog;
4import org.eclipse.swt.widgets.Display;
5import org.eclipse.swt.widgets.MessageBox;
6import org.eclipse.swt.widgets.Shell;
7import org.eclipse.swt.layout.GridLayout;
8import org.eclipse.swt.widgets.Label;
9import org.eclipse.swt.SWT;
10import org.eclipse.swt.widgets.Text;
11import org.eclipse.swt.layout.GridData;
12import org.eclipse.swt.widgets.Button;
13import org.eclipse.swt.events.SelectionAdapter;
14import org.eclipse.swt.events.SelectionEvent;
15
16public class GetObjectNameDialog extends Dialog {
17
18    String objectName = "";
19
20    protected Shell shlObjectName;
21    private Text text;
22
23    /**
24     * Create the dialog.
25     *
26     * @param parent
27     * @param style
28     */
29    public GetObjectNameDialog(Shell parent, int style) {
30        super(parent, style);
31        setText("SWT Dialog");
32    }
33
34    /**
35     * Open the dialog.
36     */
37    public void open() {
38        createContents();
39        shlObjectName.open();
40        shlObjectName.layout();
41        Display display = getParent().getDisplay();
42        while (!shlObjectName.isDisposed()) {
43            if (!display.readAndDispatch()) {
44                display.sleep();
45            }
46        }
47    }
48
49    /**
50     * Create contents of the dialog.
51     */
52    private void createContents() {
53        shlObjectName = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
54        shlObjectName.setSize(171, 109);
55        shlObjectName.setText("Object Name");
56        shlObjectName.setLayout(new GridLayout(2, false));
57
58        Label lblPleaseEnterThe = new Label(shlObjectName, SWT.NONE);
59        lblPleaseEnterThe.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
60        lblPleaseEnterThe.setText("Please enter the object name:");
61
62        text = new Text(shlObjectName, SWT.BORDER);
63        text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
64
65        Button btnOk = new Button(shlObjectName, SWT.NONE);
66        btnOk.addSelectionListener(new SelectionAdapter() {
67            @Override
68            public void widgetSelected(SelectionEvent e) {
69                if (text.getText().equals("")) {
70                    MessageBox messageBox = new MessageBox(shlObjectName, SWT.ERROR);
71                    messageBox.setText("Error");
72                    messageBox.setMessage("No name entered!");
73                    return;
74                }
75                objectName = text.getText();
76                shlObjectName.dispose();
77            }
78        });
79        btnOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
80        btnOk.setText("Ok");
81
82        Button btnAbort = new Button(shlObjectName, SWT.NONE);
83        btnAbort.addSelectionListener(new SelectionAdapter() {
84            @Override
85            public void widgetSelected(SelectionEvent e) {
86                shlObjectName.dispose();
87            }
88        });
89        btnAbort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
90        btnAbort.setText("Abort");
91
92    }
93
94    public String getObjectName() {
95        return objectName;
96    }
97}
Note: See TracBrowser for help on using the repository browser.