IDEMPIERE-3969 - askforinput new editors, allowed on callouts and new methods for display pdfList from process and infowindow from process

This commit is contained in:
Murilo Habermann Torquato 2019-05-15 19:22:30 -03:00
parent 9eabc31cde
commit a0b5e52daf
10 changed files with 300 additions and 74 deletions

View File

@ -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<Object> callback){
throw new RuntimeException("Not Implemented");
}
public void setDesktop(Object desktop);
}

View File

@ -14,7 +14,9 @@
package org.adempiere.util; package org.adempiere.util;
import java.io.File; import java.io.File;
import java.util.List;
import org.compiere.model.MLookup;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
/** /**
@ -80,9 +82,57 @@ public interface IProcessUI {
public void askForInput(String message, Callback<String> callback); public void askForInput(String message, Callback<String> 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<Object> callback){
throw new RuntimeException();
}
/** /**
* add to list of file available for download after process end * add to list of file available for download after process end
* @param file * @param file
*/ */
public void download(File file); public void download(File file);
/**
* show reports from a given file list
*
* matheus.marcelino - devCoffee #5561
*
* @param pdfList
*/
default public void showReports(List<File> 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();
}
} }

View File

@ -43,6 +43,7 @@ import org.adempiere.base.Core;
import org.adempiere.base.IColumnCallout; import org.adempiere.base.IColumnCallout;
import org.adempiere.model.MTabCustomization; import org.adempiere.model.MTabCustomization;
import org.adempiere.util.ContextRunnable; import org.adempiere.util.ContextRunnable;
import org.adempiere.util.ICalloutUI;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
@ -149,6 +150,9 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
selection = new ArrayList<Integer>(); selection = new ArrayList<Integer>();
} // GridTab } // GridTab
/** ICalloutUI*/
private ICalloutUI calloutUI;
/** Value Object */ /** Value Object */
private GridTabVO m_vo; private GridTabVO m_vo;
@ -3378,4 +3382,12 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
{ {
return m_vo; return m_vo;
} }
public ICalloutUI getCalloutUI() {
return calloutUI;
}
public void setCalloutUI(ICalloutUI calloutUI) {
this.calloutUI = calloutUI;
}
} // GridTab } // GridTab

View File

@ -34,6 +34,7 @@ import org.adempiere.webui.AdempiereIdGenerator;
import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.ClientInfo; import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.CalloutDialog;
import org.adempiere.webui.component.Borderlayout; import org.adempiere.webui.component.Borderlayout;
import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Column;
import org.adempiere.webui.component.Columns; import org.adempiere.webui.component.Columns;
@ -335,6 +336,8 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
this.windowNo = windowNo; this.windowNo = windowNo;
this.gridWindow = gridWindow; this.gridWindow = gridWindow;
this.gridTab = gridTab; this.gridTab = gridTab;
// callout dialog ask for input - devCoffee #3390
gridTab.setCalloutUI(new CalloutDialog(Executions.getCurrent().getDesktop(), windowNo));
this.windowPanel = winPanel; this.windowPanel = winPanel;
gridTab.addDataStatusListener(this); gridTab.addDataStatusListener(this);
this.dataBinder = new GridTabDataBinder(gridTab); this.dataBinder = new GridTabDataBinder(gridTab);

View File

@ -15,6 +15,7 @@
package org.adempiere.webui.apps; package org.adempiere.webui.apps;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -48,10 +49,13 @@ import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WTableDirEditor; import org.adempiere.webui.editor.WTableDirEditor;
import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.event.DialogEvents;
import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.factory.ButtonFactory;
import org.adempiere.webui.info.InfoWindow;
import org.adempiere.webui.process.WProcessInfo; import org.adempiere.webui.process.WProcessInfo;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.adempiere.webui.window.MultiFileDownloadDialog; import org.adempiere.webui.window.MultiFileDownloadDialog;
import org.adempiere.webui.window.SimplePDFViewer;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.model.Lookup; import org.compiere.model.Lookup;
import org.compiere.model.MAttachment; import org.compiere.model.MAttachment;
@ -1275,4 +1279,63 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI
}, new Event("onAskForInput")); }, new Event("onAskForInput"));
} }
@Override
public void askForInput(final String message, MLookup lookup, int editorType, final Callback<Object> callback) {
FDialog.askForInput(message, lookup, editorType, callback, getDesktop(), m_WindowNo);
}
@Override
public void showReports(List<File> 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);
}
}
});
}
} }

View File

@ -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<Object> callback) {
FDialog.askForInput(message, lookup, editorType, callback, desktop, m_windowNo);
}
@Override
public void setDesktop(Object desktop) {
this.desktop = (Desktop) desktop;
}
}

View File

@ -23,6 +23,8 @@ import org.adempiere.util.Callback;
import org.adempiere.webui.AdempiereIdGenerator; import org.adempiere.webui.AdempiereIdGenerator;
import org.adempiere.webui.ClientInfo; import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.apps.AEnv; 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.factory.ButtonFactory;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
@ -68,7 +70,7 @@ public class Messagebox extends Window implements EventListener<Event>
private Button btnAbort; private Button btnAbort;
private Button btnRetry; private Button btnRetry;
private Button btnIgnore; private Button btnIgnore;
private Textbox txtInput = new Textbox();; private WEditor inputField;
private Image img = new Image(); private Image img = new Image();
@ -177,7 +179,7 @@ public class Messagebox extends Window implements EventListener<Event>
Panel pnlInput= new Panel(); Panel pnlInput= new Panel();
pnlInput.setStyle(MESSAGE_PANEL_STYLE); pnlInput.setStyle(MESSAGE_PANEL_STYLE);
pnlInput.appendChild(txtInput); pnlInput.appendChild(inputField.getComponent());
Vbox pnlText = new Vbox(); Vbox pnlText = new Vbox();
pnlText.appendChild(pnlMessage); pnlText.appendChild(pnlMessage);
@ -254,10 +256,19 @@ public class Messagebox extends Window implements EventListener<Event>
} }
public int show(String message, String title, int buttons, String icon, Callback<?> callback, boolean modal) 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.msg = message;
this.imgSrc = icon; this.imgSrc = icon;
this.callback = callback; this.callback = callback;
if (editor == null)
inputField = new WStringEditor();
else
inputField = editor;
init(); init();
@ -268,7 +279,7 @@ public class Messagebox extends Window implements EventListener<Event>
btnRetry.setVisible(false); btnRetry.setVisible(false);
btnAbort.setVisible(false); btnAbort.setVisible(false);
btnIgnore.setVisible(false); btnIgnore.setVisible(false);
txtInput.setVisible(false); inputField.setVisible(false);
if ((buttons & OK) != 0) if ((buttons & OK) != 0)
btnOk.setVisible(true); btnOk.setVisible(true);
@ -292,7 +303,7 @@ public class Messagebox extends Window implements EventListener<Event>
btnIgnore.setVisible(true); btnIgnore.setVisible(true);
if ((buttons & INPUT) != 0) { if ((buttons & INPUT) != 0) {
txtInput.setVisible(true); inputField.setVisible(true);
isInput = true; isInput = true;
} }
@ -334,9 +345,13 @@ public class Messagebox extends Window implements EventListener<Event>
public static int showDialog(String message, String title, int buttons, String icon, Callback<?> callback, boolean modal) 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 public void onEvent(Event event) throws Exception
@ -389,7 +404,7 @@ public class Messagebox extends Window implements EventListener<Event>
{ {
callback.onCallback(returnValue); callback.onCallback(returnValue);
} else if (callback != null && isInput) { } else if (callback != null && isInput) {
callback.onCallback(txtInput.getText()); callback.onCallback(inputField.getValue());
} }
} }
} }

View File

@ -258,38 +258,13 @@ public class DunningPrint extends SvrProcess
return msgreturn.toString(); return msgreturn.toString();
} }
AEnv.executeAsyncDesktopTask(new Runnable() { if (processUI != null)
@Override {
public void run() { processUI.showReports(pdfList);
showReports(pdfList);
} }
});
StringBuilder msgreturn = new StringBuilder("@Printed@=").append(count); StringBuilder msgreturn = new StringBuilder("@Printed@=").append(count);
return msgreturn.toString(); return msgreturn.toString();
} // doIt } // doIt
private void showReports(List<File> 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 } // DunningPrint

View File

@ -17,7 +17,6 @@
package org.adempiere.webui.process; package org.adempiere.webui.process;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -25,10 +24,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; 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.MClient;
import org.compiere.model.MInvoice; import org.compiere.model.MInvoice;
import org.compiere.model.MMailText; import org.compiere.model.MMailText;
@ -325,12 +320,10 @@ public class InvoicePrint extends SvrProcess
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
AEnv.executeAsyncDesktopTask(new Runnable() { if (processUI != null)
@Override {
public void run() { processUI.showReports(pdfList);
showReports(pdfList);
} }
});
// //
if (p_EMailPDF) 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 sql.append(" ORDER BY i.C_Invoice_ID, pf.AD_Org_ID DESC"); // more than 1 PF record
} }
private void showReports(List<File> 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 } // InvoicePrint

View File

@ -20,16 +20,27 @@ package org.adempiere.webui.window;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; 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.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Trace; import org.compiere.util.Trace;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.adempiere.util.Callback; import org.zkoss.zk.ui.Desktop;
import org.adempiere.webui.apps.AEnv; import org.zkoss.zk.ui.Executions;
import org.adempiere.webui.component.Messagebox; 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); return ask(AEnv.getDialogHeader(Env.getCtx(), windowNo), windowNo, comp, adMessage, callback);
} }
public static void askForInput(final String message, MLookup lookup, int editorType, final Callback<Object> 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<Event>() {
@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<Object> callback)
{
Callback<Object> msgCallback = null;
if (callback != null)
{
msgCallback = new Callback<Object>() {
@Override
public void onCallback(Object result) {
callback.onCallback(result);
}
};
}
String s = Msg.getMsg(Env.getCtx(), adMessage).replace("\n", "<br>");
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<String> callback) public static void askForInput(int windowNo, Component comp, String adMessage, final Callback<String> callback)
{ {
Callback<String> msgCallback = null; Callback<String> msgCallback = null;