Interface Dialog.CancelRequest

Enclosing class:
Dialog

public static sealed interface Dialog.CancelRequest
One question to a dialog's Dialog.onCancel handler: may the dialog close with its cancel result? Answered once, with allow() or refuse(), now or later: a handler that shows a dialog of its own over this one keeps the request and answers from that dialog's result. Keeping it unanswered is how a handler holds it, and while it is held the dialog is not asked again.

allow() closes the dialog with its cancel result, so it is the answer for "close and lose the changes" only. A different answer, the Save of a "Save changes?" question asked over a form, is given with request.dialog().dismiss(result): the dialog closes with that result, which is what the code that showed it acts on, and the request is settled by it.


 form.onCancel(request -> question.show(scene).thenAccept(answer -> {
     if ("cancel".equals(answer)) {
         request.refuse();                  // back to the form, as it was left
     } else {
         request.dialog().dismiss(answer);  // the form closes with "save" or "discard"
     }
 }));
 

A request the dialog settles itself, because it was answered another way (a button that is not the cancel, Dialog.dismiss(java.lang.String), its window or its owner going away) while the request was held, is over: its answer, given later, then does nothing, and a second one throws, as on every request. isAnswered() says whether allow or refuse has been called, as a window's and a tab's request do; whether the dialog has closed is its result's to say.

Only Limn implements this interface. A test asks a handler the way the user does, with Escape, a click or a window's close through the headless backend of limn-test.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    How the user closed the dialog.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the dialog with its cancel result, as the user's gesture would have: through the fade, or at once under less motion; nothing, if the dialog closed another way meanwhile.
     
    boolean
     
     
    void
    Keeps the dialog open, with the keyboard where it was; nothing, if the dialog closed another way meanwhile.
  • Method Details

    • dialog

      Dialog dialog()
      Returns:
      the dialog asked about, whose Dialog.dismiss(java.lang.String) gives it an answer of the handler's own
    • reason

      Returns:
      how the user closed the dialog
    • allow

      void allow()
      Closes the dialog with its cancel result, as the user's gesture would have: through the fade, or at once under less motion; nothing, if the dialog closed another way meanwhile. UI thread only.
      Throws:
      IllegalStateException - if the request was already answered with allow or refuse
    • refuse

      void refuse()
      Keeps the dialog open, with the keyboard where it was; nothing, if the dialog closed another way meanwhile. UI thread only.
      Throws:
      IllegalStateException - if the request was already answered with allow or refuse
    • isAnswered

      boolean isAnswered()
      Returns:
      whether allow() or refuse() has been called