diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index ddd9a38e42..7a02ae0ca6 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -40,6 +40,7 @@ import org.adempiere.exceptions.AdempiereException; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.DefaultEvaluatee; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Evaluatee; @@ -1222,57 +1223,7 @@ public class GridField */ public String get_ValueAsString (Properties ctx, String variableName) { - //ref column - String foreignColumn = ""; - int f = variableName.indexOf('.'); - if (f > 0) { - foreignColumn = variableName.substring(f+1, variableName.length()); - variableName = variableName.substring(0, f); - } - - String value = null; - if( m_vo.TabNo == 0) - value = Env.getContext (ctx, m_vo.WindowNo, variableName, true); - else - { - boolean tabOnly = false; - if (variableName.startsWith("~")) - { - variableName = variableName.substring(1); - tabOnly = true; - } - value = Env.getContext (ctx, m_vo.WindowNo, m_vo.TabNo, variableName, tabOnly, true); - } - if (!Util.isEmpty(value) && !Util.isEmpty(foreignColumn) && variableName.endsWith("_ID")) { - int id = 0; - try { - id = Integer.parseInt(value); - } catch (Exception e){} - if (id > 0) { - String refValue = ""; - if (getGridTab() != null) { - MColumn column = MColumn.get(ctx, getGridTab().getTableName(), variableName); - if (column != null) { - String foreignTable = column.getReferenceTableName(); - refValue = DB.getSQLValueString(null, - "SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE " - + foreignTable + "_ID = ?", id); - } - return refValue; - } else { - // no GridTab - maybe coming from process parameter, try tableName from columnName - String foreignTable = variableName.substring(0, variableName.length()-3); - MTable table = MTable.get(ctx, foreignTable); - if (table != null) { - refValue = DB.getSQLValueString(null, - "SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE " - + foreignTable + "_ID = ?", id); - return refValue; - } - } - } - } - return value; + return new DefaultEvaluatee(getGridTab(), m_vo.WindowNo, m_vo.TabNo).get_ValueAsString(ctx, variableName); } // get_ValueAsString diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index 7e09ff0f09..1e7a27d461 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -48,6 +48,7 @@ import org.compiere.Adempiere; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.DefaultEvaluatee; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Evaluatee; @@ -1623,7 +1624,18 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable */ public String get_ValueAsString (String variableName) { - return Env.getContext (m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, variableName, false, true); + return get_ValueAsString (m_vo.ctx, variableName); + } // get_ValueAsString + + /** + * Get Variable Value (Evaluatee) + * @param ctx context + * @param variableName name + * @return value + */ + public String get_ValueAsString (Properties ctx, String variableName) + { + return new DefaultEvaluatee(this, m_vo.WindowNo, m_vo.TabNo).get_ValueAsString(ctx, variableName); } // get_ValueAsString /** diff --git a/org.adempiere.base/src/org/compiere/util/DefaultEvaluatee.java b/org.adempiere.base/src/org/compiere/util/DefaultEvaluatee.java new file mode 100644 index 0000000000..a9b4ee59c2 --- /dev/null +++ b/org.adempiere.base/src/org/compiere/util/DefaultEvaluatee.java @@ -0,0 +1,128 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * 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., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.compiere.util; + +import java.util.Properties; + +import org.compiere.model.GridTab; +import org.compiere.model.MColumn; +import org.compiere.model.MTable; + +/** + * @author hengsin + * + */ +public class DefaultEvaluatee implements Evaluatee { + + private GridTab m_GridTab; + private int m_WindowNo; + private int m_TabNo; + + /** + * + * @param gridTab + * @param windowNo + * @param tabNo + */ + public DefaultEvaluatee(GridTab gridTab, int windowNo, int tabNo) { + this.m_GridTab = gridTab; + this.m_WindowNo = windowNo; + this.m_TabNo = tabNo; + } + + @Override + public String get_ValueAsString(String variableName) { + return get_ValueAsString(Env.getCtx(), variableName); + } + + /** + * Get Variable Value (Evaluatee) + * @param variableName name + * @return value + */ + public String get_ValueAsString (Properties ctx, String variableName) + { + //ref column + String foreignColumn = ""; + int f = variableName.indexOf('.'); + if (f > 0) { + foreignColumn = variableName.substring(f+1, variableName.length()); + variableName = variableName.substring(0, f); + } + + String value = null; + if( m_TabNo == 0) + value = Env.getContext (ctx, m_WindowNo, variableName, true); + else + { + boolean tabOnly = false; + if (variableName.startsWith("~")) + { + variableName = variableName.substring(1); + tabOnly = true; + } + value = Env.getContext (ctx, m_WindowNo, m_TabNo, variableName, tabOnly, true); + } + if (!Util.isEmpty(value) && !Util.isEmpty(foreignColumn) && variableName.endsWith("_ID")) { + int id = 0; + try { + id = Integer.parseInt(value); + } catch (Exception e){} + if (id > 0) { + String refValue = ""; + MColumn column = null; + if (m_GridTab != null) { + column = MColumn.get(ctx, m_GridTab.getTableName(), variableName); + if (column == null) { + //try parent + GridTab parent = m_GridTab.getParentTab(); + while (column == null && parent != null) { + column = MColumn.get(ctx, parent.getTableName(), variableName); + parent = parent.getParentTab(); + } + } + } + if (column != null) { + String foreignTable = column.getReferenceTableName(); + refValue = DB.getSQLValueString(null, + "SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE " + + foreignTable + "_ID = ?", id); + return refValue; + } else { + // no MColumn found, try tableName from columnName + String foreignTable = variableName.substring(0, variableName.length()-3); + MTable table = MTable.get(ctx, foreignTable); + if (table != null) { + refValue = DB.getSQLValueString(null, + "SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE " + + foreignTable + "_ID = ?", id); + return refValue; + } + } + } + } + return value; + } +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java index 1caa2edaf6..56bb3270af 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java @@ -90,6 +90,7 @@ import org.compiere.model.X_AD_FieldGroup; import org.compiere.model.X_AD_ToolBarButton; import org.compiere.util.CCache; import org.compiere.util.CLogger; +import org.compiere.util.DefaultEvaluatee; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Evaluatee; @@ -1253,7 +1254,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer @Override public String get_ValueAsString(String variableName) { - return Env.getContext(Env.getCtx(), windowNo, variableName); + return new DefaultEvaluatee(getGridTab(), windowNo, tabNo).get_ValueAsString(Env.getCtx(), variableName); } // get_ValueAsString /**