public abstract class DialogDisplayer extends Object
Modifier | Constructor and Description |
---|---|
protected |
DialogDisplayer()
Subclass constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract Dialog |
createDialog(DialogDescriptor descriptor)
Get a new standard dialog.
|
Dialog |
createDialog(DialogDescriptor descriptor,
Frame parent)
Same as #createDialog(org.openide.DialogDescriptor) except that it's possible
to specify dialog's parent Frame window.
|
static DialogDisplayer |
getDefault()
Get the default dialog displayer.
|
abstract Object |
notify(NotifyDescriptor descriptor)
Notify the user of something in a message box, possibly with feedback.
|
<T extends NotifyDescriptor> |
notifyFuture(T descriptor)
Notify the user by a message box.
|
void |
notifyLater(NotifyDescriptor descriptor)
Notify the user of something in a message box, possibly with feedback,
this method may be called
from any thread.
|
public static DialogDisplayer getDefault()
public abstract Object notify(NotifyDescriptor descriptor)
To support both GUI and non-GUI use, this method may be called from any thread (providing you are not holding any locks), and will block the caller's thread. In GUI mode, it will be run in the AWT event thread automatically. If you wish to hold locks, or do not need the result object immediately or at all, please make this call asynchronously (e.g. from the request processor).
descriptor
- description of the notificationpublic void notifyLater(NotifyDescriptor descriptor)
Implementation note: Since version 7.3, implementation improved to work also before main window is opened. For example: When method is called from ModuleInstall.restored, then modal dialog is opened and blocks main window until dialog is closed. Typical use case is login dialog.
descriptor
- description of the notificationpublic <T extends NotifyDescriptor> CompletableFuture<T> notifyFuture(T descriptor)
DialogDisplayer.notifyLater(org.openide.NotifyDescriptor)
. Unlike
DialogDisplayer.notifyLater(org.openide.NotifyDescriptor)
, this method returns a CompletableFuture
that will be
completed when the UI closes. The value of the returned CompletableFuture
is
the descriptor itself: it's NotifyDescriptor.getValue()
will be set to the
closing option. If a subclass, like NotifyDescriptor.InputLine
is used, the
task can query other values of NotifyDescriptor, such as the text entered.
Any exception thrown by NotifyDescriptor
processing will be reported through CompletableFuture.completeExceptionally(java.lang.Throwable)
.
It is possible to call CompletableFuture.cancel(boolean)
on the returned value.
The implementation may (through it is not guaranteed) abort and hide the UI. If cancel() is
called, the returned Future always completes exceptionally, with a CancellationException
.
The thread that will execute the continuation or exception handler is undefined. Use usual
precautions against EDT blocking and use CompletableFuture.thenAcceptAsync(java.util.function.Consumer, java.util.concurrent.Executor)
or similar to execute in a specific thread. Prefer usage of RequestProcessor
to the
builtin thread pool.
NotifyDescriptor
.InputLine nd = newNotifyDescriptor
.InputLine("Question", "Title");CompletableFuture
<UserData> resultFuture =DialogDisplayer
.getDefault().notifyFuture(nd). // compose with processing after dialog confirmation thenCompose(d -> { UserData userData = new UserData(); // this code will NOT execute, if user cancels "Question" dialog. Neither will execute subsequent steps. userData.answer1 = d.getInputText(); // do something with user input and display another questionNotifyDescriptor
.InputLine nd2 = newNotifyDescriptor
.InputLine("Question2", "Title"); returnDialogDisplayer
.getDefault().notifyFuture(nd). thenApply(x -> { // pass userData to the next step. // This code will NOT execute if the Question2 dialog is cancelled. userData.answer2 = x.getInputText(); return userData; }); }).thenApply((data) -> { // This code will not execute if Question or Question2 is cancelled. // do some finalization steps. return data; }).exceptionally(ex -> { // JDK-8233050: JDK reports direct exception from the immediate stage, but wrapped one from earlier stages. if (ex instanceofCompletionException
) { ex = ex.getCause(); } // reached if Question, Question2 is cancelled or if some error occurs. if (!(ex instanceofCancellationException
)) { // do error handling } return null; });
T
- actual subclass of NotifyDescriptor
passed as a parameter.descriptor
- describes the UI / dialog.public abstract Dialog createDialog(DialogDescriptor descriptor)
Do not cache the resulting dialog if it is modal and try to reuse it! Always create a new dialog using this method if you need to show a dialog again. Otherwise previously closed windows can reappear.
descriptor
- general description of the dialogpublic Dialog createDialog(DialogDescriptor descriptor, Frame parent)
descriptor
- general description of the dialogparent
- Dialgo parent frame.