/** Create GUI elements in the dialog. */
  protected Control createContents(Composite parent) {

    GridLayout layout = new GridLayout();
    layout.numColumns = 3;

    GridData gridLabel = new GridData(GridData.FILL_BOTH);
    gridLabel.verticalSpan = 1;
    gridLabel.horizontalSpan = 1;
    gridLabel.widthHint = 250;
    gridLabel.heightHint = 20;

    GridData gridText = new GridData(GridData.FILL_BOTH);
    gridText.verticalSpan = 1;
    gridText.horizontalSpan = 2;
    gridText.widthHint = 150;
    gridText.heightHint = 20;

    parent.getShell().setLayout(layout);
    parent.getShell().setText("Messagebox View Options");

    Label lblRefreshTime = new Label(parent, SWT.NONE);
    lblRefreshTime.setText("Refresh Time (ms):");
    lblRefreshTime.setLayoutData(gridLabel);

    final Text txtRefreshTime = new Text(parent, SWT.BORDER);
    txtRefreshTime.setText(String.format("%d", getRefreshTime()));
    txtRefreshTime.setLayoutData(gridText);

    Label lblNMsg = new Label(parent, SWT.NONE);
    lblNMsg.setText(
        String.format(
            "Number of Messages (of %d):",
            ResourceCenter.getInstance()
                .getPersistence()
                .count(mbv.getSelectedAdapter(), mbv.getSelectedReader())));
    lblNMsg.setLayoutData(gridLabel);

    final Text txtNMsg = new Text(parent, SWT.BORDER);
    txtNMsg.setText(String.format("%d", getNumberOfMessages()));
    txtNMsg.setLayoutData(gridText);

    // we need to create a special grid data object for the check-box
    // without width-hint as otherwise the check-box will not be displayed
    // in *nix ...
    GridData gridNoWidthHint = new GridData();
    gridNoWidthHint.horizontalSpan = 3;

    final Button allMsg = new Button(parent, SWT.CHECK);
    allMsg.setText("display all messages");
    allMsg.setLayoutData(gridNoWidthHint);
    allMsg.setSelection(false);
    if (Persistence.RETRIEVE_ALL == getNumberOfMessages()) {
      allMsg.setSelection(true);
    }
    // add a selection listener that changes the value of the
    // number of messages field whenever the selection is changed.
    allMsg.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent arg0) {
            // ignore ...
          }

          public void widgetSelected(SelectionEvent arg0) {
            if (allMsg.getSelection()) {
              txtNMsg.setText(String.format("%d", Persistence.RETRIEVE_ALL));
            } else {
              txtNMsg.setText(String.format("%d", ResourceCenter.GET_MAX_MESSAGES));
            }
          }
        });

    final Button btnOK = new Button(parent, SWT.PUSH);
    btnOK.setText("OK");
    btnOK.setFocus();
    btnOK.setLayoutData(gridLabel);

    btnOK.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            setRefreshTime(Long.parseLong(txtRefreshTime.getText()));
            setNumberOfMessages(Integer.parseInt(txtNMsg.getText()));

            setReturnCode(Window.OK);
            close();
          }
        });

    txtRefreshTime.addListener(
        SWT.Modify,
        new Listener() {
          public void handleEvent(Event event) {
            try {
              if ((txtRefreshTime.getText() == null) || (txtRefreshTime.getText().length() < 3)) {
                btnOK.setEnabled(false);
              } else {
                btnOK.setEnabled(true);
                setRefreshTime(Long.parseLong(txtRefreshTime.getText()));
              }
            } catch (Exception e) {
              btnOK.setEnabled(false);
            }
          }
        });

    txtNMsg.addListener(
        SWT.Modify,
        new Listener() {
          public void handleEvent(Event event) {
            try {
              final int n = (new Integer(txtNMsg.getText())).intValue();
              btnOK.setEnabled(true);
              setNumberOfMessages(n);
              if (Persistence.RETRIEVE_ALL != n) {
                allMsg.setSelection(false);
              } else {
                allMsg.setSelection(true);
              }
            } catch (Exception e) {
              btnOK.setEnabled(false);
            }
          }
        });

    final Button btnCancel = new Button(parent, SWT.PUSH);
    btnCancel.setText("Cancel");
    btnCancel.setLayoutData(gridLabel);
    btnCancel.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            setReturnCode(Window.CANCEL);
            close();
          }
        });

    parent.pack();
    return parent;
  }
 /**
  * create a new options dialog.
  *
  * @param aShell Shell instance.
  * @param mbv a link to the surrounding message box view.
  */
 public MessageboxViewOptionsDialog(Shell aShell, MessageboxView mbv) {
   super(aShell);
   numberOfMessages = mbv.getDisplayNumMessages();
   refreshTime = ResourceCenter.getInstance().getMessageBoxRefresh().getRefreshTime();
   this.mbv = mbv;
 }