IDEMPIERE-2479 fix a problem with switching from columnnary reports to form back and forth - index out of bounds - suppresscolumns is just intended for columnnary reports

This commit is contained in:
Carlos Ruiz 2019-05-18 12:54:37 +02:00
parent c4d6e259b2
commit ba13d8584e
3 changed files with 23 additions and 9 deletions

View File

@ -21,6 +21,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import com.itextpdf.text.FontFactory; import com.itextpdf.text.FontFactory;
@ -86,7 +87,7 @@ public class Document {
document.close(); document.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new AdempiereException(e);
} }
} }
@ -96,7 +97,7 @@ public class Document {
try { try {
writePDF(pageable, new FileOutputStream(result)); writePDF(pageable, new FileOutputStream(result));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new AdempiereException(e);
} }
return result; return result;

View File

@ -60,6 +60,7 @@ import javax.print.event.PrintServiceAttributeEvent;
import javax.print.event.PrintServiceAttributeListener; import javax.print.event.PrintServiceAttributeListener;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pdf.Document; import org.adempiere.pdf.Document;
import org.adempiere.print.export.PrintDataExcelExporter; import org.adempiere.print.export.PrintDataExcelExporter;
import org.apache.ecs.XhtmlDocument; import org.apache.ecs.XhtmlDocument;
@ -578,6 +579,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "(f)", e); log.log(Level.SEVERE, "(f)", e);
throw new AdempiereException(e);
} }
return false; return false;
} // createHTML } // createHTML
@ -674,7 +676,11 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
tbody.setNeedClosingTag(false); tbody.setNeedClosingTag(false);
Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats;
Object [] preValues = new Object [colSuppressRepeats.length]; Object [] preValues = null;
if (colSuppressRepeats != null){
preValues = new Object [colSuppressRepeats.length];
}
int printColIndex = -1; int printColIndex = -1;
// for all rows (-1 = header row) // for all rows (-1 = header row)
for (int row = -1; row < m_printData.getRowCount(); row++) for (int row = -1; row < m_printData.getRowCount(); row++)
@ -732,7 +738,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID()));
if (obj == null){ if (obj == null){
td.addElement("&nbsp;"); td.addElement("&nbsp;");
if (colSuppressRepeats[printColIndex]){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){
preValues[printColIndex] = null; preValues[printColIndex] = null;
} }
} }
@ -741,7 +747,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
PrintDataElement pde = (PrintDataElement) obj; PrintDataElement pde = (PrintDataElement) obj;
String value = pde.getValueDisplay(language); // formatted String value = pde.getValueDisplay(language); // formatted
if (colSuppressRepeats[printColIndex]){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){
if (value.equals(preValues[printColIndex])){ if (value.equals(preValues[printColIndex])){
td.addElement("&nbsp;"); td.addElement("&nbsp;");
continue; continue;
@ -858,6 +864,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "(w)", e); log.log(Level.SEVERE, "(w)", e);
throw new AdempiereException(e);
} }
return false; return false;
} // createHTML } // createHTML
@ -916,7 +923,10 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
try try
{ {
Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats;
Object [] preValues = new Object [colSuppressRepeats.length]; Object [] preValues = null;
if (colSuppressRepeats != null){
preValues = new Object [colSuppressRepeats.length];
}
int printColIndex = -1; int printColIndex = -1;
// for all rows (-1 = header row) // for all rows (-1 = header row)
for (int row = -1; row < m_printData.getRowCount(); row++) for (int row = -1; row < m_printData.getRowCount(); row++)
@ -948,7 +958,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID()));
String data = ""; String data = "";
if (obj == null){ if (obj == null){
if (colSuppressRepeats[printColIndex]){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){
preValues[printColIndex] = null; preValues[printColIndex] = null;
} }
} }
@ -960,7 +970,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
else else
data = pde.getValueDisplay(language); // formatted data = pde.getValueDisplay(language); // formatted
if (colSuppressRepeats[printColIndex]){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){
if (data.equals(preValues[printColIndex])){ if (data.equals(preValues[printColIndex])){
continue; continue;
}else{ }else{
@ -1149,7 +1159,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "PDF", e); log.log(Level.SEVERE, "PDF", e);
return false; throw new AdempiereException(e);
} }
File file2 = new File(fileName); File file2 = new File(fileName);

View File

@ -250,6 +250,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
public void setPrintFormat (MPrintFormat format, boolean doLayout) public void setPrintFormat (MPrintFormat format, boolean doLayout)
{ {
m_format = format; m_format = format;
this.colSuppressRepeats = null;
// Initial & Default Settings // Initial & Default Settings
m_printCtx = new Properties(format.getCtx()); m_printCtx = new Properties(format.getCtx());
@ -1980,6 +1981,8 @@ public class LayoutEngine implements Pageable, Printable, Doc
} }
public static Boolean [] getColSuppressRepeats (MPrintFormat format){ public static Boolean [] getColSuppressRepeats (MPrintFormat format){
if (format.isForm())
return null;
List<Boolean> colSuppressRepeats = new ArrayList<>(); List<Boolean> colSuppressRepeats = new ArrayList<>();
for (int c = 0; c < format.getItemCount(); c++) for (int c = 0; c < format.getItemCount(); c++)
{ {