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