IDEMPIERE-1773 Asking for input from within a process / integrated patch from Jan Thielemann, thanks!

This commit is contained in:
Carlos Ruiz 2014-05-16 10:46:26 -05:00
parent b3cd784008
commit 4d8dc152e3
13 changed files with 163 additions and 12 deletions

View File

@ -78,6 +78,8 @@ public interface IProcessUI {
*/
public void ask(String message, Callback<Boolean> callback);
public void askForInput(String message, Callback<String> callback);
/**
* add to list of file available for download after process end
* @param file

View File

@ -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

View File

@ -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

View File

@ -3147,4 +3147,11 @@ public final class APanel extends CPanel
public void download(File file) {
}
@Override
public void askForInput(String message, Callback<String> callback) {
String s = ADialog.askForInput(m_curWindowNo, this, message);
if(callback != null)
callback.onCallback(s);
}
} // APanel

View File

@ -677,4 +677,11 @@ public class ProcessDialog extends CFrame
}
@Override
public void askForInput(String message, Callback<String> callback) {
String s = ADialog.askForInput(m_WindowNo, this, message);
if(callback != null)
callback.onCallback(s);
}
} // ProcessDialog

View File

@ -401,4 +401,11 @@ public class VGenPanel extends CPanel implements ActionListener, ChangeListener,
// TODO Auto-generated method stub
}
@Override
public void askForInput(String message, Callback<String> callback) {
String s = ADialog.askForInput(m_WindowNo, this, message);
if(callback != null)
callback.onCallback(s);
}
}

View File

@ -460,4 +460,11 @@ public class VPaySelect extends PaySelect implements FormPanel, ActionListener,
// TODO Auto-generated method stub
}
@Override
public void askForInput(String message, Callback<String> callback) {
String s = ADialog.askForInput(m_WindowNo, null, message);
if(callback != null)
callback.onCallback(s);
}
} // VPaySelect

View File

@ -923,4 +923,11 @@ public class VInOutInvoiceGen extends CPanel
// TODO Auto-generated method stub
}
@Override
public void askForInput(String message, Callback<String> callback) {
String s = ADialog.askForInput(m_WindowNo, this, message);
if(callback != null)
callback.onCallback(s);
}
} // VInOutGen

View File

@ -733,4 +733,15 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI
}
}
}
@Override
public void askForInput(final String message, final Callback<String> callback) {
Executions.schedule(getDesktop(), new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
FDialog.askForInput(m_WindowNo, null, message, callback);
}
}, new Event("onAskForInput"));
}
}

View File

@ -233,4 +233,4 @@ public class ProcessModalDialog extends AbstractProcessDialog implements EventLi
super.onEvent(event);
}
}
} // ProcessDialog
} // ProcessModalDialog

View File

@ -471,4 +471,14 @@ public class WPaySelect extends PaySelect
// TODO Auto-generated method stub
}
@Override
public void askForInput(final String message, final Callback<String> callback) {
Executions.schedule(form.getDesktop(), new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
FDialog.askForInput(m_WindowNo, null, message, callback);
}
}, new Event("onAskForInput"));
}
} // VPaySelect

View File

@ -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<Event>
{
/**
* 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<Event>
private Button btnAbort;
private Button btnRetry;
private Button btnIgnore;
private Textbox txtInput = new Textbox();;
private Image img = new Image();
private int returnValue;
private Callback<Integer> 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<Event>
/** 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<Event>
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<Event>
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<Event>
return show(message, title, buttons, icon, callback, false);
}
public int show(String message, String title, int buttons, String icon, Callback<Integer> 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<Event>
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<Event>
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<Event>
return showDialog(message, title, buttons, icon, callback, false);
}
public static int showDialog(String message, String title, int buttons, String icon, Callback<Integer> 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<Event>
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());
}
}
}

View File

@ -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<String> callback)
{
Callback<String> msgCallback = null;
if (callback != null)
{
msgCallback = new Callback<String>() {
@Override
public void onCallback(String 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, msgCallback, (msgCallback == null));
}
/**************************************************************************
* Ask Question with question icon and (OK) (Cancel) buttons
*
* @param WindowNo Number of Window