Search in sources :

Example 6 with NamePair

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

Example 7 with NamePair

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

the class Process method fillParameter.

//	createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception {
    MPInstance pInstance = new MPInstance(process, 0);
    DataField[] f = dr.getFieldArray();
    HashMap fmap = new HashMap();
    for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i].getVal());
    //
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        int displayType = pPara.getAD_Reference_ID();
        String valueString = null;
        Object ob = fmap.get(key);
        if (ob != null)
            valueString = ob.toString();
        String valueString2 = null;
        if (pPara.isRange()) {
            ob = fmap.get(key + "_2");
            if (ob != null)
                valueString2 = ob.toString();
        }
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        if (value != null && (DisplayType.List == displayType || DisplayType.TableDir == displayType || DisplayType.Table == displayType) && value.equals("-1"))
            value = null;
        //	No Value
        if (value == null && DisplayType.YesNo != pPara.getAD_Reference_ID()) {
            if (pPara.isMandatory())
                throw new Exception(" Parameter " + pPara.getName() + " is required.");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(displayType) || DisplayType.isID(displayType)) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                    if (pPara.isRange()) {
                        bd = null;
                        bd = new BigDecimal(valueString2.toString());
                        iPara.setP_Number_To(bd);
                    }
                } else if (DisplayType.isDate(displayType)) {
                    java.util.Date d;
                    if (displayType == DisplayType.DateTime)
                        d = m_cs.dateFormat.parse(value.toString());
                    else
                        // TODO: datetime
                        d = m_cs.dateFormat.parse(value.toString());
                    //d = m_cs.dateTimeFormat.parse(value.toString());
                    Timestamp ts = null;
                    ts = new Timestamp(d.getTime());
                    iPara.setP_Date(ts);
                    if (pPara.isRange()) {
                        if (displayType == DisplayType.DateTime)
                            d = m_cs.dateFormat.parse(valueString2);
                        else //d = m_cs.dateTimeFormat.parse(valueString2);
                        {
                            if (valueString2 == null || valueString2.length() == 0)
                                d = new java.util.Date();
                            else
                                //TODO: datetime
                                d = m_cs.dateFormat.parse(valueString2);
                        }
                        ts = new Timestamp(d.getTime());
                        iPara.setP_Date_To(ts);
                    }
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else if (DisplayType.YesNo == pPara.getAD_Reference_ID()) {
                    String bv = "N";
                    if (value == null)
                        bv = "N";
                    else //if (value.toString().toLowerCase().charAt(0)=='t')
                    {
                        if ("true".equalsIgnoreCase(valueString) || "y".equalsIgnoreCase(valueString))
                            bv = "Y";
                        else
                            bv = "N";
                    }
                    //bv ="Y";
                    iPara.setP_String(bv);
                } else {
                    iPara.setP_String(value.toString());
                }
                if (// kolec - ustawia wartosc dla parametru Lookup
                pPara.isLookup()) {
                    Lookup lok = pPara.getLookup();
                    if (lok != null) {
                        NamePair np = lok.getDirect(value, false, false);
                        if (np != null) {
                            iPara.setInfo(np.getName());
                        }
                    }
                } else {
                    if (value != null)
                        iPara.setInfo(value.toString());
                    if (valueString2 != null)
                        iPara.setInfo_To(valueString2);
                }
                //
                iPara.save();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    //	instance parameter loop
    // kolec - tego chyba brakowalo
    pInstance.save();
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) HashMap(java.util.HashMap) NamePair(org.compiere.util.NamePair) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) MPInstance(org.compiere.model.MPInstance) DataField(pl.x3E.adInterface.DataField) Lookup(org.compiere.model.Lookup)

Example 8 with NamePair

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

the class SortComparator method compare.

//	setSortAsc
/**************************************************************************
	 *	Compare Data of two entities
	 *  @param o1 object
	 *  @param o2 object
	 *  @return comparator
	 */
public int compare(Object o1, Object o2) {
    //	Get Objects to compare
    Object cmp1 = o1;
    if (cmp1 instanceof NamePair)
        cmp1 = ((NamePair) cmp1).getName();
    Object cmp2 = o2;
    if (cmp2 instanceof NamePair)
        cmp2 = ((NamePair) cmp2).getName();
    //	Comparing Null values
    if (cmp1 == null) {
        if (cmp2 == null)
            return 0;
        return -1 * m_multiplier;
    }
    if (cmp2 == null)
        return 1 * m_multiplier;
    //	String
    if (cmp1 instanceof String && cmp2 instanceof String) {
        // teo_sarca [ 1672820 ]
        return m_collator.compare(cmp1, cmp2) * m_multiplier;
    } else //	Date
    if (cmp1 instanceof Timestamp && cmp2 instanceof Timestamp) {
        Timestamp t = (Timestamp) cmp1;
        return t.compareTo((Timestamp) cmp2) * m_multiplier;
    } else //	BigDecimal
    if (cmp1 instanceof BigDecimal && cmp2 instanceof BigDecimal) {
        BigDecimal d = (BigDecimal) cmp1;
        return d.compareTo((BigDecimal) cmp2) * m_multiplier;
    } else //	Integer
    if (cmp1 instanceof Integer && cmp2 instanceof Integer) {
        Integer d = (Integer) cmp1;
        return d.compareTo((Integer) cmp2) * m_multiplier;
    } else //	Double
    if (cmp1 instanceof Double && cmp2 instanceof Double) {
        Double d = (Double) cmp1;
        return d.compareTo((Double) cmp2) * m_multiplier;
    }
    //  Convert to string value
    String s = cmp1.toString();
    // teo_sarca [ 1672820 ]
    return m_collator.compare(s, cmp2.toString()) * m_multiplier;
}
Also used : NamePair(org.compiere.util.NamePair) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 9 with NamePair

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

the class RecordInfoController method addLine.

/**
	 * 	Add Line
	 *	@param AD_Column_ID column
	 *	@param Updated updated
	 *	@param UpdatedBy user
	 *	@param OldValue old
	 *	@param NewValue new
	 */
private void addLine(int AD_Column_ID, Timestamp Updated, int UpdatedBy, String OldValue, String NewValue) {
    Vector<String> line = new Vector<String>();
    //	Column
    MColumn column = MColumn.get(Env.getCtx(), AD_Column_ID);
    //	No for specific column
    if (m_Field == null) {
        line.add(Msg.translate(Env.getCtx(), column.getColumnName()));
    }
    //
    if (OldValue != null && OldValue.equals(MChangeLog.NULL))
        OldValue = null;
    String showOldValue = OldValue;
    if (NewValue != null && NewValue.equals(MChangeLog.NULL))
        NewValue = null;
    String showNewValue = NewValue;
    //
    try {
        if (DisplayType.isText(column.getAD_Reference_ID()))
            ;
        else if (column.getAD_Reference_ID() == DisplayType.YesNo) {
            if (OldValue != null) {
                boolean yes = OldValue.equals("true") || OldValue.equals("Y");
                showOldValue = Msg.getMsg(Env.getCtx(), yes ? "Y" : "N");
            }
            if (NewValue != null) {
                boolean yes = NewValue.equals("true") || NewValue.equals("Y");
                showNewValue = Msg.getMsg(Env.getCtx(), yes ? "Y" : "N");
            }
        } else if (column.getAD_Reference_ID() == DisplayType.Amount) {
            if (OldValue != null)
                showOldValue = m_amtFormat.format(new BigDecimal(OldValue));
            if (NewValue != null)
                showNewValue = m_amtFormat.format(new BigDecimal(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.Integer) {
            if (OldValue != null)
                showOldValue = m_intFormat.format(new Integer(OldValue));
            if (NewValue != null)
                showNewValue = m_intFormat.format(new Integer(NewValue));
        } else if (DisplayType.isNumeric(column.getAD_Reference_ID())) {
            if (OldValue != null)
                showOldValue = m_numberFormat.format(new BigDecimal(OldValue));
            if (NewValue != null)
                showNewValue = m_numberFormat.format(new BigDecimal(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.Date) {
            if (OldValue != null)
                showOldValue = m_dateFormat.format(Timestamp.valueOf(OldValue));
            if (NewValue != null)
                showNewValue = m_dateFormat.format(Timestamp.valueOf(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
            if (OldValue != null)
                showOldValue = m_dateTimeFormat.format(Timestamp.valueOf(OldValue));
            if (NewValue != null)
                showNewValue = m_dateTimeFormat.format(Timestamp.valueOf(NewValue));
        } else if (DisplayType.isLookup(column.getAD_Reference_ID())) {
            MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, AD_Column_ID, column.getAD_Reference_ID(), Env.getLanguage(Env.getCtx()), column.getColumnName(), column.getAD_Reference_Value_ID(), column.isParent(), null);
            if (OldValue != null) {
                Object key = OldValue;
                NamePair pp = lookup.get(key);
                if (pp != null)
                    showOldValue = pp.getName();
            }
            if (NewValue != null) {
                Object key = NewValue;
                NamePair pp = lookup.get(key);
                if (pp != null)
                    showNewValue = pp.getName();
            }
        } else if (DisplayType.isLOB(column.getAD_Reference_ID()))
            ;
    } catch (Exception e) {
        log.log(Level.WARNING, OldValue + "->" + NewValue, e);
    }
    //
    line.add(showNewValue);
    line.add(showOldValue);
    //	UpdatedBy
    MUser user = MUser.get(Env.getCtx(), UpdatedBy);
    line.add(user.getName());
    //	Updated
    line.add(m_dateFormat.format(Updated));
    //	No for specific column
    if (m_Field == null) {
        line.add(column.getColumnName());
    }
    m_data.add(line);
}
Also used : MColumn(org.compiere.model.MColumn) MLookup(org.compiere.model.MLookup) NamePair(org.compiere.util.NamePair) Vector(java.util.Vector) MUser(org.compiere.model.MUser) BigDecimal(java.math.BigDecimal)

Example 10 with NamePair

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

the class PrintDataElement method toStringX.

//	hasKey
/**
	 * 	String representation with key info
	 * 	@return info
	 */
public String toStringX() {
    if (m_value instanceof NamePair) {
        NamePair pp = (NamePair) m_value;
        StringBuffer sb = new StringBuffer(m_columnName);
        sb.append("(").append(pp.getID()).append(")").append("=").append(pp.getName());
        if (m_isPKey)
            sb.append("(PK)");
        return sb.toString();
    } else
        return toString();
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair) NamePair(org.compiere.util.NamePair)

Aggregations

NamePair (org.compiere.util.NamePair)21 KeyNamePair (org.compiere.util.KeyNamePair)14 ValueNamePair (org.compiere.util.ValueNamePair)12 BigDecimal (java.math.BigDecimal)5 Point (java.awt.Point)4 AttributedString (java.text.AttributedString)3 Vector (java.util.Vector)3 MColumn (org.compiere.model.MColumn)3 MLookup (org.compiere.model.MLookup)3 MUser (org.compiere.model.MUser)3 Color (java.awt.Color)2 Font (java.awt.Font)2 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)2 TextLayout (java.awt.font.TextLayout)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 AttributedCharacterIterator (java.text.AttributedCharacterIterator)2 HashMap (java.util.HashMap)2 MQuery (org.compiere.model.MQuery)2 Dimension (java.awt.Dimension)1