diff --git a/client/src/org/compiere/apps/search/Info.java b/client/src/org/compiere/apps/search/Info.java index ceb475a4e1..45c6bfe677 100644 --- a/client/src/org/compiere/apps/search/Info.java +++ b/client/src/org/compiere/apps/search/Info.java @@ -423,6 +423,7 @@ public abstract class Info extends CDialog p_table.setRowSelectionAllowed(true); p_table.addMouseListener(this); p_table.setMultiSelection(p_multiSelection); + p_table.setShowTotals(true); // set editors (two steps) for (int i = 0; i < layout.length; i++) @@ -1088,6 +1089,8 @@ public abstract class Info extends CDialog // int no = p_table.getRowCount(); log.fine("#" + no + " - " + (System.currentTimeMillis()-start) + "ms"); + if(p_table.getShowTotals()) + p_table.addTotals(p_layout); p_table.autoSize(); // setCursor(Cursor.getDefaultCursor()); diff --git a/client/src/org/compiere/apps/search/InfoProduct.java b/client/src/org/compiere/apps/search/InfoProduct.java index f5caa8a0a9..6ff7109ff5 100644 --- a/client/src/org/compiere/apps/search/InfoProduct.java +++ b/client/src/org/compiere/apps/search/InfoProduct.java @@ -228,6 +228,7 @@ public final class InfoProduct extends Info implements ActionListener warehouseTbl.setMultiSelection(false); warehouseTbl.addMouseListener(this); warehouseTbl.getSelectionModel().addListSelectionListener(this); + warehouseTbl.setShowTotals(true); warehouseTbl.autoSize(); ColumnInfo[] s_layoutSubstitute = new ColumnInfo[]{ diff --git a/client/src/org/compiere/minigrid/MiniTable.java b/client/src/org/compiere/minigrid/MiniTable.java index 3d50e63c1c..7e6c62f439 100644 --- a/client/src/org/compiere/minigrid/MiniTable.java +++ b/client/src/org/compiere/minigrid/MiniTable.java @@ -23,6 +23,8 @@ import java.util.*; import java.util.logging.*; import javax.swing.*; import javax.swing.table.*; + +import org.compiere.apps.search.Info_Column; import org.compiere.grid.ed.*; import org.compiere.model.*; import org.compiere.swing.*; @@ -79,7 +81,9 @@ public class MiniTable extends CTable /** Lauout set in prepareTable and used in loadTable */ private ColumnInfo[] m_layout = null; /** Logger */ - private static CLogger log = CLogger.getCLogger(MiniTable.class); + private static CLogger log = CLogger.getCLogger(MiniTable.class); + /** Is Total Show */ + private boolean showTotals = false; /** * Size Columns. @@ -468,15 +472,21 @@ public class MiniTable extends CTable setValueAt(data, row, col); // log.fine( "r=" + row + ", c=" + col + " " + m_layout[col].getColHeader(), // "data=" + data.toString() + " " + data.getClass().getName() + " * " + m_table.getCellRenderer(row, col)); - } + } + + } } catch (SQLException e) { log.log(Level.SEVERE, "", e); - } + } + if(getShowTotals()) + addTotals(m_layout); autoSize(); - log.config("Row(rs)=" + getRowCount()); + log.config("Row(rs)=" + getRowCount()); + + } // loadTable /** @@ -512,7 +522,9 @@ public class MiniTable extends CTable // store setValueAt(data, row, col); } - } + } + if(getShowTotals()) + addTotals(m_layout); autoSize(); log.config("Row(array)=" + getRowCount()); } // loadTable @@ -634,6 +646,181 @@ public class MiniTable extends CTable if (cmp < 0) return 1; return 0; - } // getColorCode - + } // getColorCode + + + /** + * Set if Totals is Show + * @param boolean Show + */ + public void setShowTotals(boolean show) + { + showTotals= show; + } + /** + * get if Totals is Show + * @param boolean Show + */ + public boolean getShowTotals() + { + return showTotals; + } + + /** + * Adding a new row with the totals + */ + public void addTotals(ColumnInfo[] layout) + { + if (getRowCount() == 0 || layout.length == 0) + return; + + Object[] total = new Object[layout.length]; + + for (int row = 0 ; row < getRowCount(); row ++) + { + + int colOffset = 1; // columns start with 1 + for (int col = 0; col < layout.length; col++) + { + Object data = getModel().getValueAt(row, col); + Class c = layout[col].getColClass(); + int colIndex = col + colOffset; + if (c == BigDecimal.class) + { + BigDecimal subtotal = Env.ZERO; + if(total[col]!= null) + subtotal = (BigDecimal)(total[col]); + + BigDecimal amt = (BigDecimal) data; + if(subtotal == null) + subtotal = Env.ZERO; + if(amt == null ) + amt = Env.ZERO; + total[col] = subtotal.add(amt); + } + else if (c == Double.class) + { + Double subtotal = new Double(0); + if(total[col] != null) + subtotal = (Double)(total[col]); + + Double amt = (Double) data; + if(subtotal == null) + subtotal = new Double(0); + if(amt == null ) + subtotal = new Double(0); + total[col] = subtotal + amt; + + } + } + } + + //adding total row + + int row = getRowCount() + 1; + setRowCount(row); + int colOffset = 1; // columns start with 1 + for (int col = 0; col < layout.length; col++) + { + Class c = layout[col].getColClass(); + int colIndex = col + colOffset; + if (c == BigDecimal.class) + { + setValueAt(total[col] , row - 1, col); + } + else if (c == Double.class) + { + setValueAt(total[col] , row -1 , col); + } + else + { + if(col == 0 ) + { + setValueAt(" Σ " , row -1 , col); + } + else + setValueAt(null , row - 1, col ); + } + + } + } + + /** + * Adding a new row with the totals + */ + public void addTotals(Info_Column[] layout) + { + if (getRowCount() == 0 || layout.length == 0) + return; + + Object[] total = new Object[layout.length]; + + for (int row = 0 ; row < getRowCount(); row ++) + { + + int colOffset = 1; // columns start with 1 + for (int col = 0; col < layout.length; col++) + { + Object data = getModel().getValueAt(row, col); + Class c = layout[col].getColClass(); + int colIndex = col + colOffset; + if (c == BigDecimal.class) + { + BigDecimal subtotal = Env.ZERO; + if(total[col]!= null) + subtotal = (BigDecimal)(total[col]); + + BigDecimal amt = (BigDecimal) data; + if(subtotal == null) + subtotal = Env.ZERO; + if(amt == null ) + amt = Env.ZERO; + total[col] = subtotal.add(amt); + } + else if (c == Double.class) + { + Double subtotal = new Double(0); + if(total[col] != null) + subtotal = (Double)(total[col]); + + Double amt = (Double) data; + if(subtotal == null) + subtotal = new Double(0); + if(amt == null ) + subtotal = new Double(0); + total[col] = subtotal + amt; + + } + } + } + + //adding total row + + int row = getRowCount() + 1; + setRowCount(row); + int colOffset = 1; // columns start with 1 + for (int col = 0; col < layout.length; col++) + { + Class c = layout[col].getColClass(); + int colIndex = col + colOffset; + if (c == BigDecimal.class) + { + setValueAt(total[col] , row - 1, col); + } + else if (c == Double.class) + { + setValueAt(total[col] , row -1 , col); + } + else + { + if(col == 1 ) + { + setValueAt(" Σ " , row -1 , col); + } + else + setValueAt(null , row - 1, col ); + } + + } + } } // MiniTable