From f4631da9a8cee70e4ad5ce88023fe9066499ecbb Mon Sep 17 00:00:00 2001 From: trifonnt Date: Sat, 26 Mar 2011 00:07:47 -0500 Subject: [PATCH] FR [3090578] - GridTable wrong 'is value changed' determination https://sourceforge.net/tracker/?func=detail&atid=879332&aid=3090578&group_id=176962 and Fr [3052371] - Grid error when switching from a string field https://sourceforge.net/tracker/?func=detail&aid=3052371&group_id=176962&atid=879332 --- .../src/org/compiere/model/GridTable.java | 61 ++++++++++++++++--- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/GridTable.java b/org.adempiere.base/src/org/compiere/model/GridTable.java index c323805b5d..b7a7c650ea 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTable.java +++ b/org.adempiere.base/src/org/compiere/model/GridTable.java @@ -1188,11 +1188,7 @@ public class GridTable extends AbstractTableModel // Has anything changed? Object oldValue = getValueAt(row, col); - if (!force && ( - (oldValue == null && value == null) - || (oldValue != null && oldValue.equals(value)) - || (oldValue != null && value != null && oldValue.toString().equals(value.toString())) - )) + if (!force && !isValueChanged(oldValue, value) ) { log.finest("r=" + row + " c=" + col + " - New=" + value + "==Old=" + oldValue + " - Ignored"); return; @@ -2076,10 +2072,7 @@ public class GridTable extends AbstractTableModel ; // ignore // *** Data changed *** - else if (m_inserting - || (oldValue == null && value != null) - || (oldValue != null && value == null) - || !oldValue.equals (value)) // changed + else if (m_inserting || isValueChanged(oldValue, value) ) { // Check existence int poIndex = po.get_ColumnIndex(columnName); @@ -3668,5 +3661,53 @@ public class GridTable extends AbstractTableModel currentLevel = Env.getContextAsInt(m_ctx, m_WindowNo, tabNo, GridTab.CTX_TabLevel); } return tabNo; - } + } + + private boolean isNotNullAndIsEmpty (Object value) { + if (value != null + && (value instanceof String) + && value.toString().equals("") + ) + { + return true; + } else { + return false; + } + + } + + private boolean isValueChanged(Object oldValue, Object value) + { + if ( isNotNullAndIsEmpty(oldValue) ) { + oldValue = null; + } + + if ( isNotNullAndIsEmpty(value) ) { + value = null; + } + + boolean bChanged = (oldValue == null && value != null) + || (oldValue != null && value == null); + + if (!bChanged && oldValue != null) + { + if (oldValue.getClass().equals(value.getClass())) + { + if (oldValue instanceof Comparable) + { + bChanged = (((Comparable)oldValue).compareTo(value) != 0); + } + else + { + bChanged = !oldValue.equals(value); + } + } + else if(value != null) + { + bChanged = !(oldValue.toString().equals(value.toString())); + } + } + return bChanged; + } + }