Class Dialog
- All Implemented Interfaces:
IShellProvider
- Direct Known Subclasses:
EditorSelectionDialog,IconAndMessageDialog,InputDialog,ResizableDialog,TrayDialog,ViewSettingsDialog
Dialogs are usually modal. Consequently, it is generally bad practice to open a dialog without a parent. A modal dialog without a parent is not prevented from disappearing behind the application's other windows, making it very confusing for the user.
If more than one modal dialog is open, the second one should be parented off of the shell of the first one. Otherwise, it is possible that the OS will give focus to the first dialog, potentially blocking the UI.
This class also moves the default button to the right if required, see
initializeBounds().
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic IDialogBlockedHandlerCreate a default instance of the blocked handler which does not do anything.The button bar;nulluntil dialog is layed out.static final intA value that can be used for stored dialog width or height that indicates that the default bounds should be used.static final intPersist the last location of the dialog.static final intPersist the last known size of the dialog.protected ControlThe dialog area;nulluntil dialog is layed out.static final StringDeprecated, for removal: This API element is subject to removal in a future version.use org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_ERROR)static final StringImage registry key for help image (value"dialog_help_image").static final StringDeprecated, for removal: This API element is subject to removal in a future version.use org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_INFORMATION)static final StringImage registry key for info message image (value"dialog_message_error_image").static final StringImage registry key for info message image (value"dialog_messasge_info_image").static final StringImage registry key for info message image (value"dialog_messasge_warning_image").static final StringDeprecated, for removal: This API element is subject to removal in a future version.org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_QUESTION)static final StringDeprecated.use org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_WARNING)static final StringThe ellipsis is the string that is used to represent shortened text.Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK, resizeHasOccurred -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDialog(IShellProvider parentShell) Creates a dialog with the given parent.protectedCreates a dialog instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyDialogFont(Control control) Applies the dialog font to all controls that currently have the default font.protected voidbuttonPressed(int buttonId) Notifies that this dialog's button with the given id has been pressed.protected voidNotifies that the cancel button of this dialog has been pressed.booleanclose()Closes this window, disposes its shell, and removes this window from its window manager (if it has one).protected intconvertHeightInCharsToPixels(int chars) Returns the number of pixels corresponding to the height of the given number of characters.static intconvertHeightInCharsToPixels(FontMetrics fontMetrics, int chars) Returns the number of pixels corresponding to the height of the given number of characters.protected intconvertHorizontalDLUsToPixels(int dlus) Returns the number of pixels corresponding to the given number of horizontal dialog units.static intconvertHorizontalDLUsToPixels(FontMetrics fontMetrics, int dlus) Returns the number of pixels corresponding to the given number of horizontal dialog units.protected intconvertVerticalDLUsToPixels(int dlus) Returns the number of pixels corresponding to the given number of vertical dialog units.static intconvertVerticalDLUsToPixels(FontMetrics fontMetrics, int dlus) Returns the number of pixels corresponding to the given number of vertical dialog units.protected intconvertWidthInCharsToPixels(int chars) Returns the number of pixels corresponding to the width of the given number of characters.static intconvertWidthInCharsToPixels(FontMetrics fontMetrics, int chars) Returns the number of pixels corresponding to the width of the given number of characters.voidcreate()Creates this window's widgetry in a new top-level shell.protected ButtoncreateButton(Composite parent, int id, String label, boolean defaultButton) Creates a new button with the given id.protected ControlcreateButtonBar(Composite parent) Creates and returns the contents of this dialog's button bar.protected voidcreateButtonsForButtonBar(Composite parent) Adds buttons to this dialog's button bar.protected ControlcreateContents(Composite parent) TheDialogimplementation of thisWindowmethod creates and lays out the top level composite for the dialog, and determines the appropriate horizontal and vertical dialog units based on the font size.protected ControlcreateDialogArea(Composite parent) Creates and returns the contents of the upper part of this dialog (above the button bar).protected static booleanReturn whether or not the dialog font is currently the same as the default font.static IDialogBlockedHandlerGet the IDialogBlockedHandler to be used by WizardDialogs and ModalContexts.protected ButtongetButton(int id) Returns the button created by the methodcreateButtonfor the specified ID as defined onIDialogConstants.protected ControlReturns the button bar control.protected ButtonDeprecated.UsegetButton(IDialogConstants.CANCEL_ID)instead.protected ControlReturns the dialog area control.protected IDialogSettingsGets the dialog settings that should be used for remembering the bounds of of the dialog, according to the dialog bounds strategy.protected intGet the integer constant that describes the strategy for persisting the dialog bounds.static ImageReturns the standard dialog image with the given key.protected PointgetInitialLocation(Point initialSize) Returns the initial location to use for the shell.protected PointReturns the initial size to use for the shell.protected ButtonDeprecated.UsegetButton(IDialogConstants.OK_ID)instead.protected voidInitializes the location and size of this window's SWT shell after it has been created.protected voidinitializeDialogUnits(Control control) Initializes the computation of horizontal and vertical dialog units based on the size of current font.protected booleanReturns a boolean indicating whether the dialog should be considered resizable when the shell style is initially set.protected voidNotifies that the ok button of this dialog has been pressed.static voidsetBlockedHandler(IDialogBlockedHandler blockedHandler) Set the IDialogBlockedHandler to be used by WizardDialogs and ModalContexts.protected voidsetButtonLayoutData(Button button) Set the layout data of the button to a GridData with appropriate heights and widths.protected voidsetButtonLayoutFormData(Button button) Set the layout data of the button to a FormData with appropriate heights and widths.static StringshortenText(String textValue, Control control) Try to shorten the given texttextValueso that its width in pixels does not exceed the width of the given control.Methods inherited from class org.eclipse.jface.window.Window
canHandleShellCloseEvent, configureShell, constrainShellSize, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getLayout, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, open, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
-
Field Details
-
DLG_IMG_ERROR
Deprecated, for removal: This API element is subject to removal in a future version.use org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_ERROR)Image registry key for error image (value"dialog_error_image").- See Also:
-
DLG_IMG_INFO
Deprecated, for removal: This API element is subject to removal in a future version.use org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_INFORMATION)Image registry key for info image (value"dialog_info_image").- See Also:
-
DLG_IMG_QUESTION
Deprecated, for removal: This API element is subject to removal in a future version.org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_QUESTION)Image registry key for question image (value"dialog_question_image").- See Also:
-
DLG_IMG_WARNING
Deprecated.use org.eclipse.swt.widgets.Display.getSystemImage(SWT.ICON_WARNING)Image registry key for warning image (value"dialog_warning_image").- See Also:
-
DLG_IMG_MESSAGE_INFO
Image registry key for info message image (value"dialog_messasge_info_image").- Since:
- 2.0
- See Also:
-
DLG_IMG_MESSAGE_WARNING
Image registry key for info message image (value"dialog_messasge_warning_image").- Since:
- 2.0
- See Also:
-
DLG_IMG_MESSAGE_ERROR
Image registry key for info message image (value"dialog_message_error_image").- Since:
- 2.0
- See Also:
-
DLG_IMG_HELP
Image registry key for help image (value"dialog_help_image").- Since:
- 3.2
- See Also:
-
ELLIPSIS
The ellipsis is the string that is used to represent shortened text.- Since:
- 3.0
- See Also:
-
DIALOG_DEFAULT_BOUNDS
public static final int DIALOG_DEFAULT_BOUNDSA value that can be used for stored dialog width or height that indicates that the default bounds should be used.- Since:
- 3.2
- See Also:
-
DIALOG_PERSISTLOCATION
public static final int DIALOG_PERSISTLOCATIONPersist the last location of the dialog.- Since:
- 3.2
- See Also:
-
DIALOG_PERSISTSIZE
public static final int DIALOG_PERSISTSIZEPersist the last known size of the dialog.- Since:
- 3.2
- See Also:
-
dialogArea
The dialog area;nulluntil dialog is layed out. -
buttonBar
The button bar;nulluntil dialog is layed out. -
blockedHandler
Create a default instance of the blocked handler which does not do anything.
-
-
Constructor Details
-
Dialog
Creates a dialog instance. Note that the window will have no visual representation (no widgets) until it is told to open. By default,openblocks for dialogs.- Parameters:
parentShell- the parent shell, ornullto create a top-level shell
-
Dialog
Creates a dialog with the given parent.- Parameters:
parentShell- object that returns the current parent shell- Since:
- 3.1
-
-
Method Details
-
convertHeightInCharsToPixels
Returns the number of pixels corresponding to the height of the given number of characters.The required
FontMetricsparameter may be created in the following way:GC gc = new GC(control); gc.setFont(control.getFont()); fontMetrics = gc.getFontMetrics(); gc.dispose();
- Parameters:
fontMetrics- used in performing the conversionchars- the number of characters- Returns:
- the number of pixels
- Since:
- 2.0
-
convertHorizontalDLUsToPixels
Returns the number of pixels corresponding to the given number of horizontal dialog units.The required
FontMetricsparameter may be created in the following way:GC gc = new GC(control); gc.setFont(control.getFont()); fontMetrics = gc.getFontMetrics(); gc.dispose();
- Parameters:
fontMetrics- used in performing the conversiondlus- the number of horizontal dialog units- Returns:
- the number of pixels
- Since:
- 2.0
-
convertVerticalDLUsToPixels
Returns the number of pixels corresponding to the given number of vertical dialog units.The required
FontMetricsparameter may be created in the following way:GC gc = new GC(control); gc.setFont(control.getFont()); fontMetrics = gc.getFontMetrics(); gc.dispose();
- Parameters:
fontMetrics- used in performing the conversiondlus- the number of vertical dialog units- Returns:
- the number of pixels
- Since:
- 2.0
-
convertWidthInCharsToPixels
Returns the number of pixels corresponding to the width of the given number of characters.The required
FontMetricsparameter may be created in the following way:GC gc = new GC(control); gc.setFont(control.getFont()); fontMetrics = gc.getFontMetrics(); gc.dispose();
- Parameters:
fontMetrics- used in performing the conversionchars- the number of characters- Returns:
- the number of pixels
- Since:
- 2.0
-
shortenText
Try to shorten the given texttextValueso that its width in pixels does not exceed the width of the given control. Overrides characters in the center of the original string with an ellipsis ("...") if necessary. If anullvalue is given,nullis returned.Note: if the text cannot be shortened because the width of control is too low the full original string is returned.
- Parameters:
textValue- the original string ornullcontrol- the control the string will be displayed on- Returns:
- the string to display, or
nullif null was passed in - Since:
- 3.0
-
buttonPressed
protected void buttonPressed(int buttonId) Notifies 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.- Parameters:
buttonId- the id of the button that was pressed (seeIDialogConstants.*_IDconstants)
-
cancelPressed
protected void cancelPressed()Notifies that the cancel button of this dialog has been pressed.The
Dialogimplementation of this framework method sets this dialog's return code toWindow.CANCELand closes the dialog. Subclasses may override if desired. -
convertHeightInCharsToPixels
protected int convertHeightInCharsToPixels(int chars) Returns the number of pixels corresponding to the height of the given number of characters.This method may only be called after
initializeDialogUnitshas been called.Clients may call this framework method, but should not override it.
- Parameters:
chars- the number of characters- Returns:
- the number of pixels
-
convertHorizontalDLUsToPixels
protected int convertHorizontalDLUsToPixels(int dlus) Returns the number of pixels corresponding to the given number of horizontal dialog units.This method may only be called after
initializeDialogUnitshas been called.Clients may call this framework method, but should not override it.
- Parameters:
dlus- the number of horizontal dialog units- Returns:
- the number of pixels
-
convertVerticalDLUsToPixels
protected int convertVerticalDLUsToPixels(int dlus) Returns the number of pixels corresponding to the given number of vertical dialog units.This method may only be called after
initializeDialogUnitshas been called.Clients may call this framework method, but should not override it.
- Parameters:
dlus- the number of vertical dialog units- Returns:
- the number of pixels
-
convertWidthInCharsToPixels
protected int convertWidthInCharsToPixels(int chars) Returns the number of pixels corresponding to the width of the given number of characters.This method may only be called after
initializeDialogUnitshas been called.Clients may call this framework method, but should not override it.
- Parameters:
chars- the number of characters- Returns:
- the number of pixels
-
createButton
Creates 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,
initializeBounds()will move the default button to the right.- 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:
-
createButtonBar
Creates and returns the contents of this dialog's button bar.The
Dialogimplementation of this framework method lays out a button bar and calls thecreateButtonsForButtonBarframework method to populate it. Subclasses may override.The returned control's layout data must be an instance of
GridData.- Parameters:
parent- the parent composite to contain the button bar- Returns:
- the button bar control
-
createButtonsForButtonBar
Adds 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,
initializeBounds()will move the default button to the right.- Parameters:
parent- the button bar composite
-
initializeBounds
protected void initializeBounds()Initializes the location and size of this window's SWT shell after it has been created.This framework method is called by the
createframework method. The default implementation callsgetInitialSizeandgetInitialLocationand passes the results toShell.setBounds. This is only done if the bounds of the shell have not already been modified. Subclasses may extend or reimplement.The implementation in
Dialog(org.eclipse.jface.window.IShellProvider)also moves thedefault buttonin thebutton barto the right if that's required by theplatform convention.- Overrides:
initializeBoundsin classWindow
-
createContents
TheDialogimplementation of thisWindowmethod creates and lays out the top level composite for the dialog, and determines the appropriate horizontal and vertical dialog units based on the font size. It then calls thecreateDialogAreaandcreateButtonBarmethods to create the dialog area and button bar, respectively. OverridingcreateDialogAreaandcreateButtonBarare recommended rather than overriding this method.- Overrides:
createContentsin classWindow- Parameters:
parent- the parent composite for the controls in this window. The type of layout used is determined by getLayout()- Returns:
- the control that will be returned by subsequent calls to getContents()
-
createDialogArea
Creates and returns the contents of the upper part of this dialog (above the button bar).The
Dialogimplementation of this framework method creates and returns a newCompositewith 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
superas in the following example:Composite composite = (Composite) super.createDialogArea(parent); //add controls to composite as necessary return composite;
- Parameters:
parent- the parent composite to contain the dialog area- Returns:
- the dialog area control
-
getButton
Returns the button created by the methodcreateButtonfor the specified ID as defined onIDialogConstants. IfcreateButtonwas never called with this ID, or ifcreateButtonis overridden, this method will returnnull.- Parameters:
id- the id of the button to look for- Returns:
- the button for the ID or
null - Since:
- 2.0
- See Also:
-
getButtonBar
Returns the button bar control.Clients may call this framework method, but should not override it.
- Returns:
- the button bar, or
nullif the button bar has not been created yet
-
getCancelButton
Deprecated.UsegetButton(IDialogConstants.CANCEL_ID)instead. This method will be removed soon.Returns the button created whencreateButtonis called with an ID ofIDialogConstants.CANCEL_ID. IfcreateButtonwas never called with this parameter, or ifcreateButtonis overridden,getCancelButtonwill returnnull.- Returns:
- the cancel button or
null - Since:
- 2.0
- See Also:
-
getDialogArea
Returns the dialog area control.Clients may call this framework method, but should not override it.
- Returns:
- the dialog area, or
nullif the dialog area has not been created yet
-
getImage
Returns the standard dialog image with the given key. Note that these images are managed by the dialog framework, and must not be disposed by another party.- Parameters:
key- one of theDialog.DLG_IMG_*constants- Returns:
- the standard dialog image NOTE: Dialog does not use the following images in the registry DLG_IMG_ERROR DLG_IMG_INFO DLG_IMG_QUESTION DLG_IMG_WARNING They are now coming directly from SWT, see ImageRegistry. For backwards compatibility they are still supported, however new code should use SWT for these.
- See Also:
-
getOKButton
Deprecated.UsegetButton(IDialogConstants.OK_ID)instead. This method will be removed soon.Returns the button created whencreateButtonis called with an ID ofIDialogConstants.OK_ID. IfcreateButtonwas never called with this parameter, or ifcreateButtonis overridden,getOKButtonwill returnnull.- Returns:
- the OK button or
null - Since:
- 2.0
- See Also:
-
initializeDialogUnits
Initializes the computation of horizontal and vertical dialog units based on the size of current font.This method must be called before any of the dialog unit based conversion methods are called.
- Parameters:
control- a control from which to obtain the current font
-
okPressed
protected void okPressed()Notifies that the ok button of this dialog has been pressed.The
Dialogimplementation of this framework method sets this dialog's return code toWindow.OKand closes the dialog. Subclasses may override. -
setButtonLayoutData
Set the layout data of the button to a GridData with appropriate heights and widths.- Parameters:
button- The button which layout data is to be set.
-
setButtonLayoutFormData
Set the layout data of the button to a FormData with appropriate heights and widths.- Parameters:
button- The button which layout data is to be set.
-
close
public boolean close()Description copied from class:WindowCloses this window, disposes its shell, and removes this window from its window manager (if it has one).This framework method may be extended (
super.closemust be called).Note that in order to prevent recursive calls to this method it does not call
Shell#close(). As a resultShellListeners will not receive ashellClosedevent. -
applyDialogFont
Applies the dialog font to all controls that currently have the default font.- Parameters:
control- the control to apply the font to. Font will also be applied to its children. If the control isnullnothing happens.
-
dialogFontIsDefault
protected static boolean dialogFontIsDefault()Return whether or not the dialog font is currently the same as the default font.- Returns:
- boolean if the two are the same
-
create
public void create()Description copied from class:WindowCreates this window's widgetry in a new top-level shell.The default implementation of this framework method creates this window's shell (by calling
createShell), and its controls (by callingcreateContents), then initializes this window's shell bounds (by callinginitializeBounds). -
getBlockedHandler
Get the IDialogBlockedHandler to be used by WizardDialogs and ModalContexts.- Returns:
- Returns the blockedHandler.
-
setBlockedHandler
Set the IDialogBlockedHandler to be used by WizardDialogs and ModalContexts.- Parameters:
blockedHandler- The blockedHandler for the dialogs.
-
getDialogBoundsSettings
Gets the dialog settings that should be used for remembering the bounds of of the dialog, according to the dialog bounds strategy.- Returns:
- settings the dialog settings used to store the dialog's location
and/or size, or
nullif the dialog's bounds should never be stored. - Since:
- 3.2
- See Also:
-
getDialogBoundsStrategy
protected int getDialogBoundsStrategy()Get the integer constant that describes the strategy for persisting the dialog bounds. This strategy is ignored if the implementer does not also specify the dialog settings for storing the bounds in Dialog.getDialogBoundsSettings().- Returns:
- the constant describing the strategy for persisting the dialog bounds.
- Since:
- 3.2
- See Also:
-
getInitialSize
Returns the initial size to use for the shell. Overridden to check whether a size has been stored in dialog settings. If a size has been stored, it is returned.- Overrides:
getInitialSizein classWindow- Returns:
- the initial size of the shell
- Since:
- 3.2
- See Also:
-
getInitialLocation
Returns the initial location to use for the shell. Overridden to check whether the bounds of the dialog have been stored in dialog settings. If a location has been stored, it is returned.- Overrides:
getInitialLocationin classWindow- Parameters:
initialSize- the initial size of the shell, as returned bygetInitialSize.- Returns:
- the initial location of the shell
- Since:
- 3.2
- See Also:
-
isResizable
protected boolean isResizable()Returns a boolean indicating whether the dialog should be considered resizable when the shell style is initially set.This method is used to ensure that all style bits appropriate for resizable dialogs are added to the shell style. Individual dialogs may always set the shell style to ensure that a dialog is resizable, but using this method ensures that resizable dialogs will be created with the same set of style bits.
Style bits will never be removed based on the return value of this method. For example, if a dialog returns
false, but also sets a style bit for a SWT.RESIZE border, the style bit will be honored.- Returns:
- a boolean indicating whether the dialog is resizable and should have the default style bits for resizable dialogs
- Since:
- 3.4
-