/** * Returns list of response objects created from a string of vertical bar delimited captions. * * @param <T> The type of response object. * @param responses Response list. * @param exclusions Exclusion list (may be null). * @param dflt Default response (may be null). * @return List of response objects corresponding to response list. */ public static <T> List<DialogResponse<T>> toResponseList(List<T> responses, List<T> exclusions, T dflt) { List<DialogResponse<T>> list = new ArrayList<>(); boolean forceDefault = dflt == null && responses.size() == 1; for (T response : responses) { DialogResponse<T> rsp = new DialogResponse<>(response, response.toString(), exclusions != null && exclusions.contains(response), forceDefault || response.equals(dflt)); list.add(rsp); } return list; }
/** * Saves the last response under the named responseId. * * @param response The response to save. A null value will delete any saved response. */ public void saveLastResponse(DialogResponse<T> response) { if (saveResponseId != null && (response == null || !response.isExcluded())) { int index = response == null ? -1 : responses.indexOf(response); PropertyUtil.saveValue(SAVED_RESPONSE_PROP_NAME, saveResponseId, false, index < 0 ? null : Integer.toString(index)); } }
public DialogResponse(T response, String label, boolean excluded, boolean dflt, String flavor) { this.response = response; this.label = label; this.ok = isResponseType(label, LABEL_ID_OK); this.cancel = isResponseType(label, LABEL_ID_CANCEL); this.excluded = excluded; this.dflt = dflt; this.flavor = flavor != null ? flavor : ok ? "success" : cancel ? "danger" : dflt ? "primary" : "default"; }
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()); }); }
/** * Control 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 Responses for the dialog. * @param excludeResponses Only applies if saveResponseId is specified. This is a list of * responses that will not be saved. * @param defaultResponse Default response for the dialog. * @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. */ public DialogControl(String message, String title, String styles, List<T> responses, List<T> excludeResponses, T defaultResponse, String saveResponseId, IPromptCallback<T> callback) { this(message, title, styles, DialogResponse.toResponseList(responses, excludeResponses, defaultResponse), saveResponseId, callback); }
/** * Present a confirmation (OK/Cancel) dialog with the specified prompt and return the user * response. * * @param message Prompt to present to the user. * @param title Caption of prompt dialog. * @param responseId Optional response id if user response is to be cached. If null, the * response will not be cached. If specified, the response is cached and the user is * not prompted again. * @param callback Callback to receive dialog response. */ public static void confirm(String message, String title, String responseId, IConfirmCallback callback) { prompt(message, title, STYLES_QUESTION, LABEL_IDS_OK_CANCEL, LABEL_ID_CANCEL, null, responseId, (response) -> { IResponseCallback.invoke(callback, response != null && response.isOk()); }); }
String msg = StrUtil.formatMessage(TEXT_TOO_MANY_MATCHES, matches.size()); DialogUtil.prompt(msg, TITLE_TOO_MANY_MATCHES, REFINE_BUTTONS, (response) -> { if (response.hasResponse(BTN_REFINE_LABEL)) { matches.clear();
/** * Returns the last saved response for this dialog. * * @return The response, or null if none found. */ public DialogResponse<T> getLastResponse() { String saved = saveResponseId == null ? null : PropertyUtil.getValue(SAVED_RESPONSE_PROP_NAME, saveResponseId); int i = NumberUtils.toInt(saved, -1); DialogResponse<T> response = i < 0 || i >= responses.size() ? null : responses.get(i); return response == null || response.isExcluded() ? null : response; }
/** * Returns list of response objects created from a string of vertical bar delimited captions. * * @param <T> The type of response object. * @param responses Response list. * @param exclusions Exclusion list (may be null). * @param dflt Default response (may be null). * @return List of response objects corresponding to response list. */ public static <T> List<DialogResponse<T>> toResponseList(T[] responses, T[] exclusions, T dflt) { List<DialogResponse<T>> list = new ArrayList<>(); boolean forceDefault = dflt == null && responses.length == 1; for (T response : responses) { DialogResponse<T> rsp = new DialogResponse<>(response, response.toString(), exclusions != null && ArrayUtils.contains(exclusions, response), forceDefault || response.equals(dflt)); list.add(rsp); } return list; }