Search in sources :

Example 1 with MAttributeInstance

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

the class VPAttributeDialog method addAttributeLine.

//	initAttribute
/**
	 * 	Add Attribute Line
	 *	@param attribute attribute
	 * 	@param product product level attribute
	 * 	@param readOnly value is read only
	 */
private void addAttributeLine(MAttribute attribute, boolean product, boolean readOnly) {
    log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
    CLabel label = new CLabel(attribute.getName());
    if (product)
        label.setFont(new Font(label.getFont().getFontName(), Font.BOLD, label.getFont().getSize()));
    if (attribute.getDescription() != null)
        label.setToolTipText(attribute.getDescription());
    centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
    //
    MAttributeInstance instance = attribute.getMAttributeInstance(m_M_AttributeSetInstance_ID);
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
        //	optional = null
        MAttributeValue[] values = attribute.getMAttributeValues();
        CComboBox editor = new CComboBox(values);
        boolean found = false;
        if (instance != null) {
            for (int i = 0; i < values.length; i++) {
                if (values[i] != null && values[i].getM_AttributeValue_ID() == instance.getM_AttributeValue_ID()) {
                    editor.setSelectedIndex(i);
                    found = true;
                    break;
                }
            }
            if (found)
                log.fine("Attribute=" + attribute.getName() + " #" + values.length + " - found: " + instance);
            else
                log.warning("Attribute=" + attribute.getName() + " #" + values.length + " - NOT found: " + instance);
        } else
            //	setComboBox
            log.fine("Attribute=" + attribute.getName() + " #" + values.length + " no instance");
        label.setLabelFor(editor);
        centerPanel.add(editor, null);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
        VNumber editor = new VNumber(attribute.getName(), attribute.isMandatory(), readOnly, !readOnly, DisplayType.Number, attribute.getName());
        if (instance != null)
            editor.setValue(instance.getValueNumber());
        else
            editor.setValue(Env.ZERO);
        label.setLabelFor(editor);
        centerPanel.add(editor, null);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    } else //	Text Field
    {
        VString editor = new VString(attribute.getName(), attribute.isMandatory(), false, true, 20, INSTANCE_VALUE_LENGTH, null, null);
        if (instance != null)
            editor.setText(instance.getValue());
        label.setLabelFor(editor);
        centerPanel.add(editor, null);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    }
}
Also used : CLabel(org.compiere.swing.CLabel) MAttributeInstance(org.compiere.model.MAttributeInstance) CComboBox(org.compiere.swing.CComboBox) MAttributeValue(org.compiere.model.MAttributeValue) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) Font(java.awt.Font) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 2 with MAttributeInstance

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

the class WPAttributeDialog method addAttributeLine.

//	initAttribute
/**
	 * 	Add Attribute Line
	 *	@param attribute attribute
	 * 	@param product product level attribute
	 * 	@param readOnly value is read only
	 */
private void addAttributeLine(Rows rows, MAttribute attribute, boolean product, boolean readOnly) {
    log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
    m_row++;
    Label label = new Label(attribute.getName());
    if (product)
        label.setStyle("font-weight: bold");
    if (attribute.getDescription() != null)
        label.setTooltiptext(attribute.getDescription());
    Row row = rows.newRow();
    row.appendChild(label.rightAlign());
    //
    MAttributeInstance instance = attribute.getMAttributeInstance(m_M_AttributeSetInstance_ID);
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
        //	optional = null
        MAttributeValue[] values = attribute.getMAttributeValues();
        Listbox editor = new Listbox();
        editor.setMold("select");
        for (MAttributeValue value : values) {
            ListItem item = new ListItem(value != null ? value.getName() : "", value);
            editor.appendChild(item);
        }
        boolean found = false;
        if (instance != null) {
            for (int i = 0; i < values.length; i++) {
                if (values[i] != null && values[i].getM_AttributeValue_ID() == instance.getM_AttributeValue_ID()) {
                    editor.setSelectedIndex(i);
                    found = true;
                    break;
                }
            }
            if (found)
                log.fine("Attribute=" + attribute.getName() + " #" + values.length + " - found: " + instance);
            else
                log.warning("Attribute=" + attribute.getName() + " #" + values.length + " - NOT found: " + instance);
        } else
            //	setComboBox
            log.fine("Attribute=" + attribute.getName() + " #" + values.length + " no instance");
        row.appendChild(editor);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
        NumberBox editor = new NumberBox(false);
        if (instance != null)
            editor.setValue(instance.getValueNumber());
        else
            editor.setValue(Env.ZERO);
        row.appendChild(editor);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    } else //	Text Field
    {
        Textbox editor = new Textbox();
        if (instance != null)
            editor.setText(instance.getValue());
        row.appendChild(editor);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    }
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) Label(org.adempiere.webui.component.Label) Textbox(org.adempiere.webui.component.Textbox) Row(org.adempiere.webui.component.Row) ListItem(org.adempiere.webui.component.ListItem) NumberBox(org.adempiere.webui.component.NumberBox) Listbox(org.adempiere.webui.component.Listbox)

Example 3 with MAttributeInstance

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

the class MQMSpecification method isValid.

//	getLines
public boolean isValid(int M_AttributeSetInstance_ID) {
    //		Save Instance Attributes
    if (M_AttributeSetInstance_ID == 0)
        return false;
    MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), M_AttributeSetInstance_ID, get_TrxName());
    MAttributeSet as = MAttributeSet.get(getCtx(), asi.getM_AttributeSet_ID());
    MAttribute[] attributes = as.getMAttributes(true);
    for (int i = 0; i < attributes.length; i++) {
        MAttributeInstance instance = attributes[i].getMAttributeInstance(M_AttributeSetInstance_ID);
        List<MQMSpecificationLine> lines = getLines(" M_Attribute_ID=" + attributes[i].getM_Attribute_ID());
        if (lines == null)
            return false;
        for (MQMSpecificationLine line : lines) {
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) {
                BigDecimal objValue = instance.getValueNumber();
                if (!line.evaluate(objValue, instance.getValue()))
                    ;
                return false;
            } else {
                String objValue = instance.getValue();
                if (!line.evaluate(objValue, instance.getValue()))
                    return false;
            }
        //if(line.evaluate(mas.getValueNumber())
        }
    }
    //	for all attributes			
    return true;
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 4 with MAttributeInstance

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

the class ImportProductASI method addAttributeLine.

private MAttributeInstance addAttributeLine(MAttributeSetInstance asi, MAttribute attribute, X_I_Product_ASI ip_asi) {
    MAttributeInstance instance = attribute.getMAttributeInstance(asi.get_ID());
    if (instance == null) {
        instance = new MAttributeInstance(getCtx(), 0, get_TrxName());
        instance.setM_Attribute_ID(attribute.getM_Attribute_ID());
        instance.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
        instance.saveEx();
    }
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
        MAttributeValue attributeValue = getAttributeValue(attribute, ip_asi);
        attribute.setMAttributeInstance(instance.get_ID(), attributeValue.getValue());
        ip_asi.setM_AttributeValue_ID(attributeValue.get_ID());
        ip_asi.saveEx();
    } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
        BigDecimal numericValue = new BigDecimal(ip_asi.getAttributeValue());
        attribute.setMAttributeInstance(instance.get_ID(), numericValue);
    } else if (MAttribute.ATTRIBUTEVALUETYPE_StringMax40.equals(attribute.getAttributeValueType())) {
        attribute.setMAttributeInstance(instance.get_ID(), ip_asi.getAttributeValue().length() > 40 ? ip_asi.getAttributeValue().substring(0, 40) : ip_asi.getAttributeValue());
    }
    return instance;
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) BigDecimal(java.math.BigDecimal)

Example 5 with MAttributeInstance

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

Aggregations

MAttributeInstance (org.compiere.model.MAttributeInstance)8 MAttributeValue (org.compiere.model.MAttributeValue)5 MAttribute (org.compiere.model.MAttribute)4 BigDecimal (java.math.BigDecimal)3 MAttributeSet (org.compiere.model.MAttributeSet)3 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)2 Font (java.awt.Font)1 Label (org.adempiere.webui.component.Label)1 ListItem (org.adempiere.webui.component.ListItem)1 Listbox (org.adempiere.webui.component.Listbox)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Row (org.adempiere.webui.component.Row)1 Textbox (org.adempiere.webui.component.Textbox)1 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)1 MProduct (org.compiere.model.MProduct)1 CComboBox (org.compiere.swing.CComboBox)1 CLabel (org.compiere.swing.CLabel)1 X_I_Product_ASI (org.eevolution.model.X_I_Product_ASI)1 StorageReasoner (org.eevolution.model.reasoner.StorageReasoner)1