From 6f3d96910c49d137f9889497552ed97436e7c5c0 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 15 Feb 2013 15:52:52 +0800 Subject: [PATCH] IDEMPIERE-325 Complete AD based info window ( AD_InfoWindow ) implementation. Fixed IndexedOutOfBoundsException. Fixed paging and user ordering. --- .../org/adempiere/webui/info/InfoWindow.java | 64 ++++++++++++++++++- .../org/adempiere/webui/panel/InfoPanel.java | 19 +++++- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java index 821af7e7f5..aad5d841b7 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java @@ -4,6 +4,7 @@ package org.adempiere.webui.info; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; @@ -385,7 +386,6 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL .append(" ?"); } } - System.out.println(builder.toString()); return builder.toString(); } @@ -448,7 +448,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL if (infoWindow.isDistinct()) { m_sqlMain = m_sqlMain.substring("SELECT ".length()); - m_sqlMain = "SELECT DISTINCT " + m_sqlMain; + m_sqlMain = "SELECT DISTINCT " + m_sqlMain; } if (m_sqlOrder != null && m_sqlOrder.indexOf("@") >= 0) { @@ -504,6 +504,11 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL southBody.appendChild(statusBar); } + protected void insertPagingComponent() { + southBody.insertBefore(paging, southBody.getFirstChild()); + layout.invalidate(); + } + protected void renderContentPane(Center center) { Div div = new Div(); div.setStyle("width :100%; height: 100%"); @@ -859,4 +864,59 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL } } } + + /** + * Test Row Count + * @return true if display + */ + protected boolean testCount() + { + long start = System.currentTimeMillis(); + String dynWhere = getSQLWhere(); + StringBuilder sql = new StringBuilder (m_sqlMain); + + if (dynWhere.length() > 0) + sql.append(dynWhere); // includes first AND + + String countSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // Variables + if (countSql.trim().endsWith("WHERE")) { + countSql = countSql.trim(); + countSql = countSql.substring(0, countSql.length() - 5); + } + countSql = MRole.getDefault().addAccessSQL (countSql, getTableName(), + MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); + + countSql = "SELECT COUNT(*) FROM ( " + countSql + " ) a"; + + if (log.isLoggable(Level.FINER)) + log.finer(countSql); + m_count = -1; + + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(countSql, null); + setParameters (pstmt, true); + rs = pstmt.executeQuery(); + + if (rs.next()) + m_count = rs.getInt(1); + + } + catch (Exception e) + { + log.log(Level.SEVERE, countSql, e); + m_count = -2; + } + finally + { + DB.close(rs, pstmt); + } + + if (log.isLoggable(Level.FINE)) + log.fine("#" + m_count + " - " + (System.currentTimeMillis()-start) + "ms"); + + return true; + } // testCount } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java index d32bf9892d..429979282a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java @@ -362,7 +362,7 @@ public abstract class InfoPanel extends Window implements EventListener, /** Main SQL Statement */ protected String m_sqlMain; /** Count SQL Statement */ - private String m_sqlCount; + protected String m_sqlCount; /** Order By Clause */ protected String m_sqlOrder; protected String m_sqlUserOrder; @@ -432,7 +432,7 @@ public abstract class InfoPanel extends Window implements EventListener, m_sqlCount = "SELECT COUNT(*) FROM " + from + " WHERE " + where; // m_sqlOrder = ""; - m_sqlUserOrder = ""; +// m_sqlUserOrder = ""; if (orderBy != null && orderBy.length() > 0) m_sqlOrder = " ORDER BY " + orderBy; } // prepareTable @@ -686,7 +686,19 @@ public abstract class InfoPanel extends Window implements EventListener, { end = cacheEnd-1; } - return line.subList(start, end+1); + + if (end == -1) + { + return line; + } + else + { + int fromIndex = start-getCacheStart()+1; + int toIndex = end-getCacheStart()+2; + if (toIndex > line.size()) + toIndex = line.size(); + return line.subList(fromIndex, toIndex); + } } protected String buildDataSQL(int start, int end) { @@ -1215,6 +1227,7 @@ public abstract class InfoPanel extends Window implements EventListener, header.setSortDirection("natural"); } } + m_sqlUserOrder=""; executeQuery(); renderItems(); }