X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2Fdialogrunner%2FDialogRunnerI.java;h=ce96bad25ff149ff7032d6811159d29db8b07592;hb=a8f8ffcf78dcc7bd81b56caaa1143101b6bd3afd;hp=758d421e11c516b3e208369778e3363c1585db52;hpb=2e02b14ba33c2cf4618f65c831a506f81e621589;p=jalview.git diff --git a/src/jalview/util/dialogrunner/DialogRunnerI.java b/src/jalview/util/dialogrunner/DialogRunnerI.java index 758d421..ce96bad 100644 --- a/src/jalview/util/dialogrunner/DialogRunnerI.java +++ b/src/jalview/util/dialogrunner/DialogRunnerI.java @@ -21,23 +21,40 @@ package jalview.util.dialogrunner; /** - * functional pattern for blocking dialog response handling + * An interface for blocking dialog response handling. This is motivated by + * JalviewJS - when running as Javascript, there is only a single thread, and + * blocking dialogs have to be responsible for performing any actions required + * for user responses. * * @author jprocter * */ -public interface DialogRunnerI +public interface DialogRunnerI { /** - * Adds a new response for this dialog, and returns the dialog (this), to allow chaining, eg. - *
-   * dialog.addResponse(newRunResponse(OK_PRessed) { run()...})
-   *     .addResponse(new RunResponse(CANCEL_PRESSED);
-   * 
+ * Sets the action to be performed when the dialog returns the given response. + * Note this also handles int-valued responses, which will be + * converted to Integer when this method is invoked. * + * @param response * @param action - * @return the dialog + * @return */ - T addResponse(RunResponse action); + DialogRunnerI setResponseHandler(Object response, Runnable action); + + // DialogRunnerI setResponseHandler(Object response, Runnable action); + + /** + * Runs the registered handler (if any) for the given response. The default + * action is to do nothing. Typically an action will be need on 'OK' or other + * positive selection in the dialog. An action might in some cases also be + * needed for a 'Cancel' response. + * + * @param response + * @return + */ + default void handleResponse(Object response) + { + } }