DialogWrapper is the base class which is supposed to be used for all modal dialogs (and some non-modal dialogs) shown in IntelliJ Platform.
It provides the following features:
Button layout (platform-specific order of OK/ Cancel buttons, macOS-specific Help button)
Remembering the size of the dialog
Non-modal validation (displaying an error message text when the data entered into the dialog is not valid)
- Keyboard shortcuts:
Esc for closing the dialog
Left/Right for switching between buttons
Y/ N for Yes/ No actions if they exist in the dialog
Optional Do not ask again checkbox
When using the
DialogWrapper class for a dialog, follow these required steps:
Call the base class constructor and provide either a
Projectin the frame of which the dialog will be displayed, or a parent component for the dialog.
setTitle()method to set the title for the dialog
init()method from the constructor of the dialog class
createCenterPanel()method to return the component comprising the main contents of the dialog.
getPreferredFocusedComponent()method and return the component that should be focused when the dialog is first displayed.
getDimensionServiceKey()method to return the identifier which will be used for persisting the dialog dimensions.
getHelpId()method to return the context help topic associated with the dialog (see Context Help).
DialogWrapper class is often used together with GUI Designer forms. In this case, bind a GUI Designer form to the class extending
DialogWrapper, bind the top-level panel of the form to a field and return that field from the
createCenterPanel() method. When using Kotlin, use Kotlin UI DSL to provide the dialog's contents.
To display the dialog, call the
show() method and then use the
getExitCode() method to check how the dialog was closed (see
showAndGet() method can be used to combine these two calls.
To customize the buttons displayed in the dialog (replacing the standard OK/ Cancel/ Help set of buttons), override either the
createLeftActions() methods. Both of these methods return an array of Swing Action objects. If a button closes the dialog, use
DialogWrapperExitAction as the base class for the action. Use
action.putValue(DialogWrapper.DEFAULT_ACTION, true) to set the default button.
Please see also Validation errors topic in the IntelliJ Platform UI Guidelines.
To validate the data entered into the dialog, override the
doValidate() method. The method will be called automatically by timer. If the currently entered data is valid, return
null. Otherwise, return a
ValidationInfo object which encapsulates an error message, and an optional component associated with the invalid data. When specifying a component, an error icon will be displayed next to it, and it will be focused when the user tries to invoke the OK action.
Simple definition of a
SampleDialogWrapper dialog when user clicks on button: