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