Class PreferenceDialog
- All Implemented Interfaces:
IPageChangeProvider
,IPreferencePageContainer
,IShellProvider
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
Window.IExceptionHandler
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
Return code used when dialog failedstatic final String
Indentifier for the error imagestatic final String
Title area fieldsFields 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, ELLIPSIS
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK, resizeHasOccurred
-
Constructor Summary
ConstructorDescriptionPreferenceDialog
(Shell parentShell, PreferenceManager manager) Creates a new preference dialog under the control of the given preference manager. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addListeners
(TreeViewer viewer) Add the listeners to the tree viewer.void
addPageChangedListener
(IPageChangedListener listener) Adds a listener for page changes in this page change provider.protected void
buttonPressed
(int buttonId) Notifies that this dialog's button with the given id has been pressed.protected void
Notifies that the cancel button of this dialog has been pressed.boolean
close()
Closes this window, disposes its shell, and removes this window from its window manager (if it has one).protected void
configureShell
(Shell newShell) Configures the given shell in preparation for opening this window in it.protected void
Constrain the shell size to be no larger than the display bounds.protected void
createButtonsForButtonBar
(Composite parent) Adds buttons to this dialog's button bar.protected Control
createContents
(Composite parent) TheDialog
implementation of thisWindow
method 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 Control
createDialogArea
(Composite parent) Creates and returns the contents of the upper part of this dialog (above the button bar).protected void
createPage
(IPreferenceNode node) Create the page for the node.protected Composite
createPageContainer
(Composite parent) Creates the inner page container.protected void
createPageControl
(IPreferencePage page, Composite parent) Create the page control for the supplied page.protected Sash
createSash
(Composite composite, Control rightControl) Create the sash with right control on the right.protected Composite
createTitleArea
(Composite parent) Creates the wizard's title area.protected Control
createTreeAreaContents
(Composite parent) protected TreeViewer
createTreeViewer
(Composite parent) Create a newTreeViewer
.protected IPreferenceNode
findNodeMatching
(String nodeId) Find theIPreferenceNode
that has data the same id as the supplied value.protected void
firePageChanged
(PageChangedEvent event) Notifies any selection changed listeners that the selected page has changed.protected IPreferencePage
Returns the currentPage.protected int
Get the last known right side width.protected IPreferencePage
getPage
(IPreferenceNode node) Get the page for the node.protected Composite
Get the composite that is showing the page.protected Layout
Return the layout for the composite that contains the pages.Returns the preference mananger used by this preference dialog.Returns the preference store.protected String
Get the name of the selected item preferenceReturns the currently selected page in the dialog.protected IPreferenceNode
getSingleSelection
(ISelection selection) protected void
Save the values specified in the pages.protected void
Notifies that the window's close button was pressed, the close menu was selected, or the ESCAPE key pressed.protected void
Notifies of the pressing of the Help button.protected boolean
Returns whether the current page is valid.protected boolean
Returns a boolean indicating whether the dialog should be considered resizable when the shell style is initially set.protected void
layoutTreeAreaControl
(Control control) protected void
The preference dialog implementation of thisDialog
framework method sendsperformOk
to all pages of the preference dialog, then callshandleSave
on this dialog to save any state, and then callsclose
to close this dialog.void
Removes the given page change listener from this page change provider.protected void
Selects the saved item in the tree of preference pages.protected void
setCurrentPage
(IPreferencePage currentPage) Sets the current page.void
setErrorMessage
(String newErrorMessage) Display the given error message.void
setMessage
(String newMessage) Set the message text.void
setMessage
(String newMessage, int newType) Sets the message for this dialog with an indication of what type of message it is.void
setMinimumPageSize
(int minWidth, int minHeight) Sets the minimum page size.void
setMinimumPageSize
(Point size) Sets the minimum page size.protected void
setPageContainer
(Composite pageContainer) Set the composite that is showing the page.void
Sets the preference store for this preference dialog.void
setSelectedNode
(String pageId) Sets the name of the selected item preference.protected void
setSelectedNodePreference
(String pageId) Sets the name of the selected item preference.protected void
setTreeViewer
(TreeViewer treeViewer) Set the treeViewer.protected boolean
showPage
(IPreferenceNode node) Shows the preference page corresponding to the given preference node.protected void
update()
Updates this dialog's controls to reflect the current page.void
Adjusts the enable state of the OK button to reflect the state of the currently active page in this container.void
Updates the message (or error message) shown in the message line to reflect the state of the currently active page in this container.void
Updates the title to reflect the state of the currently active page in this container.protected void
updateTreeFont
(Font dialogFont) Update the tree to use the specifiedFont
.Methods inherited from class org.eclipse.jface.dialogs.TrayDialog
closeTray, createButtonBar, createHelpControl, getLayout, getTray, isDialogHelpAvailable, isHelpAvailable, openTray, setDialogHelpAvailable, setHelpAvailable
Methods inherited from class org.eclipse.jface.dialogs.Dialog
applyDialogFont, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, create, createButton, dialogFontIsDefault, getBlockedHandler, getButton, getButtonBar, getCancelButton, getDialogArea, getDialogBoundsSettings, getDialogBoundsStrategy, getImage, getInitialLocation, getInitialSize, getOKButton, initializeBounds, initializeDialogUnits, setBlockedHandler, setButtonLayoutData, setButtonLayoutFormData, shortenText
Methods inherited from class org.eclipse.jface.window.Window
canHandleShellCloseEvent, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, open, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
-
Field Details
-
PREF_DLG_IMG_TITLE_ERROR
Indentifier for the error image- See Also:
-
PREF_DLG_TITLE_IMG
Title area fields- See Also:
-
FAILED
protected static final int FAILEDReturn code used when dialog failed- See Also:
-
-
Constructor Details
-
PreferenceDialog
Creates a new preference dialog under the control of the given preference manager.- Parameters:
parentShell
- the parent shellmanager
- the preference manager
-
-
Method Details
-
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 callsokPressed
if the ok button is the pressed, andcancelPressed
if the cancel button is the pressed. All other button presses are ignored. Subclasses may override to handle other buttons, but should callsuper.buttonPressed
if the default handling of the ok and cancel buttons is desired.- Overrides:
buttonPressed
in classDialog
- Parameters:
buttonId
- the id of the button that was pressed (seeIDialogConstants.*_ID
constants)
-
cancelPressed
protected void cancelPressed()Description copied from class:Dialog
Notifies that the cancel button of this dialog has been pressed.The
Dialog
implementation of this framework method sets this dialog's return code toWindow.CANCEL
and closes the dialog. Subclasses may override if desired.- Overrides:
cancelPressed
in classDialog
-
close
public boolean close()Description copied from class:Window
Closes this window, disposes its shell, and removes this window from its window manager (if it has one).This framework method may be extended (
super.close
must be called).Note that in order to prevent recursive calls to this method it does not call
Shell#close()
. As a resultShellListener
s will not receive ashellClosed
event. -
configureShell
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 classWindow
- Parameters:
newShell
- the shell
-
constrainShellSize
protected void constrainShellSize()Description copied from class:Window
Constrain the shell size to be no larger than the display bounds.- Overrides:
constrainShellSize
in classWindow
-
createButtonsForButtonBar
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 thecreateButton
framework 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:
createButtonsForButtonBar
in classDialog
- Parameters:
parent
- the button bar composite
-
createContents
Description copied from class:Dialog
TheDialog
implementation of thisWindow
method 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 thecreateDialogArea
andcreateButtonBar
methods to create the dialog area and button bar, respectively. OverridingcreateDialogArea
andcreateButtonBar
are recommended rather than overriding this method.- Overrides:
createContents
in classDialog
- 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
Description copied from class:Dialog
Creates and returns the contents of the upper part of this dialog (above the button bar).The
Dialog
implementation of this framework method creates and returns a newComposite
with 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
super
as in the following example:Composite composite = (Composite) super.createDialogArea(parent); //add controls to composite as necessary return composite;
- Overrides:
createDialogArea
in classDialog
- Parameters:
parent
- the parent composite to contain the dialog area- Returns:
- the dialog area control
-
createSash
Create the sash with right control on the right. Note that this method assumes GridData for the layout data of the rightControl.- Parameters:
composite
- the parent compositerightControl
- control for the right part of the created sash- Returns:
- Sash
- Since:
- 3.1
-
createPageContainer
Creates the inner page container.- Parameters:
parent
- the parent composite- Returns:
- Composite
-
getPageLayout
Return the layout for the composite that contains the pages.- Returns:
- PageLayout
- Since:
- 3.1
-
createTitleArea
Creates the wizard's title area.- Parameters:
parent
- the SWT parent for the title area composite.- Returns:
- the created title area composite.
-
createTreeAreaContents
- Parameters:
parent
- the SWT parent for the tree area controls.- Returns:
- the new
Control
. - Since:
- 3.0
-
createTreeViewer
Create a newTreeViewer
.- Parameters:
parent
- the parentComposite
.- Returns:
- the
TreeViewer
. - Since:
- 3.0
-
addListeners
Add the listeners to the tree viewer.- Parameters:
viewer
- viewer to add listeners to- Since:
- 3.1
-
findNodeMatching
Find theIPreferenceNode
that has data the same id as the supplied value.- Parameters:
nodeId
- the id to search for.- Returns:
IPreferenceNode
ornull
if not found.
-
getLastRightWidth
protected int getLastRightWidth()Get the last known right side width.- Returns:
- the width.
-
getPreferenceManager
Returns the preference mananger used by this preference dialog.- Returns:
- the preference mananger
-
getPreferenceStore
Description copied from interface:IPreferencePageContainer
Returns the preference store.- Specified by:
getPreferenceStore
in interfaceIPreferencePageContainer
- Returns:
- the preference store, or
null
if none
-
getSelectedNodePreference
Get the name of the selected item preference- Returns:
- String
-
getSingleSelection
- Parameters:
selection
- theISelection
to examine.- Returns:
- the first element, or null if empty.
-
getTreeViewer
- Returns:
- the
TreeViewer
for this dialog. - Since:
- 3.3
-
handleSave
protected void handleSave()Save the values specified in the pages.The default implementation of this framework method saves all pages of type
PreferencePage
(if their store needs saving and is aPreferenceStore
).Subclasses may override.
-
handleShellCloseEvent
protected void handleShellCloseEvent()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 usingclose
. Subclasses may extend or reimplement.- Overrides:
handleShellCloseEvent
in classTrayDialog
-
helpPressed
protected void helpPressed()Notifies of the pressing of the Help button.The default implementation of this framework method calls
performHelp
on the currently active page. -
isCurrentPageValid
protected boolean isCurrentPageValid()Returns whether the current page is valid.- Returns:
false
if the current page is not valid, or ortrue
if the current page is valid or there is no current page
-
layoutTreeAreaControl
- Parameters:
control
- theControl
to lay out.- Since:
- 3.0
-
okPressed
protected void okPressed()The preference dialog implementation of thisDialog
framework method sendsperformOk
to all pages of the preference dialog, then callshandleSave
on this dialog to save any state, and then callsclose
to close this dialog. -
selectSavedItem
protected void selectSavedItem()Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one. -
setErrorMessage
Display the given error message. The currently displayed message is saved and will be redisplayed when the error message is set tonull
.- Parameters:
newErrorMessage
- the errorMessage to display ornull
-
setMessage
Set the message text. If the message line currently displays an error, the message is stored and will be shown after a call to clearErrorMessageShortcut for
setMessage(newMessage, NONE)
- Parameters:
newMessage
- the message, ornull
to clear the message
-
setMessage
Sets the message for this dialog with an indication of what type of message it is.The valid message types are one of
NONE
,INFORMATION
,WARNING
, orERROR
.Note that for backward compatibility, a message of type
ERROR
is different than an error message (set usingsetErrorMessage
). An error message overrides the current message until the error message is cleared. This method replaces the current message and does not affect the error message.- Parameters:
newMessage
- the message, ornull
to clear the messagenewType
- the message type- Since:
- 2.0
-
setMinimumPageSize
public void setMinimumPageSize(int minWidth, int minHeight) Sets the minimum page size.- Parameters:
minWidth
- the minimum page widthminHeight
- the minimum page height- See Also:
-
setMinimumPageSize
Sets the minimum page size.- Parameters:
size
- the page size encoded asnew Point(width,height)
- See Also:
-
setPreferenceStore
Sets the preference store for this preference dialog.- Parameters:
store
- the preference store- See Also:
-
setSelectedNode
Sets the name of the selected item preference. Public equivalent tosetSelectedNodePreference
.- Parameters:
pageId
- The identifier for the page- Since:
- 3.0
-
setSelectedNodePreference
Sets the name of the selected item preference.- Parameters:
pageId
- The identifier for the page
-
showPage
Shows the preference page corresponding to the given preference node. Does nothing if that page is already current.- Parameters:
node
- the preference node, ornull
if none- Returns:
true
if the page flip was successful, andfalse
is unsuccessful
-
createPage
Create the page for the node.- Parameters:
node
- the node to create page for- Since:
- 3.1
-
getPage
Get the page for the node.- Parameters:
node
- the node to get page for- Returns:
- IPreferencePage
- Since:
- 3.1
-
update
protected void update()Updates this dialog's controls to reflect the current page. -
updateButtons
public void updateButtons()Description copied from interface:IPreferencePageContainer
Adjusts the enable state of the OK button to reflect the state of the currently active page in this container.This method is called by the container itself when its preference page changes and may be called by the page at other times to force a button state update.
- Specified by:
updateButtons
in interfaceIPreferencePageContainer
-
updateMessage
public void updateMessage()Description copied from interface:IPreferencePageContainer
Updates the message (or error message) shown in the message line to reflect the state of the currently active page in this container.This method is called by the container itself when its preference page changes and may be called by the page at other times to force a message update.
- Specified by:
updateMessage
in interfaceIPreferencePageContainer
-
updateTitle
public void updateTitle()Description copied from interface:IPreferencePageContainer
Updates the title to reflect the state of the currently active page in this container.This method is called by the container itself when its page changes and may be called by the page at other times to force a title update.
- Specified by:
updateTitle
in interfaceIPreferencePageContainer
-
updateTreeFont
Update the tree to use the specifiedFont
.- Parameters:
dialogFont
- theFont
to use.- Since:
- 3.0
-
getCurrentPage
Returns the currentPage.- Returns:
- IPreferencePage
- Since:
- 3.1
-
setCurrentPage
Sets the current page.- Parameters:
currentPage
- page to set- Since:
- 3.1
-
setTreeViewer
Set the treeViewer.- Parameters:
treeViewer
- viewer to set- Since:
- 3.1
-
getPageContainer
Get the composite that is showing the page.- Returns:
- Composite.
- Since:
- 3.1
-
setPageContainer
Set the composite that is showing the page.- Parameters:
pageContainer
- Composite- Since:
- 3.1
-
createPageControl
Create the page control for the supplied page.- Parameters:
page
- - the preference page to be shownparent
- - the composite to parent the page- Since:
- 3.1
-
getSelectedPage
Description copied from interface:IPageChangeProvider
Returns the currently selected page in the dialog.- Specified by:
getSelectedPage
in interfaceIPageChangeProvider
- Returns:
- the selected page in the dialog or
null
if none is selected. The type may be domain specific. In the JFace provided dialogs this will be an instance ofIDialogPage
. - Since:
- 3.1
- See Also:
-
addPageChangedListener
Description copied from interface:IPageChangeProvider
Adds a listener for page changes in this page change provider. Has no effect if an identical listener is already registered.- Specified by:
addPageChangedListener
in interfaceIPageChangeProvider
- Parameters:
listener
- a page changed listener- Since:
- 3.1
- See Also:
-
removePageChangedListener
Description copied from interface:IPageChangeProvider
Removes the given page change listener from this page change provider. Has no effect if an identical listener is not registered.- Specified by:
removePageChangedListener
in interfaceIPageChangeProvider
- Parameters:
listener
- a page changed listener- Since:
- 3.1
- See Also:
-
firePageChanged
Notifies any selection changed listeners that the selected page has changed. Only listeners registered at the time this method is called are notified.- Parameters:
event
- a selection changed event- Since:
- 3.1
- See Also:
-
isResizable
protected boolean isResizable()Description copied from class:Dialog
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.- Overrides:
isResizable
in classDialog
- Returns:
- a boolean indicating whether the dialog is resizable and should have the default style bits for resizable dialogs
-