From 8264a9abfa121b853cc28447dba1c098c61ffe0e Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 9 Mar 2021 10:56:38 +0100 Subject: [PATCH] IDEMPIERE-4692 Mandatory range parameters : "To" style not updated after being filled manually (#616) * IDEMPIERE-4692 Mandatory range parameters : "To" style not updated after being filled manually * based on patch from Anozi Mada * Add javadoc explaining new columnname notation in IProcessParameterListener * Change BankTransferParameterListener to illustrate better usage of columnname - as example --- .../webui/apps/IProcessParameterListener.java | 2 +- .../webui/apps/ProcessParameterPanel.java | 40 ++++++++++++++----- .../BankTransferParameterListener.java | 6 +-- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/IProcessParameterListener.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/IProcessParameterListener.java index 106ef5e94d..6da7eabd59 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/IProcessParameterListener.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/IProcessParameterListener.java @@ -25,7 +25,7 @@ public interface IProcessParameterListener { /** * on value change of parameter field editor * @param parameterPanel - * @param columnName + * @param columnName - for range parameter the To columnname is suffixed with _2 * @param editor */ public void onChange(ProcessParameterPanel parameterPanel, String columnName, WEditor editor); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java index c30831fe21..693318e84b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.logging.Level; import org.adempiere.webui.Extensions; +import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; import org.adempiere.webui.component.EditorBox; @@ -134,8 +135,7 @@ public class ProcessParameterPanel extends Panel implements // private ArrayList m_wEditors = new ArrayList(); - private ArrayList m_wEditors2 = new ArrayList(); // for - // ranges + private ArrayList m_wEditors2 = new ArrayList(); // for ranges private ArrayList m_mFields = new ArrayList(); private ArrayList m_mFields2 = new ArrayList(); private ArrayList m_separators = new ArrayList(); @@ -361,6 +361,7 @@ public class ProcessParameterPanel extends Panel implements editor2.getComponent().addEventListener(Events.ON_FOCUS, this); // New Field value to be updated to editor mField2.addPropertyChangeListener(editor2); + editor2.addValueChangeListener(this); editor2.dynamicDisplay(); ZKUpdateUtil.setWidth((HtmlBasedComponent) editor2.getComponent(), "49%"); setEditorPlaceHolder(editor2, mField2.getPlaceholder2()); @@ -531,7 +532,10 @@ public class ProcessParameterPanel extends Panel implements if (editor.getValue() != null) { ValueChangeEvent changeEvent = new ValueChangeEvent(editor, editor.getColumnName(), null, editor.getValue()); valueChange(changeEvent); - // Note that the second editor2 in ranges has no event verification + } + if (editor2 != null && editor2.getValue() != null) { + ValueChangeEvent changeEvent = new ValueChangeEvent(editor2, editor2.getColumnName(), null, editor2.getValue()); + valueChange(changeEvent); } log.fine(para.toString()); @@ -726,15 +730,21 @@ public class ProcessParameterPanel extends Panel implements */ public void valueChange(ValueChangeEvent evt) { + String propName = evt.getPropertyName(); if (evt.getSource() instanceof WEditor) { - GridField changedField = ((WEditor) evt.getSource()).getGridField(); + WEditor editor = (WEditor) evt.getSource(); + if (m_wEditors2.contains(editor)) { + // is a _To editor for ranges + propName += "_2"; // same as web services + } + GridField changedField = editor.getGridField(); if (changedField != null) { processDependencies (changedField); // future processCallout (changedField); } Events.postEvent("onPostEditorValueChange", this, evt.getSource()); } - processNewValue(evt.getNewValue(), evt.getPropertyName()); + processNewValue(evt.getNewValue(), propName); } @Override @@ -769,9 +779,14 @@ public class ProcessParameterPanel extends Panel implements private void onPostEditorValueChange(WEditor editor) { if (m_processInfo.getAD_Process_ID() > 0) { String className = MProcess.get(Env.getCtx(), m_processInfo.getAD_Process_ID()).getClassname(); - List listeners = Extensions.getProcessParameterListeners(className, editor.getColumnName()); + String colName = editor.getColumnName(); + if (m_wEditors2.contains(editor)) { + // is a _To editor for ranges + colName += "_2"; // same as web services + } + List listeners = Extensions.getProcessParameterListeners(className, colName); for(IProcessParameterListener listener : listeners) { - listener.onChange(this, editor.getColumnName(), editor); + listener.onChange(this, colName, editor); } } } @@ -846,8 +861,7 @@ public class ProcessParameterPanel extends Panel implements m_wEditors2.get(i).setVisible(true); } } - boolean rw = mField.isEditablePara(true); // r/w - check if - // field is Editable + boolean rw = mField.isEditablePara(true); // r/w - check if field is Editable editor.setReadWrite(rw); editor.dynamicDisplay(); if (mField.getVO().isRange) { @@ -863,6 +877,14 @@ public class ProcessParameterPanel extends Panel implements } editor.setMandatory(mField.isMandatory(true)); editor.updateStyle(); + if (mField.getVO().isRange) { + m_wEditors2.get(i).setMandatory(mField.isMandatory(true)); + m_wEditors2.get(i).updateStyle(); + // Add mandatory style on label when Parameter To is still blank + if (editor.isMandatory() && editor.getLabel() != null && m_wEditors2.get(i).isNullOrEmpty()) { + LayoutUtils.addSclass("idempiere-mandatory-label", editor.getLabel()); + } + } } if (getParent() != null) { getParent().invalidate(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/BankTransferParameterListener.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/BankTransferParameterListener.java index da89dc2634..10bb31a5c0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/BankTransferParameterListener.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/BankTransferParameterListener.java @@ -37,12 +37,12 @@ public class BankTransferParameterListener implements IProcessParameterListener @Override public void onChange(ProcessParameterPanel parameterPanel, String columnName, WEditor editor) { if (editor.getValue() != null) { - if ("StatementDate".equals(editor.getColumnName())) { + if ("StatementDate".equals(columnName)) { // set Accounting Date when StatementDate changes WEditor dateAcctEditor = parameterPanel.getEditor("DateAcct"); dateAcctEditor.setValue(editor.getValue()); - } else if ( "From_C_BankAccount_ID".equals(editor.getColumnName()) - || "To_C_BankAccount_ID".equals(editor.getColumnName())) { + } else if ( "From_C_BankAccount_ID".equals(columnName) + || "To_C_BankAccount_ID".equals(columnName)) { WEditor toBankEditor = parameterPanel.getEditor("To_C_BankAccount_ID"); WEditor fromBankEditor = parameterPanel.getEditor("From_C_BankAccount_ID"); if ( toBankEditor.getValue() != null && fromBankEditor.getValue() != null