/** * Parameters for the dialog. * * @param message Text message * @param title Title of dialog * @param styles Style classes for icon, message text, and panel (pipe-delimited) * @param responses Button captions separated by vertical bars * @param excludeResponses Only applies if saveResponseId is specified. This is a list of * responses that will not be saved and is specified in the same format as the * buttonCaptions parameter. * @param defaultResponse Caption of button to have initial focus * @param saveResponseId Uniquely identifies this response for purposes of saving and retrieving * the last response. If not specified (null or empty), the response is not saved. * Otherwise, if a saved response exists, it is returned without displaying the * dialog. If a saved response does not exist, the user is prompted in the normal * manner with the addition of a check box on the dialog asking if the response is to * be saved. If this box is checked, the user's response is then saved as a user * preference. * @param callback Callback to receive response. * @return DialogParameters instance. */ public static DialogControl<String> create(String message, String title, String styles, String responses, String excludeResponses, String defaultResponse, String saveResponseId, IPromptCallback<String> callback) { return new DialogControl<>(message, title, styles, toList(responses), toList(excludeResponses), defaultResponse, saveResponseId, callback); }
private static void showDialog(String message, String title, String style) { DialogControl<String> ctl = DialogControl.create(message, title, style, LABEL_ID_OK, null, null, null, null); PromptDialog.show(ctl); }
@Override public void afterInitialized(BaseComponent comp) { this.root = (Window) comp; root.setAttribute("controller", this); control = (DialogControl<?>) root.getAttribute("control"); root.setTitle(control.getTitle()); icon.addClass(control.getIconClass()); message.addClass(control.getTextClass()); message.setLabel(control.getMessage()); root.addClass(control.getPanelClass()); chkRemember.setVisible(root.hasAttribute("remember")); root.setOnCanClose(() -> { control.callback(response); return true; }); if (control.getFormat() == ChoiceFormat.BUTTONS) { processButtonResponses(); } else { processListResponses(); } }
DialogResponse<?> response = control.getLastResponse(); control.callback(response); return;
private void processButtonResponses() { List<?> responses = control.getResponses(); for (Object rsp : responses) { DialogResponse<?> response = (DialogResponse<?>) rsp; Button button = addButton(response.getLabel(), response.getFlavor(), clickListener); button.setData(response); if (response.isDefault()) { button.setFocus(true); } } }
private void processListResponses() { List<?> responses = control.getResponses(); listbox.setVisible(true); for (Object rsp : responses) { DialogResponse<?> response = (DialogResponse<?>) rsp; Listitem item = new Listitem(StrUtil.formatMessage(response.getLabel())); item.addEventListener(DblclickEvent.TYPE, clickListener); item.setData(response); listbox.addChild(item); if (response.isDefault()) { item.setSelected(true); } } if (listbox.getSelectedCount() == 0) { listbox.setSelectedItem(listbox.getChild(Listitem.class)); } addButton(LABEL_ID_CANCEL, "danger", (event) -> { close(null); }); addButton(LABEL_ID_OK, "success", (event) -> { close(listbox.getSelectedItem()); }); }
public static void prompt(String message, String title, String styles, String responses, String exclusions, String defaultResponse, String responseId, IResponseCallback<DialogResponse<String>> callback) { DialogControl<String> ctl = DialogControl.create(message, title, styles, responses, exclusions, defaultResponse, responseId, (response) -> { IResponseCallback.invoke(callback, response); }); PromptDialog.show(ctl); }