| 1 | package de.ugoe.cs.eventbench.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 Object result;
|
|---|
| 21 | protected Shell shlObjectName;
|
|---|
| 22 | private Text text;
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * Create the dialog.
|
|---|
| 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 | * @return the result
|
|---|
| 37 | */
|
|---|
| 38 | public Object 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 | return result;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | /**
|
|---|
| 52 | * Create contents of the dialog.
|
|---|
| 53 | */
|
|---|
| 54 | private void createContents() {
|
|---|
| 55 | shlObjectName = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
|
|---|
| 56 | shlObjectName.setSize(171, 109);
|
|---|
| 57 | shlObjectName.setText("Object Name");
|
|---|
| 58 | shlObjectName.setLayout(new GridLayout(2, false));
|
|---|
| 59 |
|
|---|
| 60 | Label lblPleaseEnterThe = new Label(shlObjectName, SWT.NONE);
|
|---|
| 61 | lblPleaseEnterThe.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
|
|---|
| 62 | lblPleaseEnterThe.setText("Please enter the object name:");
|
|---|
| 63 |
|
|---|
| 64 | text = new Text(shlObjectName, SWT.BORDER);
|
|---|
| 65 | text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
|---|
| 66 |
|
|---|
| 67 | Button btnOk = new Button(shlObjectName, SWT.NONE);
|
|---|
| 68 | btnOk.addSelectionListener(new SelectionAdapter() {
|
|---|
| 69 | @Override
|
|---|
| 70 | public void widgetSelected(SelectionEvent e) {
|
|---|
| 71 | if( text.getText().equals("") ) {
|
|---|
| 72 | MessageBox messageBox = new MessageBox(shlObjectName, SWT.ERROR);
|
|---|
| 73 | messageBox.setText("Error");
|
|---|
| 74 | messageBox.setMessage("No name entered!");
|
|---|
| 75 | return;
|
|---|
| 76 | }
|
|---|
| 77 | objectName = text.getText();
|
|---|
| 78 | shlObjectName.dispose();
|
|---|
| 79 | }
|
|---|
| 80 | });
|
|---|
| 81 | btnOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
|---|
| 82 | btnOk.setText("Ok");
|
|---|
| 83 |
|
|---|
| 84 | Button btnAbort = new Button(shlObjectName, SWT.NONE);
|
|---|
| 85 | btnAbort.addSelectionListener(new SelectionAdapter() {
|
|---|
| 86 | @Override
|
|---|
| 87 | public void widgetSelected(SelectionEvent e) {
|
|---|
| 88 | shlObjectName.dispose();
|
|---|
| 89 | }
|
|---|
| 90 | });
|
|---|
| 91 | btnAbort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
|---|
| 92 | btnAbort.setText("Abort");
|
|---|
| 93 |
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | public String getObjectName() {
|
|---|
| 97 | return objectName;
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|