IDEMPIERE-242 ImageField not working in non form based print format

Found that a350b4d51f50 broke the gardenworld invoice sample (pointing to M_Product.ImageURL) - refactored the layoutTable
This commit is contained in:
Carlos Ruiz 2012-05-30 11:55:14 -05:00
parent f55f7e0e66
commit 5be12ca9cd
2 changed files with 17 additions and 59 deletions

View File

@ -102,16 +102,19 @@ public class ImageElement extends PrintElement
*/ */
public static ImageElement get(PrintDataElement data, String imageURLString) public static ImageElement get(PrintDataElement data, String imageURLString)
{ {
Object key = (BigDecimal) data.getValue(); BigDecimal imkeybd = null;
ImageElement image = (ImageElement)s_cache.get(key); if (data.getValue() instanceof Integer)
imkeybd = BigDecimal.valueOf((Integer) data.getValue());
else
imkeybd = (BigDecimal) data.getValue();
ImageElement image = (ImageElement)s_cache.get(imkeybd);
if (image == null) if (image == null)
{ {
BigDecimal imkeybd = (BigDecimal) data.getValue();
int imkeyint = 0; int imkeyint = 0;
if (imkeybd != null) if (imkeybd != null)
imkeyint = imkeybd.intValue(); imkeyint = imkeybd.intValue();
image = new ImageElement(imkeyint, false); image = new ImageElement(imkeyint, false);
s_cache.put(key, image); s_cache.put(imkeybd, image);
} }
return new ImageElement(image.getImage()); return new ImageElement(image.getImage());
} // get } // get

View File

@ -1077,7 +1077,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
} }
else if (item.isBarcode()) else if (item.isBarcode())
{ {
element = createBarcodeElement(item); element = createBarcodeElement(item, m_data);
if (element != null) if (element != null)
{ {
element.layout(maxWidth, item.getMaxHeight(), false, alignment); element.layout(maxWidth, item.getMaxHeight(), false, alignment);
@ -1086,7 +1086,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
else if (item.isTypeImage()) //** Image else if (item.isTypeImage()) //** Image
{ {
if (item.isImageField()) if (item.isImageField())
element = createImageElement (item); element = createImageElement (item, m_data);
else if (item.isImageIsAttached()) else if (item.isImageIsAttached())
element = ImageElement.get (item.get_ID()); element = ImageElement.get (item.get_ID());
else else
@ -1440,9 +1440,9 @@ public class LayoutEngine implements Pageable, Printable, Doc
* @param item item * @param item item
* @return image element * @return image element
*/ */
private PrintElement createImageElement (MPrintFormatItem item) private PrintElement createImageElement (MPrintFormatItem item, PrintData printData)
{ {
Object obj = m_data.getNode(new Integer(item.getAD_Column_ID())); Object obj = printData.getNode(new Integer(item.getAD_Column_ID()));
if (obj == null) if (obj == null)
return null; return null;
else if (obj instanceof PrintDataElement) else if (obj instanceof PrintDataElement)
@ -1478,10 +1478,10 @@ public class LayoutEngine implements Pageable, Printable, Doc
* @param item item * @param item item
* @return barcode element * @return barcode element
*/ */
private PrintElement createBarcodeElement (MPrintFormatItem item) private PrintElement createBarcodeElement (MPrintFormatItem item, PrintData printData)
{ {
// Get Data // Get Data
Object obj = m_data.getNode(new Integer(item.getAD_Column_ID())); Object obj = printData.getNode(new Integer(item.getAD_Column_ID()));
if (obj == null) if (obj == null)
return null; return null;
else if (obj instanceof PrintDataElement) else if (obj instanceof PrintDataElement)
@ -1678,64 +1678,19 @@ public class LayoutEngine implements Pageable, Printable, Doc
if (item.isTypeImage()) if (item.isTypeImage())
{ {
if (item.isImageField()) if (item.isImageField())
{ data[row][col] = createImageElement (item, printData);
Object obj = null;
if (item.getAD_Column_ID() > 0) // teo_sarca, [ 1673542 ]
obj = printData.getNode(new Integer(item.getAD_Column_ID()));
if (obj == null)
;
else if (obj instanceof PrintDataElement)
{
PrintDataElement pde = (PrintDataElement)obj;
// Get the PrintDataElement string value - teo_sarca [ 1673505 ]
Object o = pde.getValue();
String value = null;
if (o == null)
value = "";
else if (o instanceof KeyNamePair)
value = ((KeyNamePair)o).getName();
else
value = o.toString();
data[row][col] = ImageElement.get (pde, value);
}
}
else if (item.isImageIsAttached()) else if (item.isImageIsAttached())
data[row][col] = ImageElement.get (item.get_ID()); data[row][col] = ImageElement.get (item.get_ID());
else else
data[row][col] = ImageElement.get (item.getImageURL()); data[row][col] = ImageElement.get (item.getImageURL());
// Image layout - teo_sarca, [ 1673548 ]
if (data[row][col] != null) if (data[row][col] != null)
((ImageElement)data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType()); ((PrintElement)data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
} }
else if (item.isBarcode()) else if (item.isBarcode())
{ {
Object obj = null; data[row][col] = createBarcodeElement(item, printData);
if (item.getAD_Column_ID() > 0) // teo_sarca, [ 1673542 ]
obj = printData.getNode(new Integer(item.getAD_Column_ID()));
if (obj == null)
;
else if (obj instanceof PrintDataElement)
{
PrintDataElement pde = (PrintDataElement)obj;
// Get the PrintDataElement string value - teo_sarca [ 1673505 ]
String value = null;
Object o = pde.getValue();
if (o == null)
value = "";
if (o instanceof KeyNamePair)
value = ((KeyNamePair)o).getID();
else
value = o.toString();
BarcodeElement element = new BarcodeElement (value, item);
if (element.isValid())
data[row][col] = element;
}
if (data[row][col] != null) if (data[row][col] != null)
((BarcodeElement)data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType()); ((PrintElement)data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
} }
else if (item.isTypeText() ) else if (item.isTypeText() )
{ {