Represents the stack of active modal dialogs. Used in calls to
Application.invokeLater(java.lang.Runnable)
to specify
that the corresponding runnable is to be executed within the given modality state, i.e., when the same set modal dialogs is present, or its subset.
The primary purpose of the modality state is to guarantee code model (PSI/VFS/etc) correctness during user interaction.
Consider the following scenario:
- Some code invokes
SwingUtilities.invokeLater
- Before that, the user action is processed which shows a dialog (e.g., asking a yes/no question)
- While this dialog is shown, the event scheduled before is processed and does something very dramatic, e.g., removes a module from the project, deletes some files,
invalidates PSI
- The user closes the dialog
- The code that invoked that dialog now has to deal with the completely
changed world, where PSI that it worked with might be already invalid, dumb mode (see
DumbService
)
might have unexpectedly begun, etc.
Normally clients of yes/no question dialogs aren't prepared for this at all, so exceptions are likely to arise.
Worse than that, there'll be no indication on why a particular change has occurred, because the runnable that was incorrectly invoked-later will
in many cases leave no trace of itself.
For these reasons, it's strongly advised to use
Application.invokeLater(java.lang.Runnable)
everywhere.
SwingUtilities.invokeLater(Runnable)
,
any()
and
UIUtil
convenience methods may be used in the
purely UI-related code, but not with anything that deals with PSI or VFS.