From 4d8dc152e3532254241a92e060cda4f4721ab42e Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 16 May 2014 10:46:26 -0500 Subject: [PATCH] IDEMPIERE-1773 Asking for input from within a process / integrated patch from Jan Thielemann, thanks! --- .../src/org/adempiere/util/IProcessUI.java | 2 + .../src/org/compiere/apps/ADialog.java | 34 ++++++++++++++++ .../src/org/compiere/apps/ADialogDialog.java | 23 +++++++++-- .../src/org/compiere/apps/APanel.java | 7 ++++ .../src/org/compiere/apps/ProcessDialog.java | 7 ++++ .../src/org/compiere/apps/form/VGenPanel.java | 7 ++++ .../org/compiere/apps/form/VPaySelect.java | 7 ++++ .../org/eevolution/form/VInOutInvoiceGen.java | 7 ++++ .../webui/apps/AbstractProcessDialog.java | 11 ++++++ .../webui/apps/ProcessModalDialog.java | 2 +- .../adempiere/webui/apps/form/WPaySelect.java | 10 +++++ .../adempiere/webui/component/Messagebox.java | 39 +++++++++++++++---- .../org/adempiere/webui/window/FDialog.java | 19 ++++++++- 13 files changed, 163 insertions(+), 12 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/util/IProcessUI.java b/org.adempiere.base/src/org/adempiere/util/IProcessUI.java index 7d8e64cec4..fea1472316 100644 --- a/org.adempiere.base/src/org/adempiere/util/IProcessUI.java +++ b/org.adempiere.base/src/org/adempiere/util/IProcessUI.java @@ -78,6 +78,8 @@ public interface IProcessUI { */ public void ask(String message, Callback callback); + public void askForInput(String message, Callback callback); + /** * add to list of file available for download after process end * @param file diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/ADialog.java b/org.adempiere.ui.swing/src/org/compiere/apps/ADialog.java index 0922c396d5..fc5a7356a9 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/ADialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/ADialog.java @@ -323,6 +323,40 @@ public final class ADialog return ask (WindowNo, c, AD_Message, null); } // ask + public static String askForInput(int WindowNo, Container c, String AD_Message) { + if (log.isLoggable(Level.INFO)) log.info(AD_Message); + Properties ctx = Env.getCtx(); + StringBuilder out = new StringBuilder(); + if (AD_Message != null && !AD_Message.equals("")) + out.append(Msg.getMsg(ctx, AD_Message)); + + // + Window parent = Env.getParent(c); + if (parent == null) + parent = AEnv.getWindow(WindowNo); + + String retValue = null; + if (parent != null) + { + if (parent instanceof JFrame) + { + ADialogDialog d = new ADialogDialog ((JFrame)parent, + Env.getHeader(ctx, WindowNo), + out.toString(), + ADialogDialog.INPUT_MESSAGE); + retValue = d.getReturnMsg(); + } + else + { + ADialogDialog d = new ADialogDialog ((JDialog)parent, + Env.getHeader(ctx, WindowNo), + out.toString(), + ADialogDialog.INPUT_MESSAGE); + retValue = d.getReturnMsg(); + } + } + return retValue; + } /************************************************************************** * Display parsed development info Message string diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/ADialogDialog.java b/org.adempiere.ui.swing/src/org/compiere/apps/ADialogDialog.java index 270d91a575..45e4f64844 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/ADialogDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/ADialogDialog.java @@ -41,6 +41,7 @@ import org.compiere.swing.CDialog; import org.compiere.swing.CLabel; import org.compiere.swing.CMenuItem; import org.compiere.swing.CPanel; +import org.compiere.swing.CTextField; import org.compiere.swing.CTextPane; import org.compiere.util.CLogger; import org.compiere.util.Env; @@ -60,6 +61,7 @@ public final class ADialogDialog extends CDialog implements ActionListener */ private static final long serialVersionUID = 5670261006862936363L; + public static final int INPUT_MESSAGE = 4; /** * Create Dialog Window for Frame * @@ -100,7 +102,7 @@ public final class ADialogDialog extends CDialog implements ActionListener try { setInfoMessage (message); - jbInit(); + jbInit(messageType); setInfoIcon (messageType); } catch(Exception ex) @@ -150,6 +152,7 @@ public final class ADialogDialog extends CDialog implements ActionListener private CLabel iconLabel = new CLabel(); private GridBagLayout westLayout = new GridBagLayout(); private CTextPane info = new CTextPane (); + private CTextField input = new CTextField(); private GridBagLayout infoLayout = new GridBagLayout(); private CPanel infoPanel = new CPanel(); @@ -157,7 +160,7 @@ public final class ADialogDialog extends CDialog implements ActionListener * Static Constructor * @throws Exception */ - private void jbInit() throws Exception + private void jbInit(int messageType) throws Exception { this.setJMenuBar(menuBar); // @@ -193,6 +196,9 @@ public final class ADialogDialog extends CDialog implements ActionListener this.getContentPane().add(infoPanel, BorderLayout.CENTER); infoPanel.add(info, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); + if(messageType == ADialogDialog.INPUT_MESSAGE) + infoPanel.add(input, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0 + ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); // menuBar.add(mFile); mFile.add(mPrintScreen); @@ -279,7 +285,10 @@ public final class ADialogDialog extends CDialog implements ActionListener case JOptionPane.WARNING_MESSAGE: iconLabel.setIcon(i_warn); break; - + case ADialogDialog.INPUT_MESSAGE: + confirmPanel.getCancelButton().setVisible(false); + iconLabel.setIcon(i_question); + break; case JOptionPane.PLAIN_MESSAGE: default: break; @@ -340,4 +349,12 @@ public final class ADialogDialog extends CDialog implements ActionListener PrintScreenPainter.printScreen(this); } // printScreen + /** + * Get entered message if dialog is a askForInput-Dialog + * @return + */ + public String getReturnMsg() { + return input.getText(); + } + } // ADialogDialog diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java index 959e755389..43d9727607 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java @@ -3147,4 +3147,11 @@ public final class APanel extends CPanel public void download(File file) { } + @Override + public void askForInput(String message, Callback callback) { + String s = ADialog.askForInput(m_curWindowNo, this, message); + if(callback != null) + callback.onCallback(s); + } + } // APanel diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/ProcessDialog.java b/org.adempiere.ui.swing/src/org/compiere/apps/ProcessDialog.java index 86798c21bd..dd4cbe151d 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/ProcessDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/ProcessDialog.java @@ -677,4 +677,11 @@ public class ProcessDialog extends CFrame } + @Override + public void askForInput(String message, Callback callback) { + String s = ADialog.askForInput(m_WindowNo, this, message); + if(callback != null) + callback.onCallback(s); + } + } // ProcessDialog diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VGenPanel.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VGenPanel.java index 2932f93a22..281a7789c4 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VGenPanel.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VGenPanel.java @@ -401,4 +401,11 @@ public class VGenPanel extends CPanel implements ActionListener, ChangeListener, // TODO Auto-generated method stub } + + @Override + public void askForInput(String message, Callback callback) { + String s = ADialog.askForInput(m_WindowNo, this, message); + if(callback != null) + callback.onCallback(s); + } } \ No newline at end of file diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VPaySelect.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VPaySelect.java index 80456e717a..c0e9f6a1d3 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VPaySelect.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VPaySelect.java @@ -460,4 +460,11 @@ public class VPaySelect extends PaySelect implements FormPanel, ActionListener, // TODO Auto-generated method stub } + + @Override + public void askForInput(String message, Callback callback) { + String s = ADialog.askForInput(m_WindowNo, null, message); + if(callback != null) + callback.onCallback(s); + } } // VPaySelect diff --git a/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java b/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java index 74e12370de..a652320835 100755 --- a/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java +++ b/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java @@ -923,4 +923,11 @@ public class VInOutInvoiceGen extends CPanel // TODO Auto-generated method stub } + + @Override + public void askForInput(String message, Callback callback) { + String s = ADialog.askForInput(m_WindowNo, this, message); + if(callback != null) + callback.onCallback(s); + } } // VInOutGen 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 f8336e023b..1553b03b8d 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 @@ -733,4 +733,15 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI } } } + + @Override + public void askForInput(final String message, final Callback callback) { + Executions.schedule(getDesktop(), new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + FDialog.askForInput(m_WindowNo, null, message, callback); + } + }, new Event("onAskForInput")); + } + } \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java index d2f3a7b0bc..a8e1fb0d69 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java @@ -233,4 +233,4 @@ public class ProcessModalDialog extends AbstractProcessDialog implements EventLi super.onEvent(event); } } -} // ProcessDialog +} // ProcessModalDialog 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 c35deb6da9..5fe683d99e 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 @@ -471,4 +471,14 @@ public class WPaySelect extends PaySelect // TODO Auto-generated method stub } + + @Override + public void askForInput(final String message, final Callback callback) { + Executions.schedule(form.getDesktop(), new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + FDialog.askForInput(m_WindowNo, null, message, callback); + } + }, new Event("onAskForInput")); + } } // VPaySelect 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 b81cdbfc93..5a98f40b43 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 @@ -35,6 +35,7 @@ import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Hbox; import org.zkoss.zul.Image; +import org.zkoss.zul.Vbox; /** * Messagebox : Replaces ZK's Messagebox @@ -46,9 +47,10 @@ import org.zkoss.zul.Image; public class Messagebox extends Window implements EventListener { /** - * generated serial version ID + * */ - private static final long serialVersionUID = -4957498533838144942L; + private static final long serialVersionUID = 8928526331932742124L; + private static final String MESSAGE_PANEL_STYLE = "text-align:left; word-break: break-all; overflow: auto; max-height: 350pt; min-width: 230pt; max-width: 450pt;"; private String msg = new String(""); private String imgSrc = new String(""); @@ -62,11 +64,14 @@ public class Messagebox extends Window implements EventListener private Button btnAbort; private Button btnRetry; private Button btnIgnore; + private Textbox txtInput = new Textbox();; private Image img = new Image(); private int returnValue; - private Callback callback; + @SuppressWarnings("rawtypes") + private Callback callback; + private boolean isInput = false; /** A OK button. */ public static final int OK = 0x0001; @@ -88,6 +93,9 @@ public class Messagebox extends Window implements EventListener /** A IGNORE button. */ public static final int IGNORE = 0x0400; + + /** A INPUT Textfield*/ + public static final int INPUT = 0x0800; /** A symbol consisting of a question mark in a circle. */ public static final String QUESTION = "~./zul/img/msgbox/question-btn.png"; @@ -155,6 +163,14 @@ public class Messagebox extends Window implements EventListener pnlMessage.setStyle(MESSAGE_PANEL_STYLE); pnlMessage.appendChild(lblMsg); + Panel pnlInput= new Panel(); + pnlInput.setStyle(MESSAGE_PANEL_STYLE); + pnlInput.appendChild(txtInput); + + Vbox pnlText = new Vbox(); + pnlText.appendChild(pnlMessage); + pnlText.appendChild(pnlInput); + Hbox pnlImage = new Hbox(); img.setSrc(imgSrc); @@ -168,7 +184,7 @@ public class Messagebox extends Window implements EventListener north.setAlign("center"); this.appendChild(north); north.appendChild(pnlImage); - north.appendChild(pnlMessage); + north.appendChild(pnlText); north.setSclass("dialog-content"); Hbox pnlButtons = new Hbox(); @@ -201,7 +217,7 @@ public class Messagebox extends Window implements EventListener return show(message, title, buttons, icon, callback, false); } - 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) { this.msg = message; this.imgSrc = icon; @@ -216,6 +232,7 @@ public class Messagebox extends Window implements EventListener btnRetry.setVisible(false); btnAbort.setVisible(false); btnIgnore.setVisible(false); + txtInput.setVisible(false); if ((buttons & OK) != 0) btnOk.setVisible(true); @@ -238,6 +255,11 @@ public class Messagebox extends Window implements EventListener if ((buttons & IGNORE) != 0) btnIgnore.setVisible(true); + if ((buttons & INPUT) != 0) { + txtInput.setVisible(true); + isInput = true; + } + this.setTitle(title); this.setPosition("center"); this.setClosable(true); @@ -274,7 +296,7 @@ public class Messagebox extends Window implements EventListener return showDialog(message, title, buttons, icon, callback, false); } - 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(); @@ -318,12 +340,15 @@ public class Messagebox extends Window implements EventListener this.detach(); } + @SuppressWarnings("unchecked") @Override public void onPageDetached(Page page) { super.onPageDetached(page); - if (callback != null) + if (callback != null && !isInput) { callback.onCallback(returnValue); + } else if (callback != null && isInput) { + callback.onCallback(txtInput.getText()); } } } 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 cf84a2cdd2..d58acdac2b 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 @@ -330,7 +330,24 @@ public class FDialog return ask(AEnv.getDialogHeader(Env.getCtx(), windowNo), windowNo, comp, adMessage, callback); } - /************************************************************************** + public static void askForInput(int windowNo, Component comp, String adMessage, final Callback callback) + { + Callback msgCallback = null; + if (callback != null) + { + msgCallback = new Callback() { + @Override + public void onCallback(String 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, msgCallback, (msgCallback == null)); + } + + /************************************************************************** * Ask Question with question icon and (OK) (Cancel) buttons * * @param WindowNo Number of Window