public class MessageDialog extends IconAndMessageDialog
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.
Window.IExceptionHandler
Modifier and Type | Field and Description |
---|---|
static int |
CONFIRM
Constant for a simple dialog with the question image and OK/Cancel buttons (value 5).
|
static int |
ERROR
Constant for the error image, or a simple dialog with the error image and a single OK button (value 1).
|
static int |
INFORMATION
Constant for the info image, or a simple dialog with the info image and a single OK button (value 2).
|
static int |
NONE
Constant for no image (value 0).
|
static int |
QUESTION
Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).
|
static int |
QUESTION_WITH_CANCEL
Constant for a simple dialog with the question image and Yes/No/Cancel buttons (value 6).
|
static int |
WARNING
Constant for the warning image, or a simple dialog with the warning image and a single OK button (value 4).
|
imageLabel, message, messageLabel
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, ELLIPSIS
CANCEL, OK, resizeHasOccurred
Constructor and Description |
---|
MessageDialog(Shell parentShell,
String dialogTitle,
Image dialogTitleImage,
String dialogMessage,
int dialogImageType,
String[] dialogButtonLabels,
int defaultIndex)
Create a message dialog.
|
Modifier and Type | Method and Description |
---|---|
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 Button |
createButton(Composite parent,
int id,
String label,
boolean defaultButton)
Creates a new button with the given id.
|
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 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.
|
protected Button |
getButton(int index)
Gets a button in this dialog's button bar.
|
protected String[] |
getButtonLabels()
An accessor for the labels to use on the buttons.
|
protected int |
getDefaultButtonIndex()
An accessor for the index of the default button in the button array.
|
Image |
getImage()
Returns the image to display beside the message in this dialog.
|
protected int |
getMinimumMessageWidth()
Returns the minimum message area width in pixels This determines the
minimum width of the dialog.
|
protected void |
handleShellCloseEvent()
Handle the shell close.
|
int |
open()
Opens this message dialog, creating it first if it has not yet been created.
|
static boolean |
open(int kind,
Shell parent,
String title,
String message,
int style)
Convenience method to open a simple dialog as specified by the
kind flag. |
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.
|
protected void |
setButtonLabels(String[] buttonLabels)
A mutator for the button labels.
|
protected void |
setButtons(Button[] buttons)
A mutator for the array of buttons in the button bar.
|
createButtonBar, createContents, createDialogAndButtonArea, createMessageArea, getErrorImage, getInfoImage, getMessageLabelStyle, getQuestionImage, getWarningImage
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, shortenText
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
public static final int NONE
public static final int ERROR
public static final int INFORMATION
public static final int QUESTION
public static final int WARNING
public static final int CONFIRM
open(int, Shell, String, String, int)
,
Constant Field Valuespublic static final int QUESTION_WITH_CANCEL
open(int, Shell, String, String, int)
,
Constant Field Valuespublic MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex)
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.
Note: If the dialog was dismissed without pressing
a button (ESC key, close box, etc.) then SWT.DEFAULT
is returned.
Note that the open
method blocks.
parentShell
- the parent shell, or null
to create a top-level shelldialogTitle
- the dialog title, or null
if nonedialogTitleImage
- the dialog title image, or null
if nonedialogMessage
- the dialog messagedialogImageType
- one of the following values:
MessageDialog.NONE
for a dialog with no
imageMessageDialog.ERROR
for a dialog with an
error imageMessageDialog.INFORMATION
for a dialog
with an information imageMessageDialog.QUESTION
for a dialog with a
question imageMessageDialog.WARNING
for a dialog with a
warning imagedialogButtonLabels
- an array of labels for the buttons in the button bardefaultIndex
- the index in the button label array of the default buttonprotected void buttonPressed(int buttonId)
Dialog
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.
buttonPressed
in class Dialog
buttonId
- the id of the button that was pressed (see
IDialogConstants.*_ID
constants)protected void configureShell(Shell shell)
Window
The default implementation of this framework method sets the shell's image and gives it a grid layout. Subclasses may extend or reimplement.
configureShell
in class Window
shell
- the shellprotected void createButtonsForButtonBar(Composite parent)
Dialog
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.
createButtonsForButtonBar
in class Dialog
parent
- the button bar compositeprotected Control createCustomArea(Composite parent)
The default implementation of this framework method returns
null
. Subclasses may override.
parent
- parent composite to contain the custom areanull
protected Control createDialogArea(Composite parent)
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.createDialogArea
in class Dialog
parent
- the parent composite to contain the dialog areaprotected Button getButton(int index)
getButton
in class Dialog
index
- the index of the button in the dialog's button barnull
if there's no button with that indexDialog.createButton(Composite, int, String, boolean)
protected int getMinimumMessageWidth()
Subclasses may override.
protected void handleShellCloseEvent()
SWT.DEFAULT
as there has been no explicit close by the user.handleShellCloseEvent
in class Window
Window.handleShellCloseEvent()
public int open()
This method waits until the dialog is closed by the end user, and then it
returns the dialog's return code. The dialog's return code is either the
index of the button the user pressed, or SWT.DEFAULT
if the dialog
has been closed by other means.
open
in class Window
Window.open()
public static boolean open(int kind, Shell parent, String title, String message, int style)
kind
flag.kind
- the kind of dialog to open, one of ERROR
,
INFORMATION
, QUESTION
, WARNING
,
CONFIRM
, or QUESTION_WITH_CANCEL
.parent
- the parent shell of the dialog, or null
if nonetitle
- the dialog's title, or null
if nonemessage
- the messagestyle
- SWT.NONE
for a default dialog, or SWT.SHEET
for
a dialog with sheet behaviortrue
if the user presses the OK or Yes button,
false
otherwisepublic static boolean openConfirm(Shell parent, String title, String message)
parent
- the parent shell of the dialog, or null
if nonetitle
- the dialog's title, or null
if nonemessage
- the messagetrue
if the user presses the OK button,
false
otherwisepublic static void openError(Shell parent, String title, String message)
parent
- the parent shell of the dialog, or null
if nonetitle
- the dialog's title, or null
if nonemessage
- the messagepublic static void openInformation(Shell parent, String title, String message)
parent
- the parent shell of the dialog, or null
if nonetitle
- the dialog's title, or null
if nonemessage
- the messagepublic static boolean openQuestion(Shell parent, String title, String message)
parent
- the parent shell of the dialog, or null
if nonetitle
- the dialog's title, or null
if nonemessage
- the messagetrue
if the user presses the Yes button,
false
otherwisepublic static void openWarning(Shell parent, String title, String message)
parent
- the parent shell of the dialog, or null
if nonetitle
- the dialog's title, or null
if nonemessage
- the messageprotected Button createButton(Composite parent, int id, String label, boolean defaultButton)
Dialog
The Dialog
implementation 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 is
IDialogConstants.CANCEL_ID
, the new button will be
accessible from getCancelButton()
. If the button id is
IDialogConstants.OK_ID
, the new button will be accesible
from getOKButton()
. Note that the parent's layout is
assumed to be a GridLayout
and the number of columns in
this layout is incremented. Subclasses may override.
createButton
in class Dialog
parent
- the parent compositeid
- the id of the button (see IDialogConstants.*_ID
constants for standard dialog button ids)label
- the label from the buttondefaultButton
- true
if the button is to be the default button,
and false
otherwiseDialog.getCancelButton()
,
Dialog.getOKButton()
protected boolean customShouldTakeFocus()
public Image getImage()
IconAndMessageDialog
Subclasses may override.
getImage
in class IconAndMessageDialog
protected String[] getButtonLabels()
null
.protected int getDefaultButtonIndex()
protected void setButtons(Button[] buttons)
buttons
- The buttons in the button bar; must not be null
.protected void setButtonLabels(String[] buttonLabels)
buttonLabels
- The button labels to use; must not be null
.
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.