[ 2171273 ] Parameter (in Report&Process) with dynamic validation

[ 2175857 ] Parameter (in Report&Process) have no ZoomIn
Improve process dialog layout
Allow user to run the processs and report again
This commit is contained in:
Heng Sin Low 2008-12-01 02:49:47 +00:00
parent 7b30edbcb5
commit 38cb19d2a5
6 changed files with 206 additions and 67 deletions

View File

@ -94,6 +94,8 @@ import org.zkoss.zul.Tabpanels;
public class Desktop extends AbstractUIPart implements MenuListener, Serializable, IDesktop, EventListener
{
public static final String WINDOWNO_ATTRIBUTE = "desktop.windowno";
private static final long serialVersionUID = 9056511175189603883L;
private static final CLogger logger = CLogger.getCLogger(Desktop.class);
@ -625,10 +627,11 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
public ProcessDialog openProcessDialog(int processId, boolean soTrx) {
ProcessDialog pd = new ProcessDialog (processId, soTrx);
if (pd.isValid()) {
pd.setPage(page);
pd.setClosable(true);
pd.setWidth("500px");
pd.doHighlighted();
DesktopTabpanel tabPanel = new DesktopTabpanel();
pd.setParent(tabPanel);
String title = pd.getTitle();
pd.setTitle(null);
windowContainer.addWindow(tabPanel, title, true);
}
return pd;
}
@ -925,14 +928,26 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
*/
public boolean closeActiveWindow()
{
if ( windowContainer.closeActiveWindow() )
if (windowContainer.getSelectedTab() != null)
{
return true;
}
else
{
return false;
Tabpanel panel = (Tabpanel) windowContainer.getSelectedTab().getLinkedPanel();
Component component = panel.getFirstChild();
Object att = component.getAttribute(WINDOWNO_ATTRIBUTE);
if (att != null && (att instanceof Integer))
if ( windowContainer.closeActiveWindow() )
{
if (att != null && (att instanceof Integer))
{
unregisterWindow((Integer) att);
}
return true;
}
else
{
return false;
}
}
return false;
}
/**
@ -957,7 +972,7 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
{
Tabpanel panel = (Tabpanel) child;
Component component = panel.getFirstChild();
Object att = component.getAttribute("desktop.windowno");
Object att = component.getAttribute(WINDOWNO_ATTRIBUTE);
if (att != null && (att instanceof Integer))
{
if (windowNo == (Integer)att)
@ -966,6 +981,7 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
panel.getLinkedTab().onClose();
if (tab.getParent() == null)
{
unregisterWindow(windowNo);
return true;
}
else

View File

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.webui.Desktop;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.VerticalBox;
@ -40,7 +41,6 @@ import org.zkoss.zul.Html;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
@ -94,6 +94,7 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
log.info("Process=" + AD_Process_ID );
m_ctx = Env.getCtx();;
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
this.setAttribute(Desktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
m_AD_Process_ID = AD_Process_ID;
Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
try
@ -118,9 +119,9 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
centerPanel = new Panel();
vbox.appendChild(centerPanel);
div = new Div();
div.setAlign("right");
div.setAlign("center");
Hbox hbox = new Hbox();
String label = Msg.getMsg(Env.getCtx(), "Ok");
String label = Msg.getMsg(Env.getCtx(), "Start");
bOK = new Button(label.replaceAll("&", ""));
bOK.setImage("/images/Ok16.png");
bOK.setId("Ok");
@ -136,15 +137,14 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
hbox.appendChild(btn);
div.appendChild(hbox);
vbox.appendChild(div);
this.appendChild(vbox);
this.setBorder("normal");
this.appendChild(vbox);
}
private int m_WindowNo;
private Properties m_ctx;
private int m_AD_Process_ID;
private String m_Name = null;
@SuppressWarnings("unused")
private boolean m_IsReport = false;
private int[] m_ids = null;
private StringBuffer m_messageText = new StringBuffer();
@ -163,6 +163,8 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
private ProcessInfo m_pi = null;
private boolean m_isLocked = false;
private boolean isResult;
private String initialMessage;
/**
@ -180,10 +182,8 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
*/
public void dispose()
{
Env.clearWinContext(m_WindowNo);
SessionManager.getAppDesktop().unregisterWindow(m_WindowNo);
SessionManager.getAppDesktop().closeWindow(m_WindowNo);
valid = false;
this.detach();
}// dispose
/**
@ -242,14 +242,15 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
return false;
//
this.setTitle(m_Name);
message.setContent(m_messageText.toString());
initialMessage = m_messageText.toString();
message.setContent(initialMessage);
bOK.setLabel(Msg.getMsg(Env.getCtx(), "Start"));
// Move from APanel.actionButton
m_pi = new ProcessInfo(m_Name, m_AD_Process_ID);
m_pi.setAD_User_ID (Env.getAD_User_ID(Env.getCtx()));
m_pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
parameterPanel = new ProcessParameterPanel(m_WindowNo, m_pi);
parameterPanel = new ProcessParameterPanel(m_WindowNo, m_pi, "70%");
centerPanel.getChildren().clear();
if ( parameterPanel.init() ) {
centerPanel.appendChild(parameterPanel);
@ -303,10 +304,10 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
if (component instanceof Button) {
Button element = (Button)component;
if ("Ok".equalsIgnoreCase(element.getId())) {
if (element.getLabel().length() > 0)
if (!isResult)
this.startProcess();
else
this.dispose();
restart();
} else if ("Cancel".equalsIgnoreCase(element.getId())) {
this.dispose();
}
@ -377,24 +378,37 @@ public class ProcessDialog extends Window implements EventListener//, ASyncProce
m_messageText.append(pi.getLogInfo(true));
message.setContent(m_messageText.toString());
bOK.setLabel("");
bOK.setLabel(Msg.getMsg(Env.getCtx(), "Parameter"));
bOK.setImage("/images/Reset16.png");
isResult = true;
m_ids = pi.getIDs();
//no longer needed, hide to give more space to display log
centerPanel.detach();
centerPanel.setVisible(false);
invalidate();
Clients.response(new AuEcho(this, "onAfterProcess", null));
}
private void restart() {
m_messageText = new StringBuffer(initialMessage);
message.setContent(initialMessage);
centerPanel.setVisible(true);
isResult = false;
bOK.setLabel(Msg.getMsg(Env.getCtx(), "Start"));
bOK.setImage("/images/Ok16.png");
invalidate();
}
public void onAfterProcess()
{
//
afterProcessTask();
// Close automatically
if (m_IsReport && !m_pi.isError())
this.dispose();
// If the process is a silent one and no errors occured, close the dialog
if(m_ShowHelp != null && m_ShowHelp.equals("S"))

View File

@ -24,13 +24,17 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.logging.Level;
import org.adempiere.webui.component.Column;
import org.adempiere.webui.component.Columns;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.GridFactory;
import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WEditorPopupMenu;
import org.adempiere.webui.editor.WebEditorFactory;
import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.event.ValueChangeListener;
import org.adempiere.webui.window.FDialog;
@ -58,23 +62,50 @@ import org.zkoss.zul.Label;
public class ProcessParameterPanel extends Panel
implements ValueChangeListener, IProcessParameter
{
private String width;
/**
* Dynamic generated Parameter panel.
* @param WindowNo window
* @param pi process info
*/
public ProcessParameterPanel(int WindowNo, ProcessInfo pi)
{
this(WindowNo, pi, "100%");
} // ProcessParameterPanel
/**
* Dynamic generated Parameter panel.
* @param WindowNo window
* @param pi process info
*/
public ProcessParameterPanel(int WindowNo, ProcessInfo pi, String width)
{
//
m_WindowNo = WindowNo;
m_processInfo = pi;
this.width = width;
//
initComponent();
} // ProcessParameterPanel
private void initComponent() {
centerPanel = GridFactory.newGridLayout();
centerPanel.setInnerWidth(width);
this.appendChild(centerPanel);
//setup columns
Columns columns = new Columns();
centerPanel.appendChild(columns);
Column col = new Column();
col.setWidth("30%");
columns.appendChild(col);
col = new Column();
col.setWidth("65%");
columns.appendChild(col);
col = new Column();
col.setWidth("5%");
columns.appendChild(col);
}
private int m_WindowNo;
@ -87,6 +118,7 @@ implements ValueChangeListener, IProcessParameter
private ArrayList<WEditor> m_wEditors2 = new ArrayList<WEditor>(); // for ranges
private ArrayList<GridField> m_mFields = new ArrayList<GridField>();
private ArrayList<GridField> m_mFields2 = new ArrayList<GridField>();
private ArrayList<Label> m_separators = new ArrayList<Label>();
//
private Grid centerPanel = null;
@ -207,6 +239,7 @@ implements ValueChangeListener, IProcessParameter
if (hasFields)
{
centerPanel.appendChild(rows);
dynamicDisplay();
}
else
dispose();
@ -235,46 +268,66 @@ implements ValueChangeListener, IProcessParameter
Row row = new Row();
// The Editor
WEditor wEditor = WebEditorFactory.getEditor(mField, false);
wEditor.addValueChangeListener(this);
wEditor.dynamicDisplay();
WEditor editor = WebEditorFactory.getEditor(mField, false);
editor.addValueChangeListener(this);
editor.dynamicDisplay();
// MField => VEditor - New Field value to be updated to editor
mField.addPropertyChangeListener(wEditor);
mField.addPropertyChangeListener(editor);
// Set Default
Object defaultObject = mField.getDefault();
mField.setValue (defaultObject, true);
//streach component to fill grid cell
editor.fillHorizontal();
//setup editor context menu
WEditorPopupMenu popupMenu = editor.getPopupMenu();
if (popupMenu != null)
{
popupMenu.addMenuListener((ContextMenuListener)editor);
this.appendChild(popupMenu);
}
//
m_wEditors.add (wEditor); // add to Editors
m_wEditors.add (editor); // add to Editors
row.appendChild(wEditor.getLabel());
row.appendChild(editor.getLabel().rightAlign());
//
if (voF.isRange)
{
Hbox box = new Hbox();
box.appendChild(wEditor.getComponent());
box.appendChild(editor.getComponent());
//
GridFieldVO voF2 = GridFieldVO.createParameter(voF);
GridField mField2 = new GridField (voF2);
m_mFields2.add (mField2);
// The Editor
WEditor wEditor2 = WebEditorFactory.getEditor(mField2, false);
WEditor editor2 = WebEditorFactory.getEditor(mField2, false);
// New Field value to be updated to editor
mField2.addPropertyChangeListener(wEditor2);
wEditor2.dynamicDisplay();
mField2.addPropertyChangeListener(editor2);
editor2.dynamicDisplay();
editor2.fillHorizontal();
//setup editor context menu
popupMenu = editor2.getPopupMenu();
if (popupMenu != null)
{
popupMenu.addMenuListener((ContextMenuListener)editor2);
this.appendChild(popupMenu);
}
// Set Default
Object defaultObject2 = mField2.getDefault();
mField2.setValue (defaultObject2, true);
//
m_wEditors2.add (wEditor2);
box.appendChild(new Label(" - "));
box.appendChild(wEditor2.getComponent());
m_wEditors2.add (editor2);
Label separator = new Label(" - ");
m_separators.add(separator);
box.appendChild(separator);
box.appendChild(editor2.getComponent());
row.appendChild(box);
}
else
{
row.appendChild(wEditor.getComponent());
row.appendChild(editor.getComponent());
m_mFields2.add (null);
m_wEditors2.add (null);
m_separators.add(null);
}
rows.appendChild(row);
} // createField
@ -422,10 +475,58 @@ implements ValueChangeListener, IProcessParameter
public void valueChange(ValueChangeEvent evt)
{
String value = evt.getNewValue() == null ? "" : evt.getNewValue().toString();
Env.setContext(Env.getCtx(), m_WindowNo, evt.getPropertyName(), value);
processNewValue(evt.getNewValue(), evt.getPropertyName());
}
private void processNewValue(Object value, String name) {
if (value == null)
value = new String("");
if (value instanceof String)
Env.setContext(Env.getCtx(), m_WindowNo, name, (String) value);
else if (value instanceof Integer)
Env.setContext(Env.getCtx(), m_WindowNo, name, ((Integer) value)
.intValue());
else if (value instanceof Boolean)
Env.setContext(Env.getCtx(), m_WindowNo, name, ((Boolean) value)
.booleanValue());
else if (value instanceof Timestamp)
Env.setContext(Env.getCtx(), m_WindowNo, name, (Timestamp) value);
else
Env.setContext(Env.getCtx(), m_WindowNo, name, value.toString());
dynamicDisplay();
}
private void dynamicDisplay() {
for(int i = 0; i < m_wEditors.size(); i++) {
WEditor editor = m_wEditors.get(i);
GridField mField = editor.getGridField();
if (mField.isDisplayed(true)) {
if (!editor.isVisible()) {
editor.setVisible(true);
if (mField.getVO().isRange) {
m_separators.get(i).setVisible(true);
m_wEditors2.get(i).setVisible(true);
}
}
boolean rw = mField.isEditablePara(true); // r/w - check if field is Editable
editor.setReadWrite(rw);
editor.dynamicDisplay();
if (mField.getVO().isRange) {
m_wEditors2.get(i).setReadWrite(rw);
m_wEditors2.get(i).dynamicDisplay();
}
} else if (editor.isVisible()) {
editor.setVisible(false);
if (mField.getVO().isRange) {
m_separators.get(i).setVisible(false);
m_wEditors2.get(i).setVisible(false);
}
}
}
}
/**
* Restore window context.
* @author teo_sarca [ 1699826 ]

View File

@ -22,6 +22,9 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import org.adempiere.webui.component.Bandbox;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Datebox;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.event.ValueChangeListener;
@ -421,4 +424,27 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
public void dynamicDisplay()
{
}
/**
* Stretch editor component to fill container
*/
public void fillHorizontal() {
//streach component to fill grid cell
if (getComponent() instanceof HtmlBasedComponent) {
//can't stretch bandbox & datebox
if (!(getComponent() instanceof Bandbox) &&
!(getComponent() instanceof Datebox)) {
String width = "100%";
if (getComponent() instanceof Button) {
Button btn = (Button) getComponent();
String zclass = btn.getZclass();
if (!zclass.contains("form-button ")) {
btn.setZclass("form-button " + zclass);
}
} else {
((HtmlBasedComponent)getComponent()).setWidth(width);
}
}
}
}
}

View File

@ -27,11 +27,8 @@ import java.util.Map.Entry;
import java.util.logging.Level;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.component.Bandbox;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Column;
import org.adempiere.webui.component.Columns;
import org.adempiere.webui.component.Datebox;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.GridPanel;
import org.adempiere.webui.component.Label;
@ -62,7 +59,6 @@ import org.compiere.util.Evaluatee;
import org.zkoss.zk.au.out.AuFocus;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
@ -420,22 +416,7 @@ DataStatusListener, IADTabpanel
}
//streach component to fill grid cell
if (editor.getComponent() instanceof HtmlBasedComponent) {
//can't stretch bandbox & datebox
if (!(editor.getComponent() instanceof Bandbox) &&
!(editor.getComponent() instanceof Datebox)) {
String width = "100%";
if (editor.getComponent() instanceof Button) {
Button btn = (Button) editor.getComponent();
String zclass = btn.getZclass();
if (!zclass.contains("form-button ")) {
btn.setZclass("form-button " + zclass);
}
} else {
((HtmlBasedComponent)editor.getComponent()).setWidth(width);
}
}
}
editor.fillHorizontal();
//setup editor context menu
WEditorPopupMenu popupMenu = editor.getPopupMenu();

View File

@ -19,6 +19,7 @@ package org.adempiere.webui.window;
import java.util.Properties;
import org.adempiere.webui.Desktop;
import org.adempiere.webui.panel.ADWindowPanel;
import org.adempiere.webui.part.AbstractUIPart;
import org.adempiere.webui.session.SessionManager;
@ -76,7 +77,7 @@ public class ADWindow extends AbstractUIPart
{
windowPanelComponent = windowPanel.createPart(parent);
windowPanelComponent.setAttribute("ADWindow", this);
windowPanelComponent.setAttribute("desktop.windowno", windowNo);
windowPanelComponent.setAttribute(Desktop.WINDOWNO_ATTRIBUTE, windowNo);
if (windowPanel.initPanel(adWindowId, query))
{
_title = windowPanel.getTitle();