Class InputDialog

All Implemented Interfaces:
IShellProvider

public class InputDialog extends Dialog
A simple input dialog for soliciting an input string from the user.

This concrete dialog class can be instantiated as is, or further subclassed as required.

  • Constructor Details

    • InputDialog

      public InputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator)
      Creates an input dialog with OK and Cancel buttons. Note that the dialog will have no visual representation (no widgets) until it is told to open.

      Note that the open method blocks for input dialogs.

      Parameters:
      parentShell - the parent shell, or null to create a top-level shell
      dialogTitle - the dialog title, or null if none
      dialogMessage - the dialog message, or null if none
      initialValue - the initial input value, or null if none (equivalent to the empty string)
      validator - an input validator, or null if none
  • Method Details

    • buttonPressed

      protected void buttonPressed(int buttonId)
      Description copied from class: Dialog
      Notifies that this dialog's button with the given id has been pressed.

      The Dialog implementation of this framework method calls okPressed if the ok button is the pressed, and cancelPressed if the cancel button is the pressed. All other button presses are ignored. Subclasses may override to handle other buttons, but should call super.buttonPressed if the default handling of the ok and cancel buttons is desired.

      Overrides:
      buttonPressed in class Dialog
      Parameters:
      buttonId - the id of the button that was pressed (see IDialogConstants.*_ID constants)
    • configureShell

      protected void configureShell(Shell shell)
      Description copied from class: Window
      Configures the given shell in preparation for opening this window in it.

      The default implementation of this framework method sets the shell's image and gives it a grid layout. Subclasses may extend or reimplement.

      Overrides:
      configureShell in class Window
      Parameters:
      shell - the shell
    • createButtonsForButtonBar

      protected void createButtonsForButtonBar(Composite parent)
      Description copied from class: Dialog
      Adds buttons to this dialog's button bar.

      The Dialog implementation of this framework method adds standard ok and cancel buttons using the createButton framework method. These standard buttons will be accessible from getCancelButton, and getOKButton. Subclasses may override.

      Note: The common button order is: {other buttons}, OK, Cancel. On some platforms, Dialog.initializeBounds() will move the default button to the right.

      Overrides:
      createButtonsForButtonBar in class Dialog
      Parameters:
      parent - the button bar composite
    • createDialogArea

      protected Control createDialogArea(Composite parent)
      Description copied from class: Dialog
      Creates and returns the contents of the upper part of this dialog (above the button bar).

      The Dialog implementation of this framework method creates and returns a new Composite with standard margins and spacing.

      The returned control's layout data must be an instance of GridData. This method must not modify the parent's layout.

      Subclasses must override this method but may call super as in the following example:

       Composite composite = (Composite) super.createDialogArea(parent);
       //add controls to composite as necessary
       return composite;
       
      Overrides:
      createDialogArea in class Dialog
      Parameters:
      parent - the parent composite to contain the dialog area
      Returns:
      the dialog area control
    • getErrorMessageLabel

      @Deprecated protected Label getErrorMessageLabel()
      Deprecated.
      use setErrorMessage(String) instead
      Returns the error message label.
      Returns:
      the error message label
    • getOkButton

      protected Button getOkButton()
      Returns the ok button.
      Returns:
      the ok button
    • getText

      protected Text getText()
      Returns the text area.
      Returns:
      the text area
    • getValidator

      protected IInputValidator getValidator()
      Returns the validator.
      Returns:
      the validator
    • getValue

      public String getValue()
      Returns the string typed into this input dialog.
      Returns:
      the input string
    • validateInput

      protected void validateInput()
      Validates the input.

      The default implementation of this framework method delegates the request to the supplied input validator object; if it finds the input invalid, the error message is displayed in the dialog's message line. This hook method is called whenever the text changes in the input field.

    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Sets or clears the error message. If not null, the OK button is disabled.
      Parameters:
      errorMessage - the error message, or null to clear
      Since:
      3.0
    • getInputTextStyle

      protected int getInputTextStyle()
      Returns the style bits that should be used for the input text field. Defaults to a single line entry. Subclasses may override.
      Returns:
      the integer style bits that should be used when creating the input text
      Since:
      3.4