Eclipse Platform
2.0

org.eclipse.jface.dialogs
Class MessageDialog

java.lang.Object
  |
  +--org.eclipse.jface.window.Window
        |
        +--org.eclipse.jface.dialogs.Dialog
              |
              +--org.eclipse.jface.dialogs.MessageDialog

public class MessageDialog
extends Dialog

A dialog for showing messages to the user.

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


Nested Class Summary
 
Nested classes inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler
 
Field Summary
static int ERROR
          Constant for a dialog with an error image (value 1).
static int INFORMATION
          Constant for a dialog with an info image (value 2).
static int NONE
          Constant for a dialog with no image (value 0).
static int QUESTION
          Constant for a dialog with a question image (value 3).
static int WARNING
          Constant for a dialog with a warning image (value 4).
 
Fields inherited from class org.eclipse.jface.dialogs.Dialog
DLG_IMG_ERROR, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING
 
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK
 
Constructor Summary
MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex)
          Create a message dialog.
 
Method Summary
protected  void buttonPressed(int buttonId)
          Notifies that this dialog's button with the given id has been pressed.
protected  void configureShell(Shell shell)
          Configures the given shell in preparation for opening this window in it.
protected  void createButtonsForButtonBar(Composite parent)
          Adds buttons to this dialog's button bar.
protected  Control createCustomArea(Composite parent)
          Creates and returns the contents of an area of the dialog which appears below the message and above the button bar.
protected  Control createDialogArea(Composite parent)
          This implementation of the Dialog framework method creates and lays out a composite and calls createMessageArea and createCustomArea to populate it.
protected  Button getButton(int index)
          Gets a button in this dialog's button bar.
protected  int getMinimumMessageWidth()
          Returns the minimum message area width in pixels This determines the minimum width of the dialog.
protected  void handleShellCloseEvent()
          Notifies that the window's close button was pressed, the close menu was selected, or the ESCAPE key pressed.
static boolean openConfirm(Shell parent, String title, String message)
          Convenience method to open a simple confirm (OK/Cancel) dialog.
static void openError(Shell parent, String title, String message)
          Convenience method to open a standard error dialog.
static void openInformation(Shell parent, String title, String message)
          Convenience method to open a standard information dialog.
static boolean openQuestion(Shell parent, String title, String message)
          Convenience method to open a simple Yes/No question dialog.
static void openWarning(Shell parent, String title, String message)
          Convenience method to open a standard warning dialog.
 
Methods inherited from class org.eclipse.jface.dialogs.Dialog
cancelPressed, constrainShellSize, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, createButton, createButtonBar, createContents, getButtonBar, getCancelButton, getDialogArea, getImage, getOKButton, initializeDialogUnits, okPressed
 
Methods inherited from class org.eclipse.jface.window.Window
close, create, createShell, getContents, getDefaultImage, getInitialLocation, getInitialSize, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, initializeBounds, open, setBlockOnOpen, setDefaultImage, setExceptionHandler, setReturnCode, setShellStyle, setWindowManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Constant for a dialog with no image (value 0).

See Also:
Constant Field Values

ERROR

public static final int ERROR
Constant for a dialog with an error image (value 1).

See Also:
Constant Field Values

INFORMATION

public static final int INFORMATION
Constant for a dialog with an info image (value 2).

See Also:
Constant Field Values

QUESTION

public static final int QUESTION
Constant for a dialog with a question image (value 3).

See Also:
Constant Field Values

WARNING

public static final int WARNING
Constant for a dialog with a warning image (value 4).

See Also:
Constant Field Values
Constructor Detail

MessageDialog

public MessageDialog(Shell parentShell,
                     String dialogTitle,
                     Image dialogTitleImage,
                     String dialogMessage,
                     int dialogImageType,
                     String[] dialogButtonLabels,
                     int defaultIndex)
Create a message dialog. Note that the dialog will have no visual representation (no widgets) until it is told to open.

The labels of the buttons to appear in the button bar are supplied in this constructor as an array. The open method will return the index of the label in this array corresponding to the button that was pressed to close the dialog. If the dialog was dismissed without pressing a button (ESC, etc.) then -1 is returned. Note that the open method blocks.

Parameters:
parentShell - the parent shell
dialogTitle - the dialog title, or null if none
dialogTitleImage - the dialog title image, or null if none
dialogMessage - the dialog message
dialogImageType - one of the following values:
dialogButtonLabels - an array of labels for the buttons in the button bar
defaultIndex - the index in the button label array of the default button
Method Detail

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.

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

createCustomArea

protected Control createCustomArea(Composite parent)
Creates and returns the contents of an area of the dialog which appears below the message and above the button bar.

The default implementation of this framework method returns null. Subclasses may override.

Returns:
the custom area control, or null

createDialogArea

protected Control createDialogArea(Composite parent)
This implementation of the Dialog framework method creates and lays out a composite and calls createMessageArea and createCustomArea to populate it. Subclasses should override createCustomArea to add contents below the message.

Overrides:
createDialogArea in class Dialog
Parameters:
parent - the parent composite to contain the dialog area
Returns:
the dialog area control

getButton

protected Button getButton(int index)
Gets a button in this dialog's button bar.

Overrides:
getButton in class Dialog
Parameters:
index - the index of the button in the dialog's button bar
Returns:
a button in the dialog's button bar
See Also:
createButton

getMinimumMessageWidth

protected int getMinimumMessageWidth()
Returns the minimum message area width in pixels This determines the minimum width of the dialog.

Subclasses may override.

Returns:
the minimum message area width (in pixels)

handleShellCloseEvent

protected void handleShellCloseEvent()
Description copied from class: Window
Notifies that the window's close button was pressed, the close menu was selected, or the ESCAPE key pressed.

The default implementation of this framework method sets the window's return code to CANCEL and closes the window using close. Subclasses may extend or reimplement.

Overrides:
handleShellCloseEvent in class Window

openConfirm

public static boolean openConfirm(Shell parent,
                                  String title,
                                  String message)
Convenience method to open a simple confirm (OK/Cancel) dialog.

Parameters:
parent - the parent shell of the dialog, or null if none
title - the dialog's title, or null if none
message - the message
Returns:
true if the user presses the OK button, false otherwise

openError

public static void openError(Shell parent,
                             String title,
                             String message)
Convenience method to open a standard error dialog.

Parameters:
parent - the parent shell of the dialog, or null if none
title - the dialog's title, or null if none
message - the message

openInformation

public static void openInformation(Shell parent,
                                   String title,
                                   String message)
Convenience method to open a standard information dialog.

Parameters:
parent - the parent shell of the dialog, or null if none
title - the dialog's title, or null if none
message - the message

openQuestion

public static boolean openQuestion(Shell parent,
                                   String title,
                                   String message)
Convenience method to open a simple Yes/No question dialog.

Parameters:
parent - the parent shell of the dialog, or null if none
title - the dialog's title, or null if none
message - the message
Returns:
true if the user presses the OK button, false otherwise

openWarning

public static void openWarning(Shell parent,
                               String title,
                               String message)
Convenience method to open a standard warning dialog.

Parameters:
parent - the parent shell of the dialog, or null if none
title - the dialog's title, or null if none
message - the message

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.