From b8379d15beb973dba1495a88f7a555f7fd1ca99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:19:55 +0200 Subject: [PATCH] IDEMPIERE-5889 - Cannot Open Lookup Info Window if no Window is Defined for the Table (#2070) * IDEMPIERE-5889 - Cannot Open Lookup Info Window if no Window is Defined for the Table * IDEMPIERE-5889 - expand displayed columns' where clause according to Heng Sin * IDEMPIERE-5889 - add aliases to displayed columns' where clause --- .../webui/panel/InfoGeneralPanel.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java index f1087045f5..694850a05b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java @@ -43,8 +43,10 @@ import org.compiere.model.I_C_ElementValue; import org.compiere.model.MColumn; import org.compiere.model.MLookupFactory; import org.compiere.model.MReference; +import org.compiere.model.MTab; import org.compiere.model.MTable; import org.compiere.model.PO; +import org.compiere.model.Query; import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; @@ -394,18 +396,23 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener { MTable table = MTable.get(Env.getCtx(), p_tableName); String uucolName = PO.getUUIDColumnName(p_tableName); + boolean hasWindowAndTab = new Query(Env.getCtx(), MTab.Table_Name, " AD_Table_ID = ? ", null) + .setParameters(table.getAD_Table_ID()) + .match(); // Get Query Columns - final String sqlqc = "SELECT c.ColumnName, t.AD_Table_ID, t.TableName, c.ColumnSql " + String sqlqc = "SELECT c.ColumnName, t.AD_Table_ID, t.TableName, c.ColumnSql " + "FROM AD_Table t" + " INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID)" + "WHERE c.AD_Reference_ID IN (10,14)" - + " AND t.TableName=?" // #1 + + " AND t.TableName=? "; // #1 + if(hasWindowAndTab) { // Displayed in Window - + " AND EXISTS (SELECT * FROM AD_Field f " - + "WHERE f.AD_Column_ID=c.AD_Column_ID" - + " AND f.IsDisplayed='Y' AND f.IsEncrypted='N' AND f.ObscureType IS NULL) " - + "ORDER BY c.IsIdentifier DESC, c.IsSelectionColumn Desc, c.AD_Reference_ID, c.SeqNoSelection, c.SeqNo"; + sqlqc += " AND EXISTS (SELECT * FROM AD_Field f " + + " WHERE f.AD_Column_ID=c.AD_Column_ID " + + " AND f.IsDisplayed='Y' AND f.IsEncrypted='N' AND f.ObscureType IS NULL) "; + } + sqlqc += " ORDER BY c.IsIdentifier DESC, c.IsSelectionColumn Desc, c.AD_Reference_ID, c.SeqNoSelection, c.SeqNo"; int AD_Table_ID = 0; String tableName = null; @@ -490,29 +497,49 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener } ArrayList list = new ArrayList(); StringBuilder sqlc = new StringBuilder().append( - "SELECT c.ColumnName, c.AD_Reference_ID, c.IsKey, f.IsDisplayed, c.AD_Reference_Value_ID, c.ColumnSql, c.AD_Column_ID " + "SELECT c.ColumnName, c.AD_Reference_ID, c.IsKey, "); // 1-3 + if(hasWindowAndTab) { // 4 + sqlc.append(" f.IsDisplayed, "); + } else { + sqlc.append(" 'Y', "); + } + sqlc.append(" c.AD_Reference_Value_ID, c.ColumnSql, c.AD_Column_ID " // 5-7 + "FROM AD_Column c" - + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID)" - + " INNER JOIN AD_Tab tab ON (t.AD_Table_ID=tab.AD_Table_ID)" - + " INNER JOIN AD_Field f ON (tab.AD_Tab_ID=f.AD_Tab_ID AND f.AD_Column_ID=c.AD_Column_ID) " - + "WHERE t.AD_Table_ID=? " - + " AND tab.IsSortTab='N'" - + " AND tab.Ad_Tab_ID=(SELECT MIN(mt.AD_Tab_ID) FROM AD_tab mt WHERE mt.AD_Window_ID=? AND mt.AD_Table_ID=t.AD_Table_ID AND mt.IsActive='Y')" - + " AND (c.IsKey='Y' OR " - + " (f.IsEncrypted='N' AND f.ObscureType IS NULL)) " - + " AND c.IsActive = 'Y' " + + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID)"); + if(hasWindowAndTab) { + sqlc.append(" INNER JOIN AD_Tab tab ON (t.AD_Table_ID=tab.AD_Table_ID)" + + " INNER JOIN AD_Field f ON (tab.AD_Tab_ID=f.AD_Tab_ID AND f.AD_Column_ID=c.AD_Column_ID) "); + } + sqlc.append( "WHERE t.AD_Table_ID=? "); + if(hasWindowAndTab) { + sqlc.append(" AND tab.IsSortTab='N' " + + " AND tab.Ad_Tab_ID=(SELECT MIN(mt.AD_Tab_ID) FROM AD_tab mt WHERE mt.AD_Window_ID=? AND mt.AD_Table_ID=t.AD_Table_ID AND mt.IsActive='Y')" + + " AND (c.IsKey='Y' OR " + + " (f.IsEncrypted='N' AND f.ObscureType IS NULL))"); + } else { + sqlc.append(" AND (c.IsKey='Y' " + + " OR c.IsIdentifier='Y' " + + " OR c.IsParent='Y' " + + " OR c.IsSelectionColumn='Y' " + + " OR Upper(c.ColumnName) IN ('NAME','VALUE','DESCRIPTION','DOCUMENTNO') " + + " OR Upper(c.ColumnName) Like '%_NAME' " + + " OR Upper(c.ColumnName) Like '%_Value') "); + } + sqlc.append(" AND c.IsActive = 'Y' " + "ORDER BY "); if (table.isUUIDKeyTable() || p_keyColumn.endsWith("_UU")) sqlc.append("CASE WHEN c.columnname=").append(DB.TO_STRING(uucolName)).append("THEN 0 ELSE 1 END"); else sqlc.append("c.IsKey DESC"); - sqlc.append(", f.SeqNo"); + if(hasWindowAndTab) + sqlc.append(", f.SeqNo"); try { pstmt = DB.prepareStatement(sqlc.toString(), null); pstmt.setInt(1, AD_Table_ID); - pstmt.setInt(2, AD_Window_ID); + if(hasWindowAndTab) + pstmt.setInt(2, AD_Window_ID); rs = pstmt.executeQuery(); boolean keyDefined = false; while (rs.next())