Search in sources :

Example 11 with MAttribute

use of org.compiere.model.MAttribute in project adempiere by adempiere.

the class VPAttributeDialog method saveSelection.

//	cmd_zoom
/**
	 *	Save Selection
	 *	@return true if saved
	 */
private boolean saveSelection() {
    if (!m_readWrite)
        return true;
    log.info("");
    MAttributeSet as = m_masi.getMAttributeSet();
    if (as == null)
        return true;
    //
    m_changed = false;
    String mandatory = "";
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        log.fine("Lot=" + fieldLotString.getText());
        String text = fieldLotString.getText();
        m_masi.setLot(text);
        if (as.isLotMandatory() && (text == null || text.length() == 0))
            mandatory += " - " + Msg.translate(Env.getCtx(), "Lot");
        m_changed = true;
    }
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        log.fine("SerNo=" + fieldSerNo.getText());
        String text = fieldSerNo.getText();
        m_masi.setSerNo(text);
        if (as.isSerNoMandatory() && (text == null || text.length() == 0))
            mandatory += " - " + Msg.translate(Env.getCtx(), "SerNo");
        m_changed = true;
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        log.fine("GuaranteeDate=" + fieldGuaranteeDate.getValue());
        Timestamp ts = (Timestamp) fieldGuaranteeDate.getValue();
        m_masi.setGuaranteeDate(ts);
        if (as.isGuaranteeDateMandatory() && ts == null)
            mandatory += " - " + Msg.translate(Env.getCtx(), "GuaranteeDate");
        m_changed = true;
    }
    //	New Instance
    if (m_changed || m_masi.getM_AttributeSetInstance_ID() == 0) {
        m_masi.save();
        m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
        m_M_AttributeSetInstanceName = m_masi.getDescription();
    }
    //  Save attributes
    if (m_M_AttributeSetInstance_ID > 0 && m_readWrite) {
        //	Save Instance Attributes
        MAttribute[] attributes = as.getMAttributes(!m_productASI);
        for (int i = 0; i < attributes.length; i++) {
            if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributes[i].getAttributeValueType())) {
                CComboBox editor = (CComboBox) m_editors.get(i);
                MAttributeValue value = (MAttributeValue) editor.getSelectedItem();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && value == null)
                    mandatory += " - " + attributes[i].getName();
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) {
                VNumber editor = (VNumber) m_editors.get(i);
                BigDecimal value = (BigDecimal) editor.getValue();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && value == null)
                    mandatory += " - " + attributes[i].getName();
                //setMAttributeInstance doesn't work without decimal point
                if (value != null && value.scale() == 0)
                    value = value.setScale(1, BigDecimal.ROUND_HALF_UP);
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            } else {
                VString editor = (VString) m_editors.get(i);
                String value = editor.getText();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && (value == null || value.length() == 0))
                    mandatory += " - " + attributes[i].getName();
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            }
        }
        m_changed = true;
    }
    //	Save Model
    if (m_changed) {
        m_masi.setDescription();
        m_masi.save();
    }
    m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
    m_M_AttributeSetInstanceName = m_masi.getDescription();
    //
    if (mandatory.length() > 0) {
        ADialog.error(m_WindowNo, this, "FillMandatory", mandatory);
        return false;
    }
    return true;
}
Also used : CComboBox(org.compiere.swing.CComboBox) MAttributeValue(org.compiere.model.MAttributeValue) Timestamp(java.sql.Timestamp) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Aggregations

MAttribute (org.compiere.model.MAttribute)11 MAttributeSet (org.compiere.model.MAttributeSet)7 BigDecimal (java.math.BigDecimal)4 MAttributeInstance (org.compiere.model.MAttributeInstance)4 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)4 MAttributeValue (org.compiere.model.MAttributeValue)4 Timestamp (java.sql.Timestamp)2 ListItem (org.adempiere.webui.component.ListItem)2 Listbox (org.adempiere.webui.component.Listbox)2 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)2 CComboBox (org.compiere.swing.CComboBox)2 KeyNamePair (org.compiere.util.KeyNamePair)2 Dimension (java.awt.Dimension)1 Date (java.util.Date)1 Label (org.adempiere.webui.component.Label)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Row (org.adempiere.webui.component.Row)1 Rows (org.adempiere.webui.component.Rows)1 Textbox (org.adempiere.webui.component.Textbox)1 MProduct (org.compiere.model.MProduct)1