diff --git a/org.adempiere.base/src/org/compiere/model/GridFieldVO.java b/org.adempiere.base/src/org/compiere/model/GridFieldVO.java index 6f9accc26b..83bc5ecc40 100644 --- a/org.adempiere.base/src/org/compiere/model/GridFieldVO.java +++ b/org.adempiere.base/src/org/compiere/model/GridFieldVO.java @@ -683,7 +683,7 @@ public class GridFieldVO implements Serializable public void loadLookupInfo() { try { - lookupInfo = MLookupFactory.getLookupInfo (ctx, WindowNo, AD_Column_ID, displayType, + lookupInfo = MLookupFactory.getLookupInfo (ctx, WindowNo, TabNo,AD_Column_ID, displayType, Env.getLanguage(ctx), ColumnName, AD_Reference_Value_ID, IsParent, ValidationCode); if (lookupInfo == null) diff --git a/org.adempiere.base/src/org/compiere/model/MLookup.java b/org.adempiere.base/src/org/compiere/model/MLookup.java index f5d2940b51..c54d55ac29 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLookup.java @@ -742,7 +742,7 @@ public final class MLookup extends Lookup implements Serializable // not validated if (!m_info.IsValidated) { - String validation = Env.parseContext(m_info.ctx, m_info.WindowNo, m_info.ValidationCode, false); + String validation = Env.parseContext(m_info.ctx, m_info.WindowNo, m_info.tabNo, m_info.ValidationCode, false); m_info.parsedValidationCode = validation; if (validation.length() == 0 && m_info.ValidationCode.length() > 0) { diff --git a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java index 9a8cd9f388..7dd1438ade 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java @@ -129,6 +129,52 @@ public class MLookupFactory return info; } + + public static MLookupInfo getLookupInfo(Properties ctx, int WindowNo, int TabNo, int Column_ID, int AD_Reference_ID) + { + String ColumnName = ""; + int AD_Reference_Value_ID = 0; + boolean IsParent = false; + String ValidationCode = ""; + // + String sql = "SELECT c.ColumnName, c.AD_Reference_Value_ID, c.IsParent, vr.Code " + + "FROM AD_Column c" + + " LEFT OUTER JOIN AD_Val_Rule vr ON (c.AD_Val_Rule_ID=vr.AD_Val_Rule_ID) " + + "WHERE c.AD_Column_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, Column_ID); + // + rs = pstmt.executeQuery(); + if (rs.next()) + { + ColumnName = rs.getString(1); + AD_Reference_Value_ID = rs.getInt(2); + IsParent = "Y".equals(rs.getString(3)); + ValidationCode = rs.getString(4); + } + else + s_log.log(Level.SEVERE, "Column Not Found - AD_Column_ID=" + Column_ID); + } + catch (SQLException ex) + { + s_log.log(Level.SEVERE, "create", ex); + } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + // + MLookupInfo info = getLookupInfo (ctx, WindowNo, TabNo, Column_ID, AD_Reference_ID, + Env.getLanguage(ctx), ColumnName, AD_Reference_Value_ID, IsParent, ValidationCode); + + return info; + } /** * Create MLookup @@ -170,6 +216,36 @@ public class MLookupFactory int Column_ID, int AD_Reference_ID, Language language, String ColumnName, int AD_Reference_Value_ID, boolean IsParent, String ValidationCode) + { + return getLookupInfo(ctx, WindowNo, 0, + Column_ID, AD_Reference_ID, + language, ColumnName, AD_Reference_Value_ID, + IsParent, ValidationCode); + } // createLookupInfo + + /************************************************************************** + * Get Information for Lookups based on Column_ID for Table Columns or Process Parameters. + * + * The SQL returns three columns: + *
+	 *		Key, Value, Name, IsActive	(where either key or value is null)
+	 *  
+ * @param ctx context for access + * @param language report language + * @param WindowNo window no + * @param tabNo tab no + * @param Column_ID AD_Column_ID or AD_Process_Para_ID + * @param ColumnName key column name + * @param AD_Reference_ID display type + * @param AD_Reference_Value_ID AD_Reference (List, Table) + * @param IsParent parent (prevents query to directly access value) + * @param ValidationCode optional SQL validation + * @return lookup info structure + */ + static public MLookupInfo getLookupInfo (Properties ctx, int WindowNo, int tabNo, + int Column_ID, int AD_Reference_ID, + Language language, String ColumnName, int AD_Reference_Value_ID, + boolean IsParent, String ValidationCode) { MLookupInfo info = null; boolean needToAddSecurity = true; @@ -199,6 +275,7 @@ public class MLookupFactory // remaining values info.ctx = ctx; info.WindowNo = WindowNo; + info.tabNo = tabNo; info.Column_ID = Column_ID; info.DisplayType = AD_Reference_ID; info.AD_Reference_Value_ID = AD_Reference_Value_ID; diff --git a/org.adempiere.base/src/org/compiere/model/MLookupInfo.java b/org.adempiere.base/src/org/compiere/model/MLookupInfo.java index 530c3b0639..800a296232 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupInfo.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupInfo.java @@ -160,7 +160,7 @@ public class MLookupInfo implements Serializable, Cloneable ZoomQuery = zoomQuery; } // MLookupInfo - static final long serialVersionUID = -7958664359250070233L; + static final long serialVersionUID = -1869207615748248653L; /** SQL Query */ public String Query = null; @@ -190,6 +190,8 @@ public class MLookupInfo implements Serializable, Cloneable public Properties ctx = null; /** WindowNo */ public int WindowNo; + /** TabNo */ + public int tabNo; /** AD_Column_Info or AD_Process_Para */ public int Column_ID; diff --git a/org.adempiere.base/src/org/compiere/util/Env.java b/org.adempiere.base/src/org/compiere/util/Env.java index cb16c61577..c4fb04a588 100644 --- a/org.adempiere.base/src/org/compiere/util/Env.java +++ b/org.adempiere.base/src/org/compiere/util/Env.java @@ -1421,6 +1421,78 @@ public final class Env return outStr.toString(); } // parseContext + + /** + * Parse Context replaces global or Window context @tag@ with actual value. + * + * @tag@ are ignored otherwise "" is returned + * @param ctx context + * @param WindowNo Number of Window + * @param tabNo Number of Tab + * @param value Message to be parsed + * @param onlyTab if true, no defaults are used + * @param ignoreUnparsable if true, unsuccessful @return parsed String or "" if not successful and ignoreUnparsable + * @return parsed context + */ + public static String parseContext (Properties ctx, int WindowNo, int tabNo, String value, + boolean onlyTab, boolean ignoreUnparsable) + { + if (value == null || value.length() == 0) + return ""; + + String token; + String inStr = new String(value); + StringBuilder outStr = new StringBuilder(); + + int i = inStr.indexOf('@'); + while (i != -1) + { + outStr.append(inStr.substring(0, i)); // up to @ + inStr = inStr.substring(i+1, inStr.length()); // from first @ + + int j = inStr.indexOf('@'); // next @ + if (j < 0) + { + if (log.isLoggable(Level.INFO)) log.log(Level.INFO, "No second tag: " + inStr); + //not context variable, add back @ and break + outStr.append("@"); + break; + } + + token = inStr.substring(0, j); + + // IDEMPIERE-194 Handling null context variable + String defaultV = null; + int idx = token.indexOf(":"); // or clause + if (idx >= 0) + { + defaultV = token.substring(idx+1, token.length()); + token = token.substring(0, idx); + } + + String ctxInfo = getContext(ctx, WindowNo, tabNo, token, onlyTab); // get context + if (ctxInfo.length() == 0 && (token.startsWith("#") || token.startsWith("$")) ) + ctxInfo = getContext(ctx, token); // get global context + + if (ctxInfo.length() == 0 && defaultV != null) + ctxInfo = defaultV; + + if (ctxInfo.length() == 0) + { + if (log.isLoggable(Level.CONFIG)) log.config("No Context Win=" + WindowNo + " for: " + token); + if (!ignoreUnparsable) + return ""; // token not found + } + else + outStr.append(ctxInfo); // replace context with Context + + inStr = inStr.substring(j+1, inStr.length()); // from second @ + i = inStr.indexOf('@'); + } + outStr.append(inStr); // add the rest of the string + + return outStr.toString(); + } // parseContext /** * Parse Context replaces global or Window context @tag@ with actual value. @@ -1436,6 +1508,22 @@ public final class Env { return parseContext(ctx, WindowNo, value, onlyWindow, false); } // parseContext + + /** + * Parse Context replaces global or Window context @tag@ with actual value. + * + * @param ctx context + * @param WindowNo Number of Window + * @param TabNo Number of Tab + * @param value Message to be parsed + * @param onlyWindow if true, no defaults are used + * @return parsed String or "" if not successful + */ + public static String parseContext (Properties ctx, int WindowNo, int tabNo, String value, + boolean onlyWindow) + { + return parseContext(ctx, WindowNo, tabNo, value, onlyWindow, false); + } // parseContext /** * Parse expression, replaces global or PO properties @tag@ with actual value.