IDEMPIERE-1232 Zoom condition fixes. 1) Fixed WFEditor.zoom not using zoom condition. 2) Added null check for the query parameter in AEnv.zoom methods 3) Fixed AEnv.zoom(AD_Window_ID, query) not using zoom condition. Added AEnv.showZoomWindow(AD_Window_ID, query) to replace the direct opening of zoom window usage.

This commit is contained in:
Heng Sin Low 2013-08-12 14:40:17 +08:00
parent 6de2833897
commit 288c967594
3 changed files with 57 additions and 48 deletions

View File

@ -75,6 +75,9 @@ public class MZoomCondition extends X_AD_ZoomCondition
private static int findZoomWindowByTableId(int AD_Table_ID, MQuery query)
{
if (query == null)
return 0;
MZoomCondition[] conditions = MZoomCondition.getConditions(AD_Table_ID);
if (conditions.length > 0)
{
@ -111,6 +114,9 @@ public class MZoomCondition extends X_AD_ZoomCondition
*/
public static int findZoomWindowByWindowId(int AD_Window_ID, MQuery query)
{
if (query == null)
return 0;
int tableID = DB.getSQLValueEx(null,
"SELECT t.AD_Table_ID " +
"FROM AD_Tab tab JOIN AD_Table t ON t.AD_Table_ID=tab.AD_Table_ID " +
@ -125,45 +131,49 @@ public class MZoomCondition extends X_AD_ZoomCondition
if (tableName != null && tableName.equals(query.getZoomTableName())) {
return findZoomWindowByTableId(tableID, query);
} else {
GridWindow window = GridWindow.get(Env.getCtx(), -1, AD_Window_ID);
if (window == null || window.getTabCount() == 0)
return 0;
//resolve zoom to detail
int size = window.getTabCount();
GridTab gTab = null;
for(int i = 0; i < size; i++)
{
if (window.getTab(i).getTableName().equals(query.getZoomTableName()))
try {
GridWindow window = GridWindow.get(Env.getCtx(), -1, AD_Window_ID);
if (window == null || window.getTabCount() == 0)
return 0;
//resolve zoom to detail
int size = window.getTabCount();
GridTab gTab = null;
for(int i = 0; i < size; i++)
{
gTab = window.getTab(i);
break;
}
}
if (gTab != null)
{
window.initTab(gTab.getTabNo());
GridTab parentTab = gTab.getParentTab();
int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
if (parentId <= 0)return 0;
while (parentTab != null)
{
window.initTab(parentTab.getTabNo());
if (parentTab.getParentTab() != null)
if (window.getTab(i).getTableName().equals(query.getZoomTableName()))
{
parentId = DB.getSQLValue(null, "SELECT " + parentTab.getLinkColumnName() + " FROM " + parentTab.getTableName() + " WHERE "
+ parentTab.getTableName()+"_ID="+parentId);
if (parentId <= 0) return 0;
parentTab = parentTab.getParentTab();
gTab = window.getTab(i);
break;
}
else
{
if (parentTab == window.getTab(0))
}
if (gTab != null)
{
window.initTab(gTab.getTabNo());
GridTab parentTab = gTab.getParentTab();
int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
if (parentId <= 0)return 0;
while (parentTab != null)
{
window.initTab(parentTab.getTabNo());
if (parentTab.getParentTab() != null)
{
return findZoomWindowByTableId(parentTab.getAD_Table_ID(), parentId);
parentId = DB.getSQLValue(null, "SELECT " + parentTab.getLinkColumnName() + " FROM " + parentTab.getTableName() + " WHERE "
+ parentTab.getTableName()+"_ID="+parentId);
if (parentId <= 0) return 0;
parentTab = parentTab.getParentTab();
}
else
{
if (parentTab == window.getTab(0))
{
return findZoomWindowByTableId(parentTab.getAD_Table_ID(), parentId);
}
}
}
}
} finally {
Env.clearWinContext(-1);
}
}
return 0;

View File

@ -387,10 +387,19 @@ public final class AEnv
zoomQuery.setRecordCount(1); // guess
}
int windowId = lookup.getZoom(zoomQuery);
int zoomId = MZoomCondition.findZoomWindowByWindowId(windowId, zoomQuery);
zoom(zoomId > 0 ? zoomId : windowId, zoomQuery);
zoom(windowId, zoomQuery);
}
/**
* open zoom window with query
* @param AD_Window_ID
* @param query
*/
public static void showZoomWindow(int AD_Window_ID, MQuery query)
{
SessionManager.getAppDesktop().showZoomWindow(AD_Window_ID, query);
}
/**
* Zoom to a window with the provided window id and filters according to the
* query
@ -399,7 +408,8 @@ public final class AEnv
*/
public static void zoom(int AD_Window_ID, MQuery query)
{
SessionManager.getAppDesktop().showZoomWindow(AD_Window_ID, query);
int zoomId = MZoomCondition.findZoomWindowByWindowId(AD_Window_ID, query);
showZoomWindow(zoomId > 0 ? zoomId : AD_Window_ID, query);
}
public static void showWindow(Window win)
@ -421,7 +431,7 @@ public final class AEnv
if (AD_Window_ID == 0)
return;
zoom(AD_Window_ID, query);
showZoomWindow(AD_Window_ID, query);
}
/**

View File

@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.ListItem;
@ -33,9 +32,7 @@ import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.theme.ThemeManager;
import org.compiere.apps.wf.WFGraphLayout;
import org.compiere.apps.wf.WFNodeWidget;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
@ -445,15 +442,7 @@ public class WFEditor extends ADForm {
private void zoom()
{
if (m_workflowId > 0) {
int AD_Window_ID = MTable.get(Env.getCtx(), MWorkflow.Table_ID).getAD_Window_ID();
if (AD_Window_ID <= 0) {
throw new AdempiereException("@NotFound@ @AD_Window_ID@");
}
MQuery query = null;
query = MQuery.getEqualQuery("AD_Workflow_ID", m_workflowId);
AEnv.zoom(AD_Window_ID, query);
AEnv.zoom(MWorkflow.Table_ID, m_workflowId);
}
} // zoom