Search in sources :

Example 6 with MAttributeValue

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

the class MAttributeTest method testQuery.

public void testQuery() throws Exception {
    MAttribute attrib = new MAttribute(getCtx(), 100, getTrxName());
    MAttribute[] attbClient = MAttribute.getOfClient(getCtx(), true, true);
    assertTrue("atrributes must be true", attbClient.length > 0);
    MAttributeValue[] av = attrib.getMAttributeValues();
    assertTrue("atrributes must have values", av.length > 0);
    MAttributeInstance ai = attrib.getMAttributeInstance(100);
    assertTrue("atrributes must have values", ai.isActive());
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) MAttribute(org.compiere.model.MAttribute)

Example 7 with MAttributeValue

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

the class HTMLMessenger method getAttributeSetInstanceInfo.

public String getAttributeSetInstanceInfo(MAttributeSetInstance asi, boolean singleRow) {
    MAttributeSet as = new MAttributeSet(Env.getCtx(), asi.getM_AttributeSet_ID(), null);
    StorageReasoner mr = new StorageReasoner();
    int[] ids = mr.getAttributeIDs(asi);
    MAttributeInstance ai = null;
    MAttribute a = null;
    MAttributeValue av = null;
    StringBuffer sb = new StringBuffer();
    String value = null;
    Object[] obj = null;
    for (int i = 0; i < ids.length; i++) {
        ai = new MAttributeInstance(Env.getCtx(), ids[i], asi.get_ID(), (String) null, null);
        ai.load(null);
        a = new MAttribute(Env.getCtx(), ai.getM_Attribute_ID(), null);
        av = new MAttributeValue(Env.getCtx(), ai.getM_AttributeValue_ID(), null);
        // e.g. the list validation type 'L'
        if (ai.getValue() == null) {
            value = av.getValue();
        } else // Takes the value of the M_AttributeInstance itself
        {
            // Round number values to a scale of 2, if type is 'N'
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) {
                BigDecimal number = ai.getValueNumber();
                value = number.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            } else {
                value = ai.getValue();
            }
        }
        obj = new Object[] { a.getName(), value };
        sb.append(MessageFormat.format(ATTRIBUTE_INFO_PATTERN, obj));
        if (singleRow) {
            sb.append("&nbsp;");
        } else {
            sb.append("<br>");
        }
    }
    return sb.toString();
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) StorageReasoner(org.eevolution.model.reasoner.StorageReasoner) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 8 with MAttributeValue

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

the class VAttributeGrid method createGrid.

/**
	 * 	Create Grid
	 */
private void createGrid() {
    if (attributeCombo1 == null || m_setting)
        //	init
        return;
    int indexAttr1 = attributeCombo1.getSelectedIndex();
    int indexAttr2 = attributeCombo2.getSelectedIndex();
    if (indexAttr1 == indexAttr2) {
        log.warning("Same Attribute Selected");
        tabbedPane.setSelectedIndex(0);
        return;
    }
    m_setting = true;
    m_M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null)
        m_M_PriceList_Version_ID = pl.getKey();
    m_M_Warehouse_ID = 0;
    KeyNamePair wh = (KeyNamePair) pickWarehouse.getSelectedItem();
    if (wh != null)
        m_M_Warehouse_ID = wh.getKey();
    //	x dimension
    int cols = 2;
    MAttributeValue[] xValues = null;
    if (indexAttr1 > 0)
        xValues = m_attributes[indexAttr1 - 1].getMAttributeValues();
    if (xValues != null) {
        cols = xValues.length;
        log.info("X - " + m_attributes[indexAttr1 - 1].getName() + " #" + xValues.length);
    }
    //	y dimension
    int rows = 2;
    MAttributeValue[] yValues = null;
    if (indexAttr2 > 0)
        yValues = m_attributes[indexAttr2 - 1].getMAttributeValues();
    if (yValues != null) {
        rows = yValues.length;
        log.info("Y - " + m_attributes[indexAttr2 - 1].getName() + " #" + yValues.length);
    }
    //
    gridPanel.removeAll();
    CPanel grid = new CPanel(new GridLayout(rows, cols, 5, 5));
    gridPanel.add(modePanel, BorderLayout.NORTH);
    gridPanel.add(new CScrollPane(grid), BorderLayout.CENTER);
    //
    log.info("Rows=" + rows + " - Cols=" + cols);
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            MAttributeValue xValue = null;
            if (xValues != null)
                xValue = xValues[col];
            MAttributeValue yValue = null;
            if (yValues != null)
                yValue = yValues[row];
            //
            if (row == 0 && col == 0) {
                CPanel descr = new CPanel(new GridLayout(2, 1, 0, 0));
                if (xValues != null)
                    descr.add(new JLabel(m_attributes[indexAttr1 - 1].getName(), JLabel.TRAILING));
                if (yValues != null)
                    descr.add(new JLabel(m_attributes[indexAttr2 - 1].getName()));
                grid.add(descr);
            } else if (//	column labels
            row == 0) {
                if (xValue != null) {
                    grid.add(new JLabel(xValue.getName(), JLabel.TRAILING));
                } else
                    grid.add(new JLabel());
            } else if (//	row labels
            col == 0) {
                if (yValue != null)
                    grid.add(new JLabel(yValue.getName()));
                else
                    grid.add(new JLabel());
            } else {
                grid.add(getGridElement(xValue, yValue));
            }
        }
    }
    //
    tabbedPane.setSelectedIndex(1);
    m_setting = false;
    m_frame.pack();
}
Also used : GridLayout(java.awt.GridLayout) CScrollPane(org.compiere.swing.CScrollPane) MAttributeValue(org.compiere.model.MAttributeValue) CPanel(org.compiere.swing.CPanel) JLabel(javax.swing.JLabel) KeyNamePair(org.compiere.util.KeyNamePair) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 9 with MAttributeValue

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

the class ImportProductASI method getAttributeValue.

private MAttributeValue getAttributeValue(MAttribute attribute, X_I_Product_ASI ip_asi) {
    MAttributeValue attributeValue = null;
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(ip_asi.getAttributeValueType())) {
        MAttributeValue[] attributeValues = attribute.getMAttributeValues();
        for (MAttributeValue aValue : attributeValues) {
            if (aValue.getName().equals(ip_asi.getElementName())) {
                return aValue;
            }
        }
        attributeValue = new MAttributeValue(getCtx(), 0, get_TrxName());
        attributeValue.setM_Attribute_ID(attribute.getM_Attribute_ID());
        attributeValue.setValue(ip_asi.getAttributeValue());
        attributeValue.setName(ip_asi.getElementName());
        attributeValue.saveEx();
    }
    return attributeValue;
}
Also used : MAttributeValue(org.compiere.model.MAttributeValue)

Example 10 with MAttributeValue

use of org.compiere.model.MAttributeValue 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

MAttributeValue (org.compiere.model.MAttributeValue)10 MAttributeInstance (org.compiere.model.MAttributeInstance)5 BigDecimal (java.math.BigDecimal)4 MAttribute (org.compiere.model.MAttribute)4 ListItem (org.adempiere.webui.component.ListItem)3 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)3 MAttributeSet (org.compiere.model.MAttributeSet)3 Timestamp (java.sql.Timestamp)2 Label (org.adempiere.webui.component.Label)2 Listbox (org.adempiere.webui.component.Listbox)2 NumberBox (org.adempiere.webui.component.NumberBox)2 Row (org.adempiere.webui.component.Row)2 Textbox (org.adempiere.webui.component.Textbox)2 CComboBox (org.compiere.swing.CComboBox)2 Font (java.awt.Font)1 GridLayout (java.awt.GridLayout)1 Date (java.util.Date)1 JLabel (javax.swing.JLabel)1 Rows (org.adempiere.webui.component.Rows)1 CLabel (org.compiere.swing.CLabel)1