From 8a51fb8f4a9d4bc619387376db1470ea05e15527 Mon Sep 17 00:00:00 2001 From: Diego Ruiz <12065321+d-ruiz@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:46:09 +0200 Subject: [PATCH] IDEMPIERE-2205 - Ask for secret input from within a process (#1501) --- .../src/org/adempiere/util/IProcessUI.java | 8 ++++++++ .../webui/apps/AbstractProcessDialog.java | 10 ++++++++++ .../adempiere/webui/apps/form/WPaySelect.java | 10 ++++++++++ .../webui/editor/WPasswordEditor.java | 8 ++++++++ .../org/adempiere/webui/window/Dialog.java | 20 +++++++++++++++++++ 5 files changed, 56 insertions(+) diff --git a/org.adempiere.base/src/org/adempiere/util/IProcessUI.java b/org.adempiere.base/src/org/adempiere/util/IProcessUI.java index 21d7ff12d7..b013b0d251 100644 --- a/org.adempiere.base/src/org/adempiere/util/IProcessUI.java +++ b/org.adempiere.base/src/org/adempiere/util/IProcessUI.java @@ -81,6 +81,14 @@ public interface IProcessUI { public void ask(String message, Callback callback); public void askForInput(String message, Callback callback); + + /** + * Prompt for user secret input. + * + * @param title + * @param callback + */ + public void askForSecretInput(String message, Callback callback); /** * Prompt user for input with a configurable DisplayType (String, Number, TableDir or Search) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java index 6b5581c204..d4b3700ca1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java @@ -1266,6 +1266,16 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI } } } + + @Override + public void askForSecretInput(final String message, final Callback callback) { + Executions.schedule(getDesktop(), new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + Dialog.askForSecretInput(m_WindowNo, message, callback); + } + }, new Event("onAskForInput")); + } @Override public void askForInput(final String message, final Callback callback) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java index b62781b32d..6903d7664d 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaySelect.java @@ -674,4 +674,14 @@ public class WPaySelect extends PaySelect } }, new Event("onAskForInput")); } + + @Override + public void askForSecretInput(final String message, final Callback callback) { + Executions.schedule(form.getDesktop(), new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + Dialog.askForSecretInput(m_WindowNo, message, callback); + } + }, new Event("onAskForInput")); + } } // VPaySelect diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPasswordEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPasswordEditor.java index a4124ce631..d470a1d24c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPasswordEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPasswordEditor.java @@ -27,6 +27,14 @@ import org.compiere.model.GridField; */ public class WPasswordEditor extends WStringEditor { + + public WPasswordEditor() + { + super(); + super.setTypePassword(true); + setChangeEventWhenEditing(false); + } + /** * * @param gridField diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/Dialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/Dialog.java index 9c03e508f3..d831ce6a07 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/Dialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/Dialog.java @@ -34,6 +34,7 @@ import org.adempiere.webui.editor.WChosenboxListEditor; import org.adempiere.webui.editor.WChosenboxSearchEditor; import org.adempiere.webui.editor.WEditor; import org.adempiere.webui.editor.WNumberEditor; +import org.adempiere.webui.editor.WPasswordEditor; import org.adempiere.webui.editor.WSearchEditor; import org.adempiere.webui.editor.WStringEditor; import org.adempiere.webui.editor.WTableDirEditor; @@ -405,6 +406,25 @@ public final class Dialog { Messagebox.showDialog(message, dialogTitle, Messagebox.OK | Messagebox.INPUT, Messagebox.QUESTION, msgCallback, (msgCallback == null)); } + + public static void askForSecretInput(int windowNo, String adMessage, final Callback callback) { + Callback msgCallback = null; + if (callback != null) + { + msgCallback = new Callback() { + @Override + public void onCallback(String result) { + callback.onCallback(result); + } + }; + } + String dialogTitle = getDialogTitle("", windowNo); + String message = constructMessage(adMessage, null); + message = formatDialogMessage(message); + + Messagebox.showDialog(message, dialogTitle, + Messagebox.OK | Messagebox.INPUT, Messagebox.QUESTION, new WPasswordEditor(), msgCallback, (msgCallback == null)); + } /** * Confirmation dialog before deleting the records.