diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index 3755c9a901..3e87c08998 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -81,7 +81,7 @@ public class GridField /** * */ - private static final long serialVersionUID = -757531553169088955L; + private static final long serialVersionUID = 7859929653710975421L; /** * Field Constructor. @@ -812,8 +812,56 @@ public class GridField } // createDefault /** - * Validate initial Field Value. - * Called from MTab.dataNew and MTab.setCurrentRow when inserting + * Validate initial Field Value. Do not push direct value if it doesn't exist + * Called from GridTab.dataNew when inserting + * @return true if valid + */ + public boolean validateValueNoDirect() + { + // null + if (m_value == null || m_value.toString().length() == 0) + { + if (isMandatory(true)) + { + m_error = true; + return false; + } + else + return true; + } + + // Search not cached + if (getDisplayType() == DisplayType.Search && m_lookup != null) + { + // need to re-set invalid values - OK BPartner in PO Line - not OK SalesRep in Invoice + if (m_lookup.getDirect(m_value, false, true) == null) + { + if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " Serach not valid - set to null"); + setValue(null, m_inserting); + m_error = true; + return false; + } + return true; + } + + // cannot be validated + if (!isLookup() + || m_lookup == null + || m_lookup.containsKeyNoDirect(m_value)) + return true; + // it's not null, a lookup and does not have the key + if (isKey() || isParentValue()) // parents/ket are not validated + return true; + + if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " - set to null"); + setValue(null, m_inserting); + m_error = true; + return false; + } // validateValue + + /** + * Validate initial Field Value. Push direct value if it doesn't exist + * Called from GridTab.setCurrentRow when inserting * @return true if valid */ public boolean validateValue() @@ -857,8 +905,7 @@ public class GridField setValue(null, m_inserting); m_error = true; return false; - } // validateValue - + } // validateValuePushDirect /************************************************************************** * Is the Column Visible ? diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index 4ae74f8c40..204f8b2970 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -113,7 +113,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable /** * */ - private static final long serialVersionUID = 1151723870943569774L; + private static final long serialVersionUID = 5446672147679386907L; public static final String DEFAULT_STATUS_MESSAGE = "NavigateOrUpdate"; @@ -1185,15 +1185,15 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable return retValue; setCurrentRow(m_currentRow + 1, true); - // process all Callouts (no dependency check - assumed that settings are valid) - for (int i = 0; i < getFieldCount(); i++) - processCallout(getField(i)); // check validity of defaults for (int i = 0; i < getFieldCount(); i++) { getField(i).refreshLookup(); - getField(i).validateValue(); + getField(i).validateValueNoDirect(); } + // process all Callouts (no dependency check - assumed that settings are valid) + for (int i = 0; i < getFieldCount(); i++) + processCallout(getField(i)); m_mTable.setChanged(false); fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_NEW)); diff --git a/org.adempiere.base/src/org/compiere/model/Lookup.java b/org.adempiere.base/src/org/compiere/model/Lookup.java index ba32408a50..96e077d268 100644 --- a/org.adempiere.base/src/org/compiere/model/Lookup.java +++ b/org.adempiere.base/src/org/compiere/model/Lookup.java @@ -43,7 +43,7 @@ public abstract class Lookup extends AbstractListModel /** * */ - private static final long serialVersionUID = -2811763289904455349L; + private static final long serialVersionUID = -28200392264647953L; /** * Lookup @@ -382,6 +382,12 @@ public abstract class Lookup extends AbstractListModel */ public abstract boolean containsKey (Object key); + /** + * The Lookup contains the key, do not push direct + * @param key key + * @return true if contains key + */ + public abstract boolean containsKeyNoDirect (Object key); /************************************************************************** * Refresh Values - default implementation diff --git a/org.adempiere.base/src/org/compiere/model/MAccountLookup.java b/org.adempiere.base/src/org/compiere/model/MAccountLookup.java index 4ee55f2d48..19c3e05ce3 100644 --- a/org.adempiere.base/src/org/compiere/model/MAccountLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MAccountLookup.java @@ -39,7 +39,7 @@ public final class MAccountLookup extends Lookup implements Serializable /** * */ - private static final long serialVersionUID = 5565166586045152280L; + private static final long serialVersionUID = -6307559127917670193L; /** * Constructor @@ -103,6 +103,11 @@ public final class MAccountLookup extends Lookup implements Serializable return load (intValue); } // containsKey + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + /** * Get Description * @return Description diff --git a/org.adempiere.base/src/org/compiere/model/MLocationLookup.java b/org.adempiere.base/src/org/compiere/model/MLocationLookup.java index 970c9002ad..fb50ff7282 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocationLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLocationLookup.java @@ -37,7 +37,7 @@ public final class MLocationLookup extends Lookup /** * */ - private static final long serialVersionUID = -7335118019935048922L; + private static final long serialVersionUID = 7238110708451510319L; /** * Constructor @@ -95,6 +95,10 @@ public final class MLocationLookup extends Lookup return getLocation(key, null) != null; } // containsKey + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } /************************************************************************** * Get Location diff --git a/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java b/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java index 391ffbde84..bfc20cb5bb 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLocatorLookup.java @@ -48,7 +48,7 @@ public final class MLocatorLookup extends Lookup implements Serializable /** * */ - private static final long serialVersionUID = 8932848190660391496L; + private static final long serialVersionUID = -6041455174391573888L; /** * Constructor @@ -208,6 +208,11 @@ public final class MLocatorLookup extends Lookup implements Serializable return m_lookup.containsKey(key); } // containsKey + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + /** * Get Data Direct from Table * @param keyValue integer key value diff --git a/org.adempiere.base/src/org/compiere/model/MLookup.java b/org.adempiere.base/src/org/compiere/model/MLookup.java index c54d55ac29..1203477584 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLookup.java @@ -56,7 +56,7 @@ public final class MLookup extends Lookup implements Serializable /** * */ - private static final long serialVersionUID = 5784044288965615466L; + private static final long serialVersionUID = 2228200000988048623L; /** * MLookup Constructor @@ -179,7 +179,7 @@ public final class MLookup extends Lookup implements Serializable * @param key key (Integer for Keys or String for Lists) * @return value */ - public NamePair get (Object key) + public NamePair get (Object key, boolean includeDirect) { if (key == null || MINUS_ONE.equals(key)) // indicator for null return null; @@ -212,11 +212,23 @@ public final class MLookup extends Lookup implements Serializable return retValue; } - // Try to get it directly - boolean cacheLocal = m_info.IsValidated ; - return getDirect(key, false, cacheLocal); // do NOT cache + if (includeDirect) { + // Try to get it directly + boolean cacheLocal = m_info.IsValidated ; + return getDirect(key, false, cacheLocal); // do NOT cache + } + + return null; } // get + public NamePair get(Object key) { + return get(key, true); + } + + public NamePair getNoDirect(Object key) { + return get(key, false); + } + /** * Get Display value (name). * If not found return key embedded in inactive signs. @@ -254,6 +266,24 @@ public final class MLookup extends Lookup implements Serializable } } // containsKey + /** + * The Lookup contains the key, do not get direct + * @param key key + * @return true if key is known + */ + public boolean containsKeyNoDirect (Object key) + { + //should check direct too + if (m_lookup.containsKey(key)) + return true; + else { + if (m_lookup.size() > 0) + return false; + else + return ( getNoDirect(key) != null ); + } + } // containsKeyNoDirect + /** * @return a string representation of the object. */ diff --git a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java index 0a705da80c..ebc8e2ac63 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java @@ -607,7 +607,7 @@ public class MLookupFactory msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery); retValue.DisplayColumn = lookupDisplayColumn; retValue.InfoWindowId = infoWindowId; - retValue.QueryDirect = directQuery; + retValue.QueryDirect = MRole.getDefault().addAccessSQL(directQuery, TableName, true, false); s_cacheRefTable.put(key.toString(), retValue.cloneIt()); return retValue; } // getLookup_Table @@ -814,7 +814,7 @@ public class MLookupFactory MLookupInfo lInfo = new MLookupInfo(realSQL.toString(), TableName, msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery); lInfo.DisplayColumn = displayColumn.toString(); - lInfo.QueryDirect = directQuery; + lInfo.QueryDirect = MRole.getDefault().addAccessSQL(directQuery, TableName, true, false); s_cacheRefTable.put(cacheKey.toString(), lInfo.cloneIt()); return lInfo; } // getLookup_TableDir diff --git a/org.adempiere.base/src/org/compiere/model/MPAttributeLookup.java b/org.adempiere.base/src/org/compiere/model/MPAttributeLookup.java index 2f0b4556d2..33b9725ba0 100644 --- a/org.adempiere.base/src/org/compiere/model/MPAttributeLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MPAttributeLookup.java @@ -41,11 +41,10 @@ import org.compiere.util.NamePair; public class MPAttributeLookup extends Lookup implements Serializable { - /** * */ - private static final long serialVersionUID = 70273805106666111L; + private static final long serialVersionUID = 1877125428249819248L; /** * Constructor @@ -88,6 +87,11 @@ public class MPAttributeLookup extends Lookup return get(key) != null; } // containsKey + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + /** * Get Object of Key Value * @param value value diff --git a/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java b/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java index daf6389e2a..1c46867bbf 100644 --- a/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java @@ -39,7 +39,7 @@ public class MPaymentLookup extends Lookup implements Serializable { /** * */ - private static final long serialVersionUID = 6505672741140583659L; + private static final long serialVersionUID = 2876345457828980720L; /** Context */ private Properties m_ctx; @@ -97,6 +97,11 @@ public class MPaymentLookup extends Lookup implements Serializable { return false; } + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + @Override public String getColumnName() { return "PaymentRule"; diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/XLookup.java b/org.adempiere.ui.swing/src/org/compiere/grid/XLookup.java index b9b32f5e3c..c46a8cc952 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/XLookup.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/XLookup.java @@ -36,7 +36,7 @@ public class XLookup extends Lookup /** * */ - private static final long serialVersionUID = 1388987648081532657L; + private static final long serialVersionUID = -1960941688071305272L; /** * Manual Lookup @@ -94,6 +94,11 @@ public class XLookup extends Lookup return false; } // containsKey + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + /** * Get Object of Key Value * @param key key diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/GetListLookup.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/GetListLookup.java index 2df32ca03e..6ae815acfa 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/GetListLookup.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/GetListLookup.java @@ -47,11 +47,11 @@ import org.w3c.dom.Document; * */ public class GetListLookup extends Lookup { - /** - * generated serial id + * */ - private static final long serialVersionUID = -137206840260406730L; + private static final long serialVersionUID = 2582520499473909390L; + private String filter; private String serviceType; private String endPoint; @@ -203,6 +203,11 @@ public class GetListLookup extends Lookup { return dataMap.containsKey(key); } + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + /** * Refresh & return number of items read. * Get get data of parent lookups diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/QueryDataLookup.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/QueryDataLookup.java index 895ec1e04c..f7cae99a59 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/QueryDataLookup.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/client/QueryDataLookup.java @@ -51,11 +51,11 @@ import org.w3c.dom.Node; * */ public class QueryDataLookup extends Lookup { - /** - * generated serial id + * */ - private static final long serialVersionUID = -137206840260406730L; + private static final long serialVersionUID = -1322365740845617635L; + private String filter; private String serviceType; private String endPoint; @@ -219,6 +219,11 @@ public class QueryDataLookup extends Lookup { return dataMap.containsKey(key); } + public boolean containsKeyNoDirect (Object key) + { + return containsKey(key); + } + /** * Refresh & return number of items read. * Get get data of parent lookups