diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/Extensions.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/Extensions.java index be445df53f..cc46b127e1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/Extensions.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/Extensions.java @@ -23,6 +23,8 @@ package org.adempiere.webui; import java.util.List; import org.adempiere.base.Service; +import org.adempiere.base.ServiceQuery; +import org.adempiere.webui.apps.IProcessParameterListener; import org.adempiere.webui.factory.IFormFactory; import org.adempiere.webui.panel.ADForm; @@ -50,4 +52,18 @@ public class Extensions { } return null; } + + /** + * + * @param processClass + * @param columnName + * @return list of parameter listener + */ + public static List getProcessParameterListeners(String processClass, String columnName) { + ServiceQuery query = new ServiceQuery(); + query.put("ProcessClass", processClass); + if (columnName != null) + query.put("|ColumnName", columnName+"|"+columnName+",*|"+"*,"+columnName+",*|"+"*,"+columnName); + return Service.locator().list(IProcessParameterListener.class, null, query).getServices(); + } } 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 new file mode 100644 index 0000000000..5ebe52790d --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/IProcessParameterListener.java @@ -0,0 +1,40 @@ +/****************************************************************************** + * Product: iDempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2018 iDempiere.org. All Rights Reserved. * + * 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.webui.editor.WEditor; + +/** + * Listener interface for process parameter panel + * @author hengsin + * + */ +public interface IProcessParameterListener { + /** + * on value change of parameter field editor + * @param parameterPanel + * @param columnName + * @param editor + */ + public void onChange(ProcessParameterPanel parameterPanel, String columnName, WEditor editor); + + /** + * validate process parameter form + * @param parameterPanel + * @return error message (if any) + */ + public default String validate(ProcessParameterPanel parameterPanel) { + return null; + } +} 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 3f7ef31270..6200efb58b 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 @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Level; +import org.adempiere.webui.Extensions; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; import org.adempiere.webui.component.EditorBox; @@ -50,12 +51,14 @@ import org.compiere.model.MClient; import org.compiere.model.MLookup; import org.compiere.model.MPInstance; import org.compiere.model.MPInstancePara; +import org.compiere.model.MProcess; import org.compiere.process.ProcessInfo; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.compiere.util.Util; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.HtmlBasedComponent; import org.zkoss.zk.ui.event.Event; @@ -99,6 +102,7 @@ public class ProcessParameterPanel extends Panel implements // initComponent(); addEventListener("onDynamicDisplay", this); + addEventListener("onPostEditorValueChange", this); } // ProcessParameterPanel private void initComponent() { @@ -445,6 +449,18 @@ public class ProcessParameterPanel extends Panel implements return false; } + if (m_processInfo.getAD_Process_ID() > 0) { + String className = MProcess.get(Env.getCtx(), m_processInfo.getAD_Process_ID()).getClassname(); + List listeners = Extensions.getProcessParameterListeners(className, null); + for(IProcessParameterListener listener : listeners) { + String error = listener.validate(this); + if (!Util.isEmpty(error)) { + FDialog.error(m_WindowNo, this, error); + return false; + } + } + } + return true; } // validateParameters @@ -703,6 +719,7 @@ public class ProcessParameterPanel extends Panel implements processDependencies (changedField); // future processCallout (changedField); } + Events.postEvent("onPostEditorValueChange", this, evt.getSource()); } processNewValue(evt.getNewValue(), evt.getPropertyName()); } @@ -731,8 +748,21 @@ public class ProcessParameterPanel extends Panel implements else if (event.getName().equals("onDynamicDisplay")) { dynamicDisplay(); } + else if (event.getName().equals("onPostEditorValueChange")) { + onPostEditorValueChange((WEditor)event.getData()); + } } + 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()); + for(IProcessParameterListener listener : listeners) { + listener.onChange(this, editor.getColumnName(), editor); + } + } + } + /** * Evaluate Dependencies * @param changedField changed field @@ -874,6 +904,34 @@ public class ProcessParameterPanel extends Panel implements ((HtmlBasedComponent)c).focus(); } + /** + * Get parameter field editor by column name + * @param columnName + * @return editor + */ + public WEditor getEditor(String columnName) { + for(int i = 0; i < m_mFields.size(); i++) { + if (m_mFields.get(i).getColumnName().equals(columnName)) { + return m_wEditors.get(i); + } + } + return null; + } + + /** + * Get parameter field value to editor by column name + * @param columnName + * @return editor + */ + public WEditor getEditorTo(String columnName) { + for(int i = 0; i < m_mFields.size(); i++) { + if (m_mFields.get(i).getColumnName().equals(columnName)) { + return m_wEditors2.get(i); + } + } + return null; + } + static class ZoomListener implements EventListener { private IZoomableEditor searchEditor;