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