From a0b5e52dafc7492371f9d85648872f80d0b79a71 Mon Sep 17 00:00:00 2001 From: Murilo Habermann Torquato Date: Wed, 15 May 2019 19:22:30 -0300 Subject: [PATCH] IDEMPIERE-3969 - askforinput new editors, allowed on callouts and new methods for display pdfList from process and infowindow from process --- .../src/org/adempiere/util/ICalloutUI.java | 34 ++++++++++ .../src/org/adempiere/util/IProcessUI.java | 50 ++++++++++++++ .../src/org/compiere/model/GridTab.java | 12 ++++ .../adempiere/webui/adwindow/ADTabpanel.java | 3 + .../webui/apps/AbstractProcessDialog.java | 65 ++++++++++++++++++- .../adempiere/webui/apps/CalloutDialog.java | 49 ++++++++++++++ .../adempiere/webui/component/Messagebox.java | 29 +++++++-- .../adempiere/webui/process/DunningPrint.java | 31 +-------- .../adempiere/webui/process/InvoicePrint.java | 38 +---------- .../org/adempiere/webui/window/FDialog.java | 63 +++++++++++++++++- 10 files changed, 300 insertions(+), 74 deletions(-) create mode 100644 org.adempiere.base/src/org/adempiere/util/ICalloutUI.java create mode 100644 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/CalloutDialog.java diff --git a/org.adempiere.base/src/org/adempiere/util/ICalloutUI.java b/org.adempiere.base/src/org/adempiere/util/ICalloutUI.java new file mode 100644 index 0000000000..6d4c06d1bf --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/util/ICalloutUI.java @@ -0,0 +1,34 @@ +/****************************************************************************** + * Copyright (C) 2019 Murilo H. Torquato * + * Copyright (C) 2019 devCoffee * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.util; + +import org.compiere.model.MLookup; + + + +/** + * Interface for callout Ask For Input + * + * @author Murilo H. Torquato (devCoffee, http://devcoffee.com.br) + * + */ +public interface ICalloutUI { + + default public void askForInput(String message, MLookup lookup, int displayType, Callback callback){ + throw new RuntimeException("Not Implemented"); + } + + public void setDesktop(Object desktop); + +} diff --git a/org.adempiere.base/src/org/adempiere/util/IProcessUI.java b/org.adempiere.base/src/org/adempiere/util/IProcessUI.java index fea1472316..21d7ff12d7 100644 --- a/org.adempiere.base/src/org/adempiere/util/IProcessUI.java +++ b/org.adempiere.base/src/org/adempiere/util/IProcessUI.java @@ -14,7 +14,9 @@ package org.adempiere.util; import java.io.File; +import java.util.List; +import org.compiere.model.MLookup; import org.compiere.process.ProcessInfo; /** @@ -80,9 +82,57 @@ public interface IProcessUI { public void askForInput(String message, Callback callback); + /** + * Prompt user for input with a configurable DisplayType (String, Number, TableDir or Search) + * + * Usage is the same from ask and askForInput methods with some additional parameters + * + * muriloht - devCoffee #3390 + * + * @param message + * @param lookup + * @param displayType + * @param callback + */ + default public void askForInput(String message, MLookup lookup, int displayType, Callback callback){ + throw new RuntimeException(); + } + /** * add to list of file available for download after process end * @param file */ public void download(File file); + + /** + * show reports from a given file list + * + * matheus.marcelino - devCoffee #5561 + * + * @param pdfList + */ + default public void showReports(List pdfList) + { + throw new RuntimeException(); +} + + /** + * show an info window from inside a process with user defined parameters + * + * gustavo.francisco - devCoffee #7094 + * + * @param WindowNo + * @param tableName + * @param keyColumn + * @param queryValue + * @param multipleSelection + * @param whereClause + * @param AD_InfoWindow_ID + * @param lookup + */ + default public void showInfoWindow(int WindowNo, String tableName, String keyColumn, String queryValue, + boolean multipleSelection, String whereClause, Integer AD_InfoWindow_ID, boolean lookup) + { + throw new RuntimeException(); + } } diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index ca57300f76..da3a1381ed 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -43,6 +43,7 @@ import org.adempiere.base.Core; import org.adempiere.base.IColumnCallout; import org.adempiere.model.MTabCustomization; import org.adempiere.util.ContextRunnable; +import org.adempiere.util.ICalloutUI; import org.compiere.Adempiere; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; @@ -149,6 +150,9 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable selection = new ArrayList(); } // GridTab + /** ICalloutUI*/ + private ICalloutUI calloutUI; + /** Value Object */ private GridTabVO m_vo; @@ -3378,4 +3382,12 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable { return m_vo; } + + public ICalloutUI getCalloutUI() { + return calloutUI; + } + + public void setCalloutUI(ICalloutUI calloutUI) { + this.calloutUI = calloutUI; + } } // GridTab diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java index 07bd5f0ca4..2502ff421c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java @@ -34,6 +34,7 @@ import org.adempiere.webui.AdempiereIdGenerator; import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.ClientInfo; import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.apps.CalloutDialog; import org.adempiere.webui.component.Borderlayout; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; @@ -335,6 +336,8 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer this.windowNo = windowNo; this.gridWindow = gridWindow; this.gridTab = gridTab; + // callout dialog ask for input - devCoffee #3390 + gridTab.setCalloutUI(new CalloutDialog(Executions.getCurrent().getDesktop(), windowNo)); this.windowPanel = winPanel; gridTab.addDataStatusListener(this); this.dataBinder = new GridTabDataBinder(gridTab); 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 4201d832aa..8425ca1a41 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 @@ -15,6 +15,7 @@ package org.adempiere.webui.apps; import java.io.File; +import java.io.FileInputStream; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -48,10 +49,13 @@ import org.adempiere.webui.editor.WEditor; import org.adempiere.webui.editor.WTableDirEditor; import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.factory.ButtonFactory; +import org.adempiere.webui.info.InfoWindow; import org.adempiere.webui.process.WProcessInfo; +import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.MultiFileDownloadDialog; +import org.adempiere.webui.window.SimplePDFViewer; import org.compiere.Adempiere; import org.compiere.model.Lookup; import org.compiere.model.MAttachment; @@ -1275,4 +1279,63 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI }, new Event("onAskForInput")); } -} \ No newline at end of file + @Override + public void askForInput(final String message, MLookup lookup, int editorType, final Callback callback) { + FDialog.askForInput(message, lookup, editorType, callback, getDesktop(), m_WindowNo); + } + + @Override + public void showReports(List pdfList) { + + if (pdfList == null || pdfList.isEmpty()) + return; + + AEnv.executeAsyncDesktopTask(new Runnable() { + @Override + public void run() { + if (pdfList.size() > 1) { + try { + File outFile = File.createTempFile(m_Name, ".pdf"); + AEnv.mergePdf(pdfList, outFile); + Window win = new SimplePDFViewer(m_Name, new FileInputStream(outFile)); + win.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); + SessionManager.getAppDesktop().showWindow(win, "center"); + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } else if (pdfList.size() > 0) { + try { + Window win = new SimplePDFViewer(m_Name, new FileInputStream(pdfList.get(0))); + win.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); + SessionManager.getAppDesktop().showWindow(win, "center"); + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } + } + }); + } + + @Override + public void showInfoWindow(int WindowNo, String tableName, String keyColumn, String queryValue, + boolean multipleSelection, String whereClause, Integer AD_InfoWindow_ID, boolean lookup) { + + if (AD_InfoWindow_ID <= 0) + return; + + AEnv.executeAsyncDesktopTask(new Runnable() { + @Override + public void run() { + try { + Window win = new InfoWindow(WindowNo, tableName, keyColumn, queryValue, multipleSelection, + whereClause, AD_InfoWindow_ID, lookup); + + SessionManager.getAppDesktop().showWindow(win, "center"); + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + + } + }); + } +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/CalloutDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/CalloutDialog.java new file mode 100644 index 0000000000..ae618a3de7 --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/CalloutDialog.java @@ -0,0 +1,49 @@ +/****************************************************************************** + * Copyright (C) 2019 Murilo H. Torquato * + * Copyright (C) 2019 devCoffee * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ + +package org.adempiere.webui.apps; + +import org.adempiere.util.Callback; +import org.adempiere.util.ICalloutUI; +import org.adempiere.webui.window.FDialog; +import org.compiere.model.MLookup; +import org.zkoss.zk.ui.Desktop; + +/** + * Callout Dialog used for Ask For Input + * + * @author Murilo H. Torquato (devCoffee, http://devcoffee.com.br) + * + **/ +public class CalloutDialog implements ICalloutUI { + + private Desktop desktop; + private int m_windowNo; + + public CalloutDialog(Desktop desktop, int windowNo) { + this.desktop = desktop; + this.m_windowNo = windowNo; + } + + @Override + public void askForInput(final String message, MLookup lookup, int editorType, final Callback callback) { + FDialog.askForInput(message, lookup, editorType, callback, desktop, m_windowNo); + } + + @Override + public void setDesktop(Object desktop) { + this.desktop = (Desktop) desktop; + } + +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java index 8addd94c68..01b947c0d9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java @@ -23,6 +23,8 @@ import org.adempiere.util.Callback; import org.adempiere.webui.AdempiereIdGenerator; import org.adempiere.webui.ClientInfo; import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.editor.WStringEditor; import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.theme.ThemeManager; @@ -68,7 +70,7 @@ public class Messagebox extends Window implements EventListener private Button btnAbort; private Button btnRetry; private Button btnIgnore; - private Textbox txtInput = new Textbox();; + private WEditor inputField; private Image img = new Image(); @@ -177,7 +179,7 @@ public class Messagebox extends Window implements EventListener Panel pnlInput= new Panel(); pnlInput.setStyle(MESSAGE_PANEL_STYLE); - pnlInput.appendChild(txtInput); + pnlInput.appendChild(inputField.getComponent()); Vbox pnlText = new Vbox(); pnlText.appendChild(pnlMessage); @@ -254,10 +256,19 @@ public class Messagebox extends Window implements EventListener } public int show(String message, String title, int buttons, String icon, Callback callback, boolean modal) + { + return show(message, title, buttons, icon, null, callback, modal); + } + + public int show(String message, String title, int buttons, String icon, WEditor editor, Callback callback, boolean modal) { this.msg = message; this.imgSrc = icon; this.callback = callback; + if (editor == null) + inputField = new WStringEditor(); + else + inputField = editor; init(); @@ -268,7 +279,7 @@ public class Messagebox extends Window implements EventListener btnRetry.setVisible(false); btnAbort.setVisible(false); btnIgnore.setVisible(false); - txtInput.setVisible(false); + inputField.setVisible(false); if ((buttons & OK) != 0) btnOk.setVisible(true); @@ -292,7 +303,7 @@ public class Messagebox extends Window implements EventListener btnIgnore.setVisible(true); if ((buttons & INPUT) != 0) { - txtInput.setVisible(true); + inputField.setVisible(true); isInput = true; } @@ -334,9 +345,13 @@ public class Messagebox extends Window implements EventListener public static int showDialog(String message, String title, int buttons, String icon, Callback callback, boolean modal) { - Messagebox msg = new Messagebox(); + return showDialog(message, title, buttons, icon, null, callback, modal); + } - return msg.show(message, title, buttons, icon, callback, modal); + public static int showDialog(String message, String title, int buttons, String icon, WEditor editor, Callback callback, boolean modal) + { + Messagebox msg = new Messagebox(); + return msg.show(message, title, buttons, icon, editor, callback, modal); } public void onEvent(Event event) throws Exception @@ -389,7 +404,7 @@ public class Messagebox extends Window implements EventListener { callback.onCallback(returnValue); } else if (callback != null && isInput) { - callback.onCallback(txtInput.getText()); + callback.onCallback(inputField.getValue()); } } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/DunningPrint.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/DunningPrint.java index a56528f1ba..5a2b190368 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/DunningPrint.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/DunningPrint.java @@ -258,38 +258,13 @@ public class DunningPrint extends SvrProcess return msgreturn.toString(); } - AEnv.executeAsyncDesktopTask(new Runnable() { - @Override - public void run() { - showReports(pdfList); + if (processUI != null) + { + processUI.showReports(pdfList); } - }); StringBuilder msgreturn = new StringBuilder("@Printed@=").append(count); return msgreturn.toString(); } // doIt - private void showReports(List pdfList) { - if (pdfList.size() > 1) { - try { - File outFile = File.createTempFile("DunningPrint", ".pdf"); - AEnv.mergePdf(pdfList, outFile); - Window win = new SimplePDFViewer(this.getName(), new FileInputStream(outFile)); - win.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); - SessionManager.getAppDesktop().showWindow(win, "center"); - } catch (Exception e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } - } else if (pdfList.size() > 0) { - try { - Window win = new SimplePDFViewer(this.getName(), new FileInputStream(pdfList.get(0))); - win.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); - SessionManager.getAppDesktop().showWindow(win, "center"); - } catch (Exception e) - { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } - } - } - } // DunningPrint diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/InvoicePrint.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/InvoicePrint.java index 1b3fde0133..405c3f46a9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/InvoicePrint.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/InvoicePrint.java @@ -17,7 +17,6 @@ package org.adempiere.webui.process; import java.io.File; -import java.io.FileInputStream; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; @@ -25,10 +24,6 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Level; -import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.component.Window; -import org.adempiere.webui.session.SessionManager; -import org.adempiere.webui.window.SimplePDFViewer; import org.compiere.model.MClient; import org.compiere.model.MInvoice; import org.compiere.model.MMailText; @@ -325,12 +320,10 @@ public class InvoicePrint extends SvrProcess DB.close(rs, pstmt); } - AEnv.executeAsyncDesktopTask(new Runnable() { - @Override - public void run() { - showReports(pdfList); + if (processUI != null) + { + processUI.showReports(pdfList); } - }); // if (p_EMailPDF) @@ -441,29 +434,4 @@ public class InvoicePrint extends SvrProcess sql.append(" ORDER BY i.C_Invoice_ID, pf.AD_Org_ID DESC"); // more than 1 PF record } - private void showReports(List pdfList) { - if (pdfList.size() > 1) { - try { - File outFile = File.createTempFile("InvoicePrint", ".pdf"); - AEnv.mergePdf(pdfList, outFile); - - Window win = new SimplePDFViewer(this.getName(), new FileInputStream(outFile)); - win.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); - SessionManager.getAppDesktop().showWindow(win, "center"); - } catch (Exception e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } - } else if (pdfList.size() > 0) { - try { - Window win = new SimplePDFViewer(this.getName(), new FileInputStream(pdfList.get(0))); - win.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); - SessionManager.getAppDesktop().showWindow(win, "center"); - } catch (Exception e) - { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } - } - - } - } // InvoicePrint diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FDialog.java index 54ae512ed2..a4ffb4a22c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FDialog.java @@ -20,16 +20,27 @@ package org.adempiere.webui.window; import java.util.Properties; import java.util.logging.Level; +import org.adempiere.util.Callback; +import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.component.Messagebox; +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.editor.WNumberEditor; +import org.adempiere.webui.editor.WSearchEditor; +import org.adempiere.webui.editor.WStringEditor; +import org.adempiere.webui.editor.WTableDirEditor; +import org.compiere.model.MLookup; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; +import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Trace; import org.zkoss.zk.ui.Component; -import org.adempiere.util.Callback; -import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.component.Messagebox; +import org.zkoss.zk.ui.Desktop; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; /** * @@ -346,6 +357,52 @@ public class FDialog return ask(AEnv.getDialogHeader(Env.getCtx(), windowNo), windowNo, comp, adMessage, callback); } + public static void askForInput(final String message, MLookup lookup, int editorType, final Callback callback, Desktop desktop, int windowNo) { + @SuppressWarnings("unused") + final WEditor weditor; + + switch (editorType) { + case DisplayType.String: + weditor = new WStringEditor(); + break; + case DisplayType.Number: + weditor = new WNumberEditor(); + break; + case DisplayType.TableDir: + weditor = new WTableDirEditor(lookup, "", "", true, false, true); + break; + case DisplayType.Search: + weditor = new WSearchEditor(lookup, "", "", true, false, true); + break; + default: + weditor = null; + break; + } + Executions.schedule(desktop, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + FDialog.askForInput(windowNo, weditor, message, callback); + } + }, new Event("onAskForInput")); + } + + public static void askForInput(int windowNo, WEditor weditor, String adMessage, final Callback callback) + { + Callback msgCallback = null; + if (callback != null) + { + msgCallback = new Callback() { + @Override + public void onCallback(Object result) { + callback.onCallback(result); + } + }; + } + String s = Msg.getMsg(Env.getCtx(), adMessage).replace("\n", "
"); + Messagebox.showDialog(s, AEnv.getDialogHeader(Env.getCtx(), windowNo), + Messagebox.OK | Messagebox.INPUT, Messagebox.QUESTION, weditor, msgCallback, (msgCallback == null)); + } + public static void askForInput(int windowNo, Component comp, String adMessage, final Callback callback) { Callback msgCallback = null;