Class MessageDialogWithToggle
- All Implemented Interfaces:
IShellProvider
- Direct Known Subclasses:
NavigationEndDialog
A message dialog which also allows the user to adjust a toggle setting. If a preference store is provided and the user selects the toggle, then the user's answer (yes/ok or no) will be persisted in the store. If no store is provided, then this information can be queried after the dialog closes.
This type of dialog should be used whenever you want to user to be able to avoid being prompted in the future. It is strongly recommended that a cancel option be provided, so that the user has the option of making the decision at a later point in time. The semantic for a cancel button should be to cancel the operation (if it has not yet started), or stop the operation (if it has already started).
It is the responsibility of the developer to provide a mechanism for the user to change this preference at some later point in time (e.g., through a preference page).
- Since:
- 3.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe value of the preference when the user has asked that the answer to the question always be "okay" or "yes".static final StringThe value of the preference when the user has asked that the answer to the question always be "no".static final StringThe value of the preference when the user wishes to prompted for an answer every time the question is to be asked.Fields inherited from class org.eclipse.jface.dialogs.MessageDialog
AUTOMATED_MODE, CONFIRM, ERROR, INFORMATION, NONE, QUESTION, QUESTION_WITH_CANCEL, WARNINGFields 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
ConstructorsConstructorDescriptionMessageDialogWithToggle(Shell parentShell, String dialogTitle, Image image, String message, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, String toggleMessage, boolean toggleState) Creates a message dialog with a toggle.MessageDialogWithToggle(Shell parentShell, String dialogTitle, Image image, String message, int dialogImageType, LinkedHashMap<String, Integer> buttonLabelToIdMap, int defaultIndex, String toggleMessage, boolean toggleState) Creates a message dialog with a toggle. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuttonPressed(int buttonId) Notifies that this dialog's button with the given id has been pressed.protected voidcreateButtonsForButtonBar(Composite parent) Adds buttons to this dialog's button bar.protected ControlcreateDialogArea(Composite parent) This implementation of theDialogframework method creates and lays out a composite and callscreateMessageAreaandcreateCustomAreato populate it.protected ButtoncreateToggleButton(Composite parent) Creates a toggle button without any text or state.An accessor for the current key of the toggle preference.An accessor for the current preference store for this dialog.protected ButtonReturns the toggle button.booleanReturns the toggle state.static MessageDialogWithToggleopen(int kind, Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key, int style) Convenience method to open a simple dialog as specified by thekindflag, with a "don't show again' toggle.static MessageDialogWithToggleopen(int kind, Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key, int style, LinkedHashMap<String, Integer> buttonLabelToIdMap) Convenience method to open a simple dialog as specified by thekindflag, with a "don't show again' toggle.static MessageDialogWithToggleopenError(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a standard error dialog.static MessageDialogWithToggleopenInformation(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a standard information dialog.static MessageDialogWithToggleopenOkCancelConfirm(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a simple confirm (OK/Cancel) dialog.static MessageDialogWithToggleopenWarning(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a standard warning dialog.static MessageDialogWithToggleopenYesNoCancelQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a simple question Yes/No/Cancel dialog.static MessageDialogWithToggleopenYesNoQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a simple Yes/No question dialog.voidsetPrefKey(String prefKey) A mutator for the key of the preference to be modified by the toggle button.voidsetPrefStore(IPreferenceStore prefStore) A mutator for the preference store to be modified by the toggle button.protected voidsetToggleButton(Button button) A mutator for the button providing the toggle option.protected voidsetToggleMessage(String message) A mutator for the text on the toggle button.voidsetToggleState(boolean toggleState) A mutator for the state of the toggle button.Methods inherited from class org.eclipse.jface.dialogs.MessageDialog
configureShell, createButton, createCustomArea, customShouldTakeFocus, getButton, getButtonLabels, getDefaultButtonIndex, getImage, getMinimumMessageWidth, handleShellCloseEvent, open, open, open, openConfirm, openError, openInformation, openQuestion, openWarning, setButtonLabels, setButtonsMethods 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
-
ALWAYS
The value of the preference when the user has asked that the answer to the question always be "okay" or "yes".- See Also:
-
NEVER
The value of the preference when the user has asked that the answer to the question always be "no".- See Also:
-
PROMPT
The value of the preference when the user wishes to prompted for an answer every time the question is to be asked.- See Also:
-
-
Constructor Details
-
MessageDialogWithToggle
public MessageDialogWithToggle(Shell parentShell, String dialogTitle, Image image, String message, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, String toggleMessage, boolean toggleState) Creates a message dialog with a toggle. See the superclass constructor for info on the other parameters.- Parameters:
parentShell- the parent shelldialogTitle- the dialog title, ornullif noneimage- the dialog title image, ornullif nonemessage- 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 dialog with a question imageMessageDialog.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 buttontoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the toggle
-
MessageDialogWithToggle
public MessageDialogWithToggle(Shell parentShell, String dialogTitle, Image image, String message, int dialogImageType, LinkedHashMap<String, Integer> buttonLabelToIdMap, int defaultIndex, String toggleMessage, boolean toggleState) Creates a message dialog with a toggle. See the superclass constructor for info on the other parameters. This constructor accepts a LinkedHashMap<String, Integer> to set custom button labels (String) and custom button IDs (Integer) as return codes for those buttons. Use this constructor if you need to override the default labels and IDs.- Parameters:
parentShell- the parent shelldialogTitle- the dialog title, ornullif noneimage- the dialog title image, ornullif nonemessage- 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 dialog with a question imageMessageDialog.WARNINGfor a dialog with a warning image
buttonLabelToIdMap- map with button labels and IDs to define custom labels and their corresponding IDsdefaultIndex- the index of the default button in the button label and ID map related to the insertion order of the elementstoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the toggle- Since:
- 3.13
-
-
Method Details
-
open
public static MessageDialogWithToggle open(int kind, Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key, int style) Convenience method to open a simple dialog as specified by thekindflag, with a "don't show again' toggle.- Parameters:
kind- the kind of dialog to open, one ofMessageDialog.ERROR,MessageDialog.INFORMATION,MessageDialog.QUESTION,MessageDialog.WARNING,MessageDialog.CONFIRM, or {#QUESTION_WITH_CANCEL}.parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.style-SWT.NONEfor a default dialog, orSWT.SHEETfor a dialog with sheet behavior- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState() - Since:
- 3.5
-
open
public static MessageDialogWithToggle open(int kind, Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key, int style, LinkedHashMap<String, Integer> buttonLabelToIdMap) Convenience method to open a simple dialog as specified by thekindflag, with a "don't show again' toggle. This method accepts a LinkedHashMap<String, Integer> to set custom button labels (String) and custom button IDs (Integer) as return codes for those buttons. Use this method if you need to override the default labels and IDs.- Parameters:
kind- the kind of dialog to open, one ofMessageDialog.ERROR,MessageDialog.INFORMATION,MessageDialog.QUESTION,MessageDialog.WARNING,MessageDialog.CONFIRM, or {#QUESTION_WITH_CANCEL}.parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.style-SWT.NONEfor a default dialog, orSWT.SHEETfor a dialog with sheet behaviorbuttonLabelToIdMap- map with button labels and ids to define custom labels and their corresponding ids- Returns:
- the dialog, after being closed by the user, which the client can only
call
getReturnCode()orgetToggleState() - Since:
- 3.13
-
openError
public static MessageDialogWithToggle openError(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) 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 messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState()
-
openInformation
public static MessageDialogWithToggle openInformation(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) 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 messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState()
-
openOkCancelConfirm
public static MessageDialogWithToggle openOkCancelConfirm(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) 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 messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState()
-
openWarning
public static MessageDialogWithToggle openWarning(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) 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 messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState()
-
openYesNoCancelQuestion
public static MessageDialogWithToggle openYesNoCancelQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) Convenience method to open a simple question Yes/No/Cancel dialog.- Parameters:
parent- the parent shell of the dialog, ornullif nonetitle- the dialog's title, ornullif nonemessage- the messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState()
-
openYesNoQuestion
public static MessageDialogWithToggle openYesNoQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key) 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 messagetoggleMessage- the message for the toggle control, ornullfor the default messagetoggleState- the initial state for the togglestore- the IPreference store in which the user's preference should be persisted;nullif you don't want it persisted automatically.key- the key to use when persisting the user's preference;nullif you don't want it persisted.- Returns:
- the dialog, after being closed by the user, which the client can
only call
getReturnCode()orgetToggleState()
-
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 classMessageDialog- Parameters:
buttonId- the id of the button that was pressed (seeIDialogConstants.*_IDconstants)- See Also:
-
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 classMessageDialog- Parameters:
parent- the button bar composite- See Also:
-
createDialogArea
Description copied from class:MessageDialogThis implementation of theDialogframework method creates and lays out a composite and callscreateMessageAreaandcreateCustomAreato populate it. Subclasses should overridecreateCustomAreato add contents below the message.- Overrides:
createDialogAreain classMessageDialog- Parameters:
parent- the parent composite to contain the dialog area- Returns:
- the dialog area control
- See Also:
-
createToggleButton
Creates a toggle button without any text or state. The text and state will be created bycreateDialogArea.- Parameters:
parent- The composite in which the toggle button should be placed; must not benull.- Returns:
- The added toggle button; never
null.
-
getToggleButton
Returns the toggle button.- Returns:
- the toggle button
-
getPrefStore
An accessor for the current preference store for this dialog.- Returns:
- The preference store; this value may be
nullif no preference is being used.
-
getPrefKey
An accessor for the current key of the toggle preference.- Returns:
- The preference key; this value may be
nullif no preference is being used.
-
getToggleState
public boolean getToggleState()Returns the toggle state. This can be called even after the dialog is closed.- Returns:
trueif the toggle button is checked,falseif not
-
setPrefKey
A mutator for the key of the preference to be modified by the toggle button.- Parameters:
prefKey- The prefKey to set. If this value isnull, then no preference will be modified.
-
setPrefStore
A mutator for the preference store to be modified by the toggle button.- Parameters:
prefStore- The prefStore to set. If this value isnull, then no preference will be modified.
-
setToggleButton
A mutator for the button providing the toggle option. If the button exists, then it will automatically get the text set to the current toggle message, and its selection state set to the current selection state.- Parameters:
button- The button to use; must not benull.
-
setToggleMessage
A mutator for the text on the toggle button. The button will automatically get updated with the new text, if it exists.- Parameters:
message- The new text of the toggle button; if it isnull, then used the default toggle message.
-
setToggleState
public void setToggleState(boolean toggleState) A mutator for the state of the toggle button. This method will update the button, if it exists.- Parameters:
toggleState- The desired state of the toggle button (truemeans the toggle should be selected).
-