From fa569115e116473977945326c4ca0dad327c538c Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 26 Feb 2010 02:07:55 +0000 Subject: [PATCH] The window context variable is share by all tab and can get mix up when user navigate from one tab to another. This patch recreate the window context variable before entering a tab to solve the potential conflict issue. Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2959339 --- base/src/org/compiere/model/GridField.java | 29 ++++++---- .../webui/component/AbstractADTab.java | 58 +++++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/base/src/org/compiere/model/GridField.java b/base/src/org/compiere/model/GridField.java index ac6474393a..b0dadc67e5 100644 --- a/base/src/org/compiere/model/GridField.java +++ b/base/src/org/compiere/model/GridField.java @@ -1278,6 +1278,19 @@ public class GridField m_inserting = inserting; m_error = false; // reset error + updateContext(); + + // Does not fire, if same value + Object oldValue = m_oldValue; + if (inserting) + oldValue = INSERTING; + m_propertyChangeListeners.firePropertyChange(PROPERTY, oldValue, m_value); + } // setValue + + /** + * Update env. context with current value + */ + public void updateContext() { // Set Context if (m_vo.displayType == DisplayType.Text || m_vo.displayType == DisplayType.Memo @@ -1286,15 +1299,15 @@ public class GridField || m_vo.displayType == DisplayType.RowID || isEncrypted()) ; // ignore - else if (newValue instanceof Boolean) + else if (m_value instanceof Boolean) { backupValue(); // teo_sarca [ 1699826 ] Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, - ((Boolean)newValue).booleanValue()); + ((Boolean)m_value).booleanValue()); Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, m_value==null ? null : (((Boolean)m_value) ? "Y" : "N")); } - else if (newValue instanceof Timestamp) + else if (m_value instanceof Timestamp) { backupValue(); // teo_sarca [ 1699826 ] Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, (Timestamp)m_value); @@ -1308,14 +1321,8 @@ public class GridField m_value==null ? null : m_value.toString()); Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, m_value==null ? null : m_value.toString()); - } - - // Does not fire, if same value - Object oldValue = m_oldValue; - if (inserting) - oldValue = INSERTING; - m_propertyChangeListeners.firePropertyChange(PROPERTY, oldValue, m_value); - } // setValue + } + } /** * Set Value and Validate diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/AbstractADTab.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/AbstractADTab.java index c0bb78cf44..f7a65cc212 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/AbstractADTab.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/AbstractADTab.java @@ -18,14 +18,18 @@ package org.adempiere.webui.component; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import org.adempiere.webui.panel.ADSortTab; import org.adempiere.webui.panel.ADTabpanel; import org.adempiere.webui.panel.IADTabpanel; import org.adempiere.webui.part.AbstractUIPart; import org.compiere.model.DataStatusEvent; +import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.util.CLogger; +import org.compiere.util.Env; import org.compiere.util.Evaluator; /** @@ -119,6 +123,7 @@ public abstract class AbstractADTab extends AbstractUIPart implements IADTab canJump = canNavigateTo(oldIndex, newIndex); if (canJump) { + prepareContext(newIndex, newTab); doTabSelectionChanged(oldIndex, newIndex); } } @@ -126,6 +131,59 @@ public abstract class AbstractADTab extends AbstractUIPart implements IADTab return canJump; } + private void prepareContext(int newIndex, IADTabpanel newTab) { + //update context + if (newTab != null) + { + List parents = new ArrayList(); + //get parent list + if (newIndex > 0) + { + int currentLevel = newTab.getTabLevel(); + for (int i = newIndex - 1; i >= 0; i--) + { + IADTabpanel adtab = tabPanelList.get(i); + if (adtab.getGridTab() == null) continue; + if (adtab instanceof ADSortTab) continue; + if (adtab.getTabLevel() < currentLevel || i == 0) + { + parents.add(i); + currentLevel = adtab.getTabLevel(); + } + } + Collections.reverse(parents); + } + + //clear context + for (int i = 0; i < tabPanelList.size(); i++) + { + IADTabpanel adtab = tabPanelList.get(i); + if (adtab.getGridTab() == null) continue; + if (adtab instanceof ADSortTab) continue; + GridField[] fields = adtab.getGridTab().getFields(); + for (GridField gf : fields) + { + Env.setContext(Env.getCtx(), gf.getWindowNo(), gf.getColumnName(), ""); + } + } + + //add parent value to context + if (!parents.isEmpty()) + { + for(int i : parents) + { + IADTabpanel adtab = tabPanelList.get(i); + + GridField[] fields = adtab.getGridTab().getFields(); + for (GridField gf : fields) + { + gf.updateContext(); + } + } + } + } + } + protected abstract void doTabSelectionChanged(int oldIndex, int newIndex); public boolean isDisplay(int index) {