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,8 +411,13 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
if (field.getColumnName().equalsIgnoreCase(query.getZoomColumnName()))
{
gridWindow.initTab(tabIndex);
int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
if (parentId > 0)
int[] parentIds = DB.getIDsEx(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
if (parentIds.length > 0)
{
GridTab parentTab = null;
Map<Integer, MQuery>queryMap = new TreeMap<Integer, MQuery>();
for (int parentId : parentIds)
{
Map<Integer, Object[]>parentMap = new TreeMap<Integer, Object[]>();
int index = tabIndex;
@ -424,6 +429,8 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
GridTab pTab = gridWindow.getTab(index);
if (pTab.getTabLevel() < currentTab.getTabLevel())
{
if (parentTab == null)
parentTab = pTab;
gridWindow.initTab(index);
if (index > 0)
{
@ -454,36 +461,72 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
{
GridTab pTab = gridWindow.getTab(entry.getKey());
Object[] value = entry.getValue();
MQuery pquery = new MQuery(pTab.getAD_Table_ID());
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
{
pquery.addRestriction((String)value[0], "=", value[1], null, null, false, 0);
}
}
}
for (Map.Entry<Integer, MQuery> entry : queryMap.entrySet())
{
GridTab pTab = gridWindow.getTab(entry.getKey());
IADTabpanel tp = adTabbox.findADTabpanel(pTab);
tp.createUI();
if (tp.getTabLevel() == 0)
{
pTab.setQuery(pquery);
pTab.setQuery(entry.getValue());
tp.query();
}
else
{
tp.query();
pTab.setQuery(pquery);
pTab.setQuery(entry.getValue());
tp.query();
}
}
MQuery targetQuery = new MQuery(gTab.getAD_Table_ID());
targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentId);
targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentTab.getRecord_ID());
gTab.setQuery(targetQuery);
IADTabpanel gc = null;
gc = adTabbox.findADTabpanel(gTab);
gc.createUI();
gc.query(false, 0, 0);
int zoomColumnIndex = -1;
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();
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())
{
setActiveTab(gridWindow.getTabIndex(gTab), null);