use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class MLookup method getData.
// getData
/**
* Return data as Array containing Value/KeyNamePair
* @param mandatory if not mandatory, an additional empty value is inserted
* @param onlyValidated only validated
* @param onlyActive only active
* @param temporary force load for temporary display
* @return list
*/
public ArrayList<Object> getData(boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary) {
// create list
ArrayList<Object> list = getData(onlyValidated, true);
// Remove inactive choices
if (onlyActive && m_hasInactive) {
// list from the back
for (int i = list.size(); i > 0; i--) {
Object o = list.get(i - 1);
if (o != null) {
String s = o.toString();
if (s.startsWith(INACTIVE_S) && s.endsWith(INACTIVE_E))
list.remove(i - 1);
}
}
}
// Add Optional (empty) selection
if (!mandatory) {
NamePair p = null;
if (m_info.KeyColumn != null && m_info.KeyColumn.endsWith("_ID"))
p = new KeyNamePair(-1, "");
else
p = new ValueNamePair("", "");
list.add(0, p);
}
return list;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class MLookup method getDirect.
/**
* Get Data Direct from Table.
* @param key key
* @param saveInCache save in cache for r/w
* @param cacheLocal cache locally for r/o
* @return value
*/
public NamePair getDirect(Object key, boolean saveInCache, boolean cacheLocal) {
// Nothing to query
if (key == null || m_info.QueryDirect == null || m_info.QueryDirect.length() == 0)
return null;
if (key.equals(m_directNullKey))
return null;
//
NamePair directValue = null;
if (// Lookup cache
m_lookupDirect != null) {
directValue = (NamePair) m_lookupDirect.get(key);
if (directValue != null)
return directValue;
}
log.finer(m_info.KeyColumn + ": " + key + ", SaveInCache=" + saveInCache + ",Local=" + cacheLocal);
boolean isNumber = m_info.KeyColumn.endsWith("_ID");
try {
// SELECT Key, Value, Name FROM ...
PreparedStatement pstmt = DB.prepareStatement(m_info.QueryDirect, null);
if (isNumber)
pstmt.setInt(1, Integer.parseInt(key.toString()));
else
pstmt.setString(1, key.toString());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
String name = rs.getString(3);
if (isNumber) {
int keyValue = rs.getInt(1);
KeyNamePair p = new KeyNamePair(keyValue, name);
if (// save if
saveInCache)
m_lookup.put(new Integer(keyValue), p);
directValue = p;
} else {
String value = rs.getString(2);
ValueNamePair p = new ValueNamePair(value, name);
if (// save if
saveInCache)
m_lookup.put(value, p);
directValue = p;
}
if (rs.next())
log.log(Level.SEVERE, m_info.KeyColumn + ": Not unique (first returned) for " + key + " SQL=" + m_info.QueryDirect);
} else {
m_directNullKey = key;
directValue = null;
}
rs.close();
pstmt.close();
if (CLogMgt.isLevelFinest())
log.finest(m_info.KeyColumn + ": " + directValue + " - " + m_info);
} catch (Exception e) {
log.log(Level.SEVERE, m_info.KeyColumn + ": SQL=" + m_info.QueryDirect + "; Key=" + key, e);
directValue = null;
}
// Cache Local if not added to R/W cache
if (cacheLocal && !saveInCache && directValue != null) {
if (m_lookupDirect == null)
m_lookupDirect = new HashMap<Object, Object>();
m_lookupDirect.put(key, directValue);
}
m_hasInactive = true;
return directValue;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class LayoutEngine method layoutTable.
// getColor
/**************************************************************************
* Layout Table.
* Convert PrintData into TableElement
* @param format format to use
* @param printData data to use
* @param xOffset X Axis - offset (start of table) i.e. indentation
* @return TableElement
*/
private PrintElement layoutTable(MPrintFormat format, PrintData printData, int xOffset) {
log.info(format.getName() + " - " + printData.getName());
MPrintTableFormat tf = format.getTableFormat();
// Initial Values
HashMap<Point, Font> rowColFont = new HashMap<Point, Font>();
MPrintFont printFont = MPrintFont.get(format.getAD_PrintFont_ID());
rowColFont.put(new Point(TableElement.ALL, TableElement.ALL), printFont.getFont());
tf.setStandard_Font(printFont.getFont());
rowColFont.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeader_Font());
//
HashMap<Point, Color> rowColColor = new HashMap<Point, Color>();
MPrintColor printColor = MPrintColor.get(getCtx(), format.getAD_PrintColor_ID());
rowColColor.put(new Point(TableElement.ALL, TableElement.ALL), printColor.getColor());
rowColColor.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeaderFG_Color());
//
HashMap<Point, Color> rowColBackground = new HashMap<Point, Color>();
rowColBackground.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeaderBG_Color());
// Sizes
boolean multiLineHeader = tf.isMultiLineHeader();
int pageNoStart = m_pageNo;
int repeatedColumns = 1;
Rectangle firstPage = new Rectangle(m_content);
firstPage.x += xOffset;
firstPage.width -= xOffset;
int yOffset = (int) m_position[AREA_CONTENT].y - m_content.y;
firstPage.y += yOffset;
firstPage.height -= yOffset;
Rectangle nextPages = new Rectangle(m_content);
nextPages.x += xOffset;
nextPages.width -= xOffset;
// Column count
int columnCount = 0;
for (int c = 0; c < format.getItemCount(); c++) {
if (format.getItem(c).isPrinted())
columnCount++;
}
// System.out.println("Cols=" + cols);
// Header & Column Setup
ValueNamePair[] columnHeader = new ValueNamePair[columnCount];
int[] columnMaxWidth = new int[columnCount];
int[] columnMaxHeight = new int[columnCount];
boolean[] fixedWidth = new boolean[columnCount];
boolean[] colSuppressRepeats = new boolean[columnCount];
String[] columnJustification = new String[columnCount];
HashMap<Integer, Integer> additionalLines = new HashMap<Integer, Integer>();
int col = 0;
for (int c = 0; c < format.getItemCount(); c++) {
MPrintFormatItem item = format.getItem(c);
if (item.isPrinted()) {
if (item.isNextLine() && item.getBelowColumn() != 0) {
additionalLines.put(new Integer(col), new Integer(item.getBelowColumn() - 1));
if (!item.isSuppressNull()) {
// display size will be set to 0 in TableElement
item.setIsSuppressNull(true);
item.saveEx();
}
}
columnHeader[col] = new ValueNamePair(item.getColumnName(), item.getPrintName(format.getLanguage()));
columnMaxWidth[col] = item.getMaxWidth();
fixedWidth[col] = (columnMaxWidth[col] != 0 && item.isFixedWidth());
colSuppressRepeats[col] = item.isSuppressRepeats();
if (item.isSuppressNull()) {
if (columnMaxWidth[col] == 0)
// indication suppress if Null
columnMaxWidth[col] = -1;
else
columnMaxWidth[col] *= -1;
}
columnMaxHeight[col] = item.getMaxHeight();
if (item.isHeightOneLine())
columnMaxHeight[col] = -1;
columnJustification[col] = item.getFieldAlignmentType();
if (columnJustification[col] == null || columnJustification[col].equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Default))
// when generated sets correct alignment
columnJustification[col] = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
// Column Fonts
if (item.getAD_PrintFont_ID() != 0 && item.getAD_PrintFont_ID() != format.getAD_PrintFont_ID()) {
MPrintFont font = MPrintFont.get(item.getAD_PrintFont_ID());
rowColFont.put(new Point(TableElement.ALL, col), font.getFont());
}
if (item.getAD_PrintColor_ID() != 0 && item.getAD_PrintColor_ID() != format.getAD_PrintColor_ID()) {
MPrintColor color = MPrintColor.get(getCtx(), item.getAD_PrintColor_ID());
rowColColor.put(new Point(TableElement.ALL, col), color.getColor());
}
//
col++;
}
}
// The Data
int rows = printData.getRowCount();
// System.out.println("Rows=" + rows);
Object[][] data = new Object[rows][columnCount];
KeyNamePair[] pk = new KeyNamePair[rows];
String pkColumnName = null;
ArrayList<Integer> functionRows = new ArrayList<Integer>();
ArrayList<Integer> pageBreak = new ArrayList<Integer>();
// for all rows
for (int row = 0; row < rows; row++) {
// System.out.println("row=" + row);
printData.setRowIndex(row);
if (printData.isFunctionRow()) {
functionRows.add(new Integer(row));
rowColFont.put(new Point(row, TableElement.ALL), tf.getFunct_Font());
rowColColor.put(new Point(row, TableElement.ALL), tf.getFunctFG_Color());
rowColBackground.put(new Point(row, TableElement.ALL), tf.getFunctBG_Color());
if (printData.isPageBreak()) {
pageBreak.add(new Integer(row));
log.finer("PageBreak row=" + row);
}
} else // Summary/Line Levels for Finanial Reports
{
int levelNo = printData.getLineLevelNo();
if (levelNo != 0) {
if (levelNo < 0)
levelNo = -levelNo;
Font base = printFont.getFont();
if (levelNo == 1)
rowColFont.put(new Point(row, TableElement.ALL), new Font(base.getName(), Font.ITALIC, base.getSize() - levelNo));
else if (levelNo == 2)
rowColFont.put(new Point(row, TableElement.ALL), new Font(base.getName(), Font.PLAIN, base.getSize() - levelNo));
}
}
// for all columns
col = 0;
for (int c = 0; c < format.getItemCount(); c++) {
MPrintFormatItem item = format.getItem(c);
Object dataElement = null;
if (// Text Columns
item.isPrinted()) {
if (item.isTypeImage()) {
if (item.isImageField())
data[row][col] = createImageElement(item);
else if (item.isImageIsAttached())
data[row][col] = ImageElement.get(item.get_ID());
else
data[row][col] = ImageElement.get(item.getImageURL());
// Image layout - teo_sarca, [ 1673548 ]
if (data[row][col] != null)
((ImageElement) data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
} else if (item.isBarcode()) {
Object obj = null;
if (// teo_sarca, [ 1673542 ]
item.getAD_Column_ID() > 0)
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)
((BarcodeElement) data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
} else if (item.isTypeText()) {
data[row][col] = item.getPrintName(format.getLanguage());
} else if (item.isTypeField()) {
Object obj = null;
if (// teo_sarca, [ 1673542 ]
item.getAD_Column_ID() > 0)
obj = printData.getNode(new Integer(item.getAD_Column_ID()));
if (obj == null)
;
else if (obj instanceof PrintDataElement) {
PrintDataElement pde = (PrintDataElement) obj;
if (pde.isID() || pde.isYesNo())
dataElement = pde.getValue();
else
dataElement = pde.getValueDisplay(format.getLanguage());
} else
log.log(Level.SEVERE, "Element not PrintDataElement " + obj.getClass());
// System.out.println(" row=" + row + ",col=" + col + " - " + item.getAD_Column_ID() + " => " + dataElement);
data[row][col] = dataElement;
} else if (item.isTypePrintFormat()) {
m_currPage.addElement(includeFormat(item, printData));
} else // item.isTypeBox() or isTypePrintFormat()
{
log.warning("Unsupported: " + (item.isTypeBox() ? "Box" : "PrintFormat") + " in Table: " + item);
}
col++;
}
// printed
}
// for all columns
PrintDataElement pde = printData.getPKey();
if (// for FunctionRows
pde != null) {
pk[row] = (KeyNamePair) pde.getValue();
if (pkColumnName == null)
pkColumnName = pde.getColumnName();
}
// else
// System.out.println("No PK " + printData);
}
// for all rows
//
TableElement table = new TableElement(columnHeader, columnMaxWidth, columnMaxHeight, columnJustification, fixedWidth, functionRows, multiLineHeader, data, pk, pkColumnName, pageNoStart, firstPage, nextPages, repeatedColumns, additionalLines, rowColFont, rowColColor, rowColBackground, tf, pageBreak, colSuppressRepeats);
table.layout(0, 0, false, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
if (m_tableElement == null)
m_tableElement = table;
return table;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class LayoutEngine method createFieldElement.
// createStringElement
/**
* Create Field Element
* @param item Format Item
* @param maxWidth max width
* @param FieldAlignmentType alignment type (MPrintFormatItem.FIELD_ALIGN_*)
* @param isForm true if document
* @return Print Element or null if nothing to print
*/
private PrintElement createFieldElement(MPrintFormatItem item, int maxWidth, String FieldAlignmentType, boolean isForm) {
// Get Data
Object obj = m_data.getNode(new Integer(item.getAD_Column_ID()));
if (obj == null)
return null;
else if (obj instanceof PrintDataElement)
;
else {
log.log(Level.SEVERE, "Element not PrintDataElement " + obj.getClass());
return null;
}
// Convert DataElement to String
PrintDataElement data = (PrintDataElement) obj;
if (data.isNull() && item.isSuppressNull())
return null;
String stringContent = data.getValueDisplay(m_format.getLanguage());
if ((stringContent == null || stringContent.length() == 0) && item.isSuppressNull())
return null;
// non-string
Object content = stringContent;
if (data.getValue() instanceof Boolean)
content = data.getValue();
// Convert AmtInWords Content to alpha
if (item.getColumnName().equals("AmtInWords")) {
log.fine("AmtInWords: " + stringContent);
stringContent = Msg.getAmtInWords(m_format.getLanguage(), stringContent);
content = stringContent;
}
// Label
String label = item.getPrintName(m_format.getLanguage());
String labelSuffix = item.getPrintNameSuffix(m_format.getLanguage());
// ID Type
NamePair ID = null;
if (data.isID()) {
// Record_ID/ColumnName
Object value = data.getValue();
if (value instanceof KeyNamePair)
ID = new KeyNamePair(((KeyNamePair) value).getKey(), item.getColumnName());
else if (value instanceof ValueNamePair)
ID = new ValueNamePair(((ValueNamePair) value).getValue(), item.getColumnName());
} else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Default.equals(FieldAlignmentType)) {
if (data.isNumeric())
FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight;
else
FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
}
// Get Color/ Font
// default
Color color = getColor();
if (ID != null && !isForm)
// link color/underline handeled in PrintElement classes
;
else if (item.getAD_PrintColor_ID() != 0 && m_printColor.get_ID() != item.getAD_PrintColor_ID()) {
MPrintColor c = MPrintColor.get(getCtx(), item.getAD_PrintColor_ID());
if (c.getColor() != null)
color = c.getColor();
}
// default
Font font = m_printFont.getFont();
if (item.getAD_PrintFont_ID() != 0 && m_printFont.get_ID() != item.getAD_PrintFont_ID()) {
MPrintFont f = MPrintFont.get(item.getAD_PrintFont_ID());
if (f.getFont() != null)
font = f.getFont();
}
// Create String, HTML or Location
PrintElement e = null;
if (data.getDisplayType() == DisplayType.Location) {
e = new LocationElement(m_printCtx, ((KeyNamePair) ID).getKey(), font, color, item.isHeightOneLine(), label, labelSuffix, m_format.getLanguage().getAD_Language());
e.layout(maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
} else {
if (HTMLElement.isHTML(stringContent))
e = new HTMLElement(stringContent);
else
e = new StringElement(content, font, color, isForm ? null : ID, label, labelSuffix);
e.layout(maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
}
return e;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class VPayPrint method cmd_EFT.
// cmd_export
/**
* Create EFT payment
*/
private void cmd_EFT() {
ValueNamePair pp = (ValueNamePair) fPaymentRule.getSelectedItem();
if (pp == null)
return;
String PaymentRule = pp.getValue();
log.info(PaymentRule);
if (!getChecks(PaymentRule))
return;
dispose();
}
Aggregations