IDEMPIERE-1465 Zoom Across Only retrieve one Parent Record when target have multiple parent record. / commit patch provided by Heng Sin

This commit is contained in:
Carlos Ruiz 2013-11-26 20:06:57 -05:00
parent 2f14109f1d
commit 382208ffe9
1 changed files with 76 additions and 33 deletions

View File

@ -411,79 +411,122 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
if (field.getColumnName().equalsIgnoreCase(query.getZoomColumnName())) if (field.getColumnName().equalsIgnoreCase(query.getZoomColumnName()))
{ {
gridWindow.initTab(tabIndex); gridWindow.initTab(tabIndex);
int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause()); int[] parentIds = DB.getIDsEx(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
if (parentId > 0) if (parentIds.length > 0)
{ {
Map<Integer, Object[]>parentMap = new TreeMap<Integer, Object[]>(); GridTab parentTab = null;
int index = tabIndex; Map<Integer, MQuery>queryMap = new TreeMap<Integer, MQuery>();
int oldpid = parentId;
GridTab currentTab = gTab; for (int parentId : parentIds)
while (index > 0)
{ {
index--; Map<Integer, Object[]>parentMap = new TreeMap<Integer, Object[]>();
GridTab pTab = gridWindow.getTab(index); int index = tabIndex;
if (pTab.getTabLevel() < currentTab.getTabLevel()) int oldpid = parentId;
GridTab currentTab = gTab;
while (index > 0)
{ {
gridWindow.initTab(index); index--;
if (index > 0) GridTab pTab = gridWindow.getTab(index);
if (pTab.getTabLevel() < currentTab.getTabLevel())
{ {
if (pTab.getLinkColumnName() != null && pTab.getLinkColumnName().trim().length() > 0) if (parentTab == null)
parentTab = pTab;
gridWindow.initTab(index);
if (index > 0)
{ {
int pid = DB.getSQLValue(null, "SELECT " + pTab.getLinkColumnName() + " FROM " + pTab.getTableName() + " WHERE " + currentTab.getLinkColumnName() + " = ?", oldpid); if (pTab.getLinkColumnName() != null && pTab.getLinkColumnName().trim().length() > 0)
if (pid > 0)
{ {
parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid}); int pid = DB.getSQLValue(null, "SELECT " + pTab.getLinkColumnName() + " FROM " + pTab.getTableName() + " WHERE " + currentTab.getLinkColumnName() + " = ?", oldpid);
oldpid = pid; if (pid > 0)
currentTab = pTab; {
} parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid});
else oldpid = pid;
{ currentTab = pTab;
parentMap.clear(); }
break; else
{
parentMap.clear();
break;
}
} }
} }
else
{
parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid});
}
}
}
for(Map.Entry<Integer, Object[]> entry : parentMap.entrySet())
{
GridTab pTab = gridWindow.getTab(entry.getKey());
Object[] value = entry.getValue();
MQuery pquery = queryMap.get(entry.getKey());
if (pquery == null)
{
pquery = new MQuery(pTab.getAD_Table_ID());
queryMap.put(entry.getKey(), pquery);
pquery.addRestriction((String)value[0], "=", value[1]);
} }
else else
{ {
parentMap.put(index, new Object[]{currentTab.getLinkColumnName(), oldpid}); pquery.addRestriction((String)value[0], "=", value[1], null, null, false, 0);
} }
} }
} }
for(Map.Entry<Integer, Object[]> entry : parentMap.entrySet()) for (Map.Entry<Integer, MQuery> entry : queryMap.entrySet())
{ {
GridTab pTab = gridWindow.getTab(entry.getKey()); GridTab pTab = gridWindow.getTab(entry.getKey());
Object[] value = entry.getValue();
MQuery pquery = new MQuery(pTab.getAD_Table_ID());
pquery.addRestriction((String)value[0], "=", value[1]);
IADTabpanel tp = adTabbox.findADTabpanel(pTab); IADTabpanel tp = adTabbox.findADTabpanel(pTab);
tp.createUI(); tp.createUI();
if (tp.getTabLevel() == 0) if (tp.getTabLevel() == 0)
{ {
pTab.setQuery(pquery); pTab.setQuery(entry.getValue());
tp.query(); tp.query();
} }
else else
{ {
tp.query(); tp.query();
pTab.setQuery(pquery); pTab.setQuery(entry.getValue());
tp.query(); tp.query();
} }
} }
MQuery targetQuery = new MQuery(gTab.getAD_Table_ID()); MQuery targetQuery = new MQuery(gTab.getAD_Table_ID());
targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentId); targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentTab.getRecord_ID());
gTab.setQuery(targetQuery); gTab.setQuery(targetQuery);
IADTabpanel gc = null; IADTabpanel gc = null;
gc = adTabbox.findADTabpanel(gTab); gc = adTabbox.findADTabpanel(gTab);
gc.createUI(); gc.createUI();
gc.query(false, 0, 0); gc.query(false, 0, 0);
int zoomColumnIndex = -1;
GridTable table = gTab.getTableModel(); GridTable table = gTab.getTableModel();
for (int i = 0; i < table.getColumnCount(); i++)
{
if (table.getColumnName(i).equalsIgnoreCase(query.getZoomColumnName()))
{
zoomColumnIndex = i;
break;
}
}
int count = table.getRowCount(); int count = table.getRowCount();
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
int id = table.getKeyID(i); int id = -1;
if (zoomColumnIndex >= 0)
{
Object zoomValue = table.getValueAt(i, zoomColumnIndex);
if (zoomValue != null && zoomValue instanceof Number)
{
id = ((Number)zoomValue).intValue();
}
}
else
{
id = table.getKeyID(i);
}
if (id == ((Integer)query.getZoomValue()).intValue()) if (id == ((Integer)query.getZoomValue()).intValue())
{ {
setActiveTab(gridWindow.getTabIndex(gTab), null); setActiveTab(gridWindow.getTabIndex(gTab), null);