Class MessageDialog
- All Implemented Interfaces:
IShellProvider
- Direct Known Subclasses:
MessageDialogWithToggle
This concrete dialog class can be instantiated as is, or further subclassed as required.
Note: This class does not use button IDs from IDialogConstants. Instead, the ID is the index of the button in the supplied array.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanFlag to prevent opening of message dialogs for automated testing.static final intConstant for a simple dialog without an icon and OK/Cancel buttons (value 5).static final intConstant for the error image, or a simple dialog with the error image and a single OK button (value 1).static final intConstant for the info image, or a simple dialog with the info image and a single OK button (value 2).static final intConstant for no image (value 0).static final intConstant for the question image, or a simple dialog without an icon and Yes/No buttons (value 3).static final intConstant for a simple dialog without an icon and Yes/No/Cancel buttons (value 6).static final intConstant for the warning image, or a simple dialog with the warning image and a single OK button (value 4).Fields inherited from class org.eclipse.jface.dialogs.IconAndMessageDialog
imageLabel, message, messageLabelFields inherited from class org.eclipse.jface.dialogs.Dialog
blockedHandler, buttonBar, DIALOG_DEFAULT_BOUNDS, DIALOG_PERSISTLOCATION, DIALOG_PERSISTSIZE, dialogArea, DLG_IMG_ERROR, DLG_IMG_HELP, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING, ELLIPSISFields inherited from class org.eclipse.jface.window.Window
CANCEL, OK, resizeHasOccurred -
Constructor Summary
ConstructorsConstructorDescriptionMessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, int defaultIndex, String... dialogButtonLabels) Create a message dialog.MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) Create a message dialog. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuttonPressed(int buttonId) Notifies that this dialog's button with the given id has been pressed.protected voidconfigureShell(Shell shell) Configures the given shell in preparation for opening this window in it.protected ButtoncreateButton(Composite parent, int id, String label, boolean defaultButton) Creates a new button with the given id.protected voidcreateButtonsForButtonBar(Composite parent) Adds buttons to this dialog's button bar.protected ControlcreateCustomArea(Composite parent) Creates and returns the contents of an area of the dialog which appears below the message and above the button bar.protected ControlcreateDialogArea(Composite parent) This implementation of theDialogframework method creates and lays out a composite and callscreateMessageAreaandcreateCustomAreato populate it.protected booleanReturn whether or not we should apply the workaround where we take focus for the default button or if that should be determined by the dialog.protected ButtongetButton(int index) Gets a button in this dialog's button bar.protected String[]An accessor for the labels to use on the buttons.protected intAn accessor for the index of the default button in the button array.getImage()Returns the image to display beside the message in this dialog.protected intReturns the minimum message area width in pixels This determines the minimum width of the dialog.protected voidHandle the shell close.intopen()Opens this window, creating it first if it has not yet been created.static booleanConvenience method to open a simple dialog as specified by thekindflag.static intMethod to open a simple dialog as specified by thekindflag.static booleanopenConfirm(Shell parent, String title, String message) Convenience method to open a simple confirm (OK/Cancel) dialog.static voidConvenience method to open a standard error dialog.static voidopenInformation(Shell parent, String title, String message) Convenience method to open a standard information dialog.static booleanopenQuestion(Shell parent, String title, String message) Convenience method to open a simple Yes/No question dialog.static voidopenWarning(Shell parent, String title, String message) Convenience method to open a standard warning dialog.protected voidsetButtonLabels(String... buttonLabels) A mutator for the button labels.protected voidsetButtons(Button... buttons) A mutator for the array of buttons in the button bar.Methods inherited from class org.eclipse.jface.dialogs.IconAndMessageDialog
createButtonBar, createContents, createDialogAndButtonArea, createMessageArea, getColumnCount, getErrorImage, getInfoImage, getMessageLabelStyle, getQuestionImage, getWarningImageMethods inherited from class org.eclipse.jface.dialogs.Dialog
applyDialogFont, cancelPressed, close, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, create, dialogFontIsDefault, getBlockedHandler, getButtonBar, getCancelButton, getDialogArea, getDialogBoundsSettings, getDialogBoundsStrategy, getImage, getInitialLocation, getInitialSize, getOKButton, initializeBounds, initializeDialogUnits, isResizable, okPressed, setBlockedHandler, setButtonLayoutData, setButtonLayoutFormData, shortenTextMethods inherited from class org.eclipse.jface.window.Window
canHandleShellCloseEvent, constrainShellSize, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getLayout, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
-
Field Details
-
AUTOMATED_MODE
public static boolean AUTOMATED_MODEFlag to prevent opening of message dialogs for automated testing.- Since:
- 3.27
-
NONE
public static final int NONEConstant for no image (value 0). -
ERROR
public static final int ERRORConstant for the error image, or a simple dialog with the error image and a single OK button (value 1). -
INFORMATION
public static final int INFORMATIONConstant for the info image, or a simple dialog with the info image and a single OK button (value 2). -
QUESTION
public static final int QUESTIONConstant for the question image, or a simple dialog without an icon and Yes/No buttons (value 3). -
WARNING
public static final int WARNINGConstant for the warning image, or a simple dialog with the warning image and a single OK button (value 4). -
CONFIRM
public static final int CONFIRMConstant for a simple dialog without an icon and OK/Cancel buttons (value 5).- Since:
- 3.5
- See Also:
-
QUESTION_WITH_CANCEL
public static final int QUESTION_WITH_CANCELConstant for a simple dialog without an icon and Yes/No/Cancel buttons (value 6).- Since:
- 3.5
- See Also:
-
-
Constructor Details
-
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
openmethod will return the index of the label in this array corresponding to the button that was pressed to close the dialog.Note: If the dialog was dismissed without pressing a button (ESC key, close box, etc.) then
As of 3.11 you can also use the other constructor which is based on varargsSWT.DEFAULTis returned. Note that theopenmethod blocks.- Parameters:
parentShell- the parent shell, ornullto create a top-level shelldialogTitle- the dialog title, ornullif nonedialogTitleImage- the dialog title image, ornullif nonedialogMessage- the dialog messagedialogImageType- one of the following values:MessageDialog.NONEfor a dialog with no imageMessageDialog.ERRORfor a dialog with an error imageMessageDialog.INFORMATIONfor a dialog with an information imageMessageDialog.QUESTIONfor a simple dialog without an iconMessageDialog.WARNINGfor a dialog with a warning image
dialogButtonLabels- an array of labels for the buttons in the button bardefaultIndex- the index in the button label array of the default button
-
MessageDialog
public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, int defaultIndex, String... dialogButtonLabels) 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 a varargs of Strings. The
openmethod will return the index of the label in this array corresponding to the button that was pressed to close the dialog.Note: If the dialog was dismissed without pressing a button (ESC key, close box, etc.) then
SWT.DEFAULTis returned. Note that theopenmethod blocks.- Parameters:
parentShell- the parent shell, ornullto create a top-level shelldialogTitle- the dialog title, ornullif nonedialogTitleImage- the dialog title image, ornullif nonedialogMessage- the dialog messagedialogImageType- one of the following values:MessageDialog.NONEfor a dialog with no imageMessageDialog.ERRORfor a dialog with an error imageMessageDialog.INFORMATIONfor a dialog with an information imageMessageDialog.QUESTIONfor a simple dialog without an iconMessageDialog.WARNINGfor a dialog with a warning image
defaultIndex- the index in the button label array of the default buttondialogButtonLabels- varargs of Strings for the button labels in the button bar- Since:
- 3.12
-
-
Method Details
-
buttonPressed
protected void buttonPressed(int buttonId) Description copied from class:DialogNotifies that this dialog's button with the given id has been pressed.The
Dialogimplementation of this framework method callsokPressedif the ok button is the pressed, andcancelPressedif the cancel button is the pressed. All other button presses are ignored. Subclasses may override to handle other buttons, but should callsuper.buttonPressedif the default handling of the ok and cancel buttons is desired.- Overrides:
buttonPressedin classDialog- Parameters:
buttonId- the id of the button that was pressed (seeIDialogConstants.*_IDconstants)
-
configureShell
Description copied from class:WindowConfigures 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:
configureShellin classWindow- Parameters:
shell- the shell
-
createButtonsForButtonBar
Description copied from class:DialogAdds buttons to this dialog's button bar.The
Dialogimplementation of this framework method adds standard ok and cancel buttons using thecreateButtonframework method. These standard buttons will be accessible fromgetCancelButton, andgetOKButton. 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:
createButtonsForButtonBarin classDialog- Parameters:
parent- the button bar composite
-
createCustomArea
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.- Parameters:
parent- parent composite to contain the custom area- Returns:
- the custom area control, or
null
-
createDialogArea
This implementation of theDialogframework method creates and lays out a composite and callscreateMessageAreaandcreateCustomAreato populate it. Subclasses should overridecreateCustomAreato add contents below the message.- Overrides:
createDialogAreain classDialog- Parameters:
parent- the parent composite to contain the dialog area- Returns:
- the dialog area control
-
getButton
Gets a button in this dialog's button bar. -
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()Handle the shell close. Set the return code toSWT.DEFAULTas there has been no explicit close by the user.- Overrides:
handleShellCloseEventin classWindow- See Also:
-
open
Convenience method to open a simple dialog as specified by thekindflag.- Parameters:
kind- the kind of dialog to open, one ofERROR,INFORMATION,QUESTION,WARNING,CONFIRM, orQUESTION_WITH_CANCEL.parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the messagestyle-SWT.NONEfor a default dialog, orSWT.SHEETfor a dialog with sheet behavior- Returns:
trueif the user presses the OK or Yes button,falseotherwise- Since:
- 3.5
-
open
public static int open(int kind, Shell parent, String title, String message, int style, String... dialogButtonLabels) Method to open a simple dialog as specified by thekindflag. This method accepts varargs of String to set custom button labels. Use this method if you want to override the default labels.- Parameters:
kind- the kind of dialog to open, one ofERROR,INFORMATION,QUESTION,WARNING,CONFIRM, orQUESTION_WITH_CANCEL.parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the messagestyle-SWT.NONEfor a default dialog, orSWT.SHEETfor a dialog with sheet behaviordialogButtonLabels- varargs of Strings for the button labels in the button bar- Returns:
- the index of the button that was pressed.
- Since:
- 3.13
-
openConfirm
Convenience method to open a simple confirm (OK/Cancel) dialog.- Parameters:
parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the message- Returns:
trueif the user presses the OK button,falseotherwise
-
openError
Convenience method to open a standard error dialog.- Parameters:
parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the message
-
openInformation
Convenience method to open a standard information dialog.- Parameters:
parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the message
-
openQuestion
Convenience method to open a simple Yes/No question dialog.- Parameters:
parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the message- Returns:
trueif the user presses the Yes button,falseotherwise
-
openWarning
Convenience method to open a standard warning dialog.- Parameters:
parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the message
-
createButton
Description copied from class:DialogCreates a new button with the given id.The
Dialogimplementation of this framework method creates a standard push button, registers it for selection events including button presses, and registers default buttons with its shell. The button id is stored as the button's client data. If the button id isIDialogConstants.CANCEL_ID, the new button will be accessible fromgetCancelButton(). If the button id isIDialogConstants.OK_ID, the new button will be accesible fromgetOKButton(). Note that the parent's layout is assumed to be aGridLayoutand the number of columns in this layout is incremented. 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:
createButtonin classDialog- Parameters:
parent- the parent compositeid- the id of the button (seeIDialogConstants.*_IDconstants for standard dialog button ids)label- the label from the buttondefaultButton-trueif the button is to be the default button, andfalseotherwise- Returns:
- the new button
- See Also:
-
customShouldTakeFocus
protected boolean customShouldTakeFocus()Return whether or not we should apply the workaround where we take focus for the default button or if that should be determined by the dialog. By default only return true if the custom area is a label or CLabel that cannot take focus.- Returns:
- boolean
-
getImage
Description copied from class:IconAndMessageDialogReturns the image to display beside the message in this dialog.Subclasses may override.
- Specified by:
getImagein classIconAndMessageDialog- Returns:
- the image to display beside the message
-
getButtonLabels
An accessor for the labels to use on the buttons.- Returns:
- The button labels to used; never
null.
-
getDefaultButtonIndex
protected int getDefaultButtonIndex()An accessor for the index of the default button in the button array.- Returns:
- The default button index.
-
setButtons
A mutator for the array of buttons in the button bar.- Parameters:
buttons- The buttons in the button bar; must not benull.
-
setButtonLabels
A mutator for the button labels.- Parameters:
buttonLabels- The button labels to use; must not benull.
-
open
public int open()Description copied from class:WindowOpens this window, creating it first if it has not yet been created.If this window has been configured to block on open (
setBlockOnOpen), this method waits until the window is closed by the end user, and then it returns the window's return code; otherwise, this method returns immediately. A window's return codes are window-specific, although two standard return codes are predefined:OKandCANCEL.
-