From 6aa16930d25d8a9fb40ff741c849ac8397a112a7 Mon Sep 17 00:00:00 2001 From: hieplq Date: Tue, 7 Jul 2015 22:06:23 +0700 Subject: [PATCH] IDEMPIERE-2479:Printformat, Surpress Repeats doesnt works for HTML and XLS some time m_layout is null example when call report from report button at standart window --- .../adempiere/impexp/AbstractExcelExporter.java | 2 +- .../print/export/PrintDataExcelExporter.java | 2 +- .../src/org/compiere/print/ReportEngine.java | 17 ++++++++++------- .../org/compiere/print/layout/LayoutEngine.java | 17 +++++++++++++++-- .../org/compiere/print/layout/TableElement.java | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java index 153dfe3c1c..3e39c0f8a5 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java @@ -131,7 +131,7 @@ public abstract class AbstractExcelExporter /** Styles cache */ private HashMap m_styles = new HashMap(); - protected boolean[] colSuppressRepeats; + protected Boolean[] colSuppressRepeats; public AbstractExcelExporter() { m_workbook = new HSSFWorkbook(); diff --git a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java index 742c44af61..c77de78b27 100644 --- a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java @@ -39,7 +39,7 @@ extends AbstractExcelExporter private PrintData m_printData; private MPrintFormat m_printFormat; - public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, boolean[] colSuppressRepeats) { + public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Boolean[] colSuppressRepeats) { super(); this.m_printData = printData; this.m_printFormat = printFormat; diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 1b14b66f71..079afc9909 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -629,7 +629,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) thead thead = new thead(); tbody tbody = new tbody(); - Object [] preValues = new Object [m_layout.colSuppressRepeats.length]; + Boolean [] colSuppressRepeats = m_layout == null ? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; + Object [] preValues = new Object [colSuppressRepeats.length]; int printColIndex = -1; // for all rows (-1 = header row) for (int row = -1; row < m_printData.getRowCount(); row++) @@ -687,7 +688,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) Object obj = m_printData.getNode(new Integer(item.getAD_Column_ID())); if (obj == null){ td.addElement(" "); - if (m_layout.colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; } } @@ -696,7 +697,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) PrintDataElement pde = (PrintDataElement) obj; String value = pde.getValueDisplay(language); // formatted - if (m_layout.colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats[printColIndex]){ if (value.equals(preValues[printColIndex])){ td.addElement(" "); continue; @@ -898,7 +899,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) delimiter = '\t'; try { - Object [] preValues = new Object [m_layout.colSuppressRepeats.length]; + Boolean [] colSuppressRepeats = m_layout == null ? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; + Object [] preValues = new Object [colSuppressRepeats.length]; int printColIndex = -1; // for all rows (-1 = header row) for (int row = -1; row < m_printData.getRowCount(); row++) @@ -930,7 +932,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) Object obj = m_printData.getNode(new Integer(item.getAD_Column_ID())); String data = ""; if (obj == null){ - if (m_layout.colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; } } @@ -942,7 +944,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) else data = pde.getValueDisplay(language); // formatted - if (m_layout.colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats[printColIndex]){ if (data.equals(preValues[printColIndex])){ continue; }else{ @@ -1229,7 +1231,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) public void createXLS(File outFile, Language language) throws Exception { - PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), m_layout.colSuppressRepeats); + Boolean [] colSuppressRepeats = m_layout == null ? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; + PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), colSuppressRepeats); exp.export(outFile, language); } diff --git a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java index 429b91a145..96f4611414 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java +++ b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java @@ -40,6 +40,7 @@ import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -225,7 +226,7 @@ public class LayoutEngine implements Pageable, Printable, Doc /** Image Size */ public static Dimension IMAGE_SIZE = new Dimension(10,10); - public boolean[] colSuppressRepeats; + public Boolean[] colSuppressRepeats; static { Toolkit tk = Toolkit.getDefaultToolkit(); @@ -1605,7 +1606,7 @@ public class LayoutEngine implements Pageable, Printable, Doc int[] columnMaxWidth = new int[columnCount]; int[] columnMaxHeight = new int[columnCount]; boolean[] fixedWidth = new boolean [columnCount]; - colSuppressRepeats = new boolean[columnCount]; + colSuppressRepeats = new Boolean[columnCount]; String[] columnJustification = new String[columnCount]; HashMap additionalLines = new HashMap(); @@ -1973,4 +1974,16 @@ public class LayoutEngine implements Pageable, Printable, Doc return m_PrintInfo; } + public static Boolean [] getColSuppressRepeats (MPrintFormat format){ + List colSuppressRepeats = new ArrayList<>(); + for (int c = 0; c < format.getItemCount(); c++) + { + MPrintFormatItem item = format.getItem(c); + if (item.isPrinted()) + { + colSuppressRepeats.add(item.isSuppressRepeats()); + } + } + return colSuppressRepeats.toArray(new Boolean[0]); + } } // LayoutEngine diff --git a/org.adempiere.base/src/org/compiere/print/layout/TableElement.java b/org.adempiere.base/src/org/compiere/print/layout/TableElement.java index 3b9dc00cc9..393bc8e825 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/TableElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/TableElement.java @@ -120,7 +120,7 @@ public class TableElement extends PrintElement SerializableMatrix data, KeyNamePair[] pk, String pkColumnName, int pageNoStart, Rectangle firstPage, Rectangle nextPages, int repeatedColumns, HashMap additionalLines, HashMap rowColFont, HashMap rowColColor, HashMap rowColBackground, - MPrintTableFormat tFormat, ArrayList pageBreak, boolean[] colSuppressRepeats) + MPrintTableFormat tFormat, ArrayList pageBreak, Boolean[] colSuppressRepeats) { super(); if (log.isLoggable(Level.FINE)) @@ -212,7 +212,7 @@ public class TableElement extends PrintElement /** Bounds of next Pages */ private Rectangle m_nextPages; - private boolean[] m_colSuppressRepeats; + private Boolean[] m_colSuppressRepeats; /** repeat first x columns on - X Axis follow pages */ private int m_repeatedColumns;