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);
}
}
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);
}
}
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;
}
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;
}
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());
}
Aggregations