Search in sources :

Example 46 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class MLocatorLookup method get.

//  loadComplete
/**
	 *	Get value
	 *  @param key key
	 *  @return value value
	 */
public NamePair get(Object key) {
    if (key == null)
        return null;
    //	try cache
    MLocator loc = (MLocator) m_lookup.get(key);
    if (loc != null)
        return new KeyNamePair(loc.getM_Locator_ID(), loc.toString());
    //	Not found and waiting for loader
    if (m_loader.isAlive()) {
        log.fine("Waiting for Loader");
        loadComplete();
        //	is most current
        loc = (MLocator) m_lookup.get(key);
    }
    if (loc != null)
        return new KeyNamePair(loc.getM_Locator_ID(), loc.toString());
    //	Try to get it directly
    return getDirect(key, true, null);
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 47 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class MLot method getProductLotPairs.

//	getProductLot
/**
	 * 	Get Lot Key Name Pairs for Product
	 *	@param M_Product_ID product
	 *	@param trxName transaction
	 *	@return Array of Lot Key Name Pairs for Product
	 */
public static KeyNamePair[] getProductLotPairs(int M_Product_ID, String trxName) {
    String sql = "SELECT M_Lot_ID, Name FROM M_Lot WHERE M_Product_ID=?";
    ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        pstmt.setInt(1, M_Product_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
    } catch (SQLException ex) {
        s_log.log(Level.SEVERE, sql, ex);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    KeyNamePair[] retValue = new KeyNamePair[list.size()];
    list.toArray(retValue);
    return retValue;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair)

Example 48 with KeyNamePair

use of org.compiere.util.KeyNamePair 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;
}
Also used : HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) MPrintFont(org.compiere.print.MPrintFont) Font(java.awt.Font) ValueNamePair(org.compiere.util.ValueNamePair) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) MPrintFont(org.compiere.print.MPrintFont) MPrintFormatItem(org.compiere.print.MPrintFormatItem) Point(java.awt.Point) Point(java.awt.Point) PrintDataElement(org.compiere.print.PrintDataElement) MPrintTableFormat(org.compiere.print.MPrintTableFormat) MPrintColor(org.compiere.print.MPrintColor) KeyNamePair(org.compiere.util.KeyNamePair)

Example 49 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class StringElement method getDrillDown.

//	calculateSize
/**************************************************************************
	 * 	Get Drill Down value
	 * 	@param relativePoint relative Point
	 *  @param pageNo page number (ignored)
	 * 	@return if found query or null
	 */
public MQuery getDrillDown(Point relativePoint, int pageNo) {
    if (m_ID != null && getBounds().contains(relativePoint)) {
        log.fine(toString());
        String columnName = MQuery.getZoomColumnName(m_ID.getName());
        String tableName = MQuery.getZoomTableName(columnName);
        Object code = m_ID.getID();
        if (m_ID instanceof KeyNamePair)
            code = new Integer(((KeyNamePair) m_ID).getKey());
        //
        MQuery query = new MQuery(tableName);
        query.addRestriction(columnName, MQuery.EQUAL, code);
        return query;
    }
    return null;
}
Also used : MQuery(org.compiere.model.MQuery) AttributedString(java.text.AttributedString) KeyNamePair(org.compiere.util.KeyNamePair)

Example 50 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class TableElement method getDrillDown.

//	getPageYCount
/**************************************************************************
	 * 	Get Drill Down value
	 * 	@param relativePoint relative Point
	 *  @param pageNo page number
	 * 	@return if found Qyery or null
	 */
public MQuery getDrillDown(Point relativePoint, int pageNo) {
    if (m_rowColDrillDown.size() == 0)
        return null;
    if (!getBounds(pageNo).contains(relativePoint))
        return null;
    int row = getRow(relativePoint.y, pageNo);
    if (row == -1)
        return null;
    int col = getCol(relativePoint.x, pageNo);
    if (col == -1)
        return null;
    log.fine("Row=" + row + ", Col=" + col + ", PageNo=" + pageNo);
    //
    NamePair pp = (NamePair) m_rowColDrillDown.get(new Point(row, col));
    if (pp == null)
        return null;
    String columnName = MQuery.getZoomColumnName(m_columnHeader[col].getID());
    String tableName = MQuery.getZoomTableName(columnName);
    Object code = pp.getID();
    if (pp instanceof KeyNamePair)
        code = new Integer(((KeyNamePair) pp).getKey());
    //
    MQuery query = new MQuery(tableName);
    query.addRestriction(columnName, MQuery.EQUAL, code, null, pp.toString());
    return query;
}
Also used : NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) MQuery(org.compiere.model.MQuery) Point(java.awt.Point) AttributedString(java.text.AttributedString) KeyNamePair(org.compiere.util.KeyNamePair) Point(java.awt.Point)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7