use of org.compiere.model.MAttributeValue 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.MAttributeValue in project adempiere by adempiere.
the class WPAttributeDialog method saveSelection.
// cmd_zoom
/**
* Save Selection
* @return true if saved
*/
private boolean saveSelection() {
log.info("");
MAttributeSet as = m_masi.getMAttributeSet();
if (as == null)
return true;
//
m_changed = false;
String mandatory = "";
if (!m_productWindow && 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 && 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 && as.isGuaranteeDate()) {
log.fine("GuaranteeDate=" + fieldGuaranteeDate.getValue());
Date gDate = fieldGuaranteeDate.getValue();
Timestamp ts = gDate != null ? new Timestamp(gDate.getTime()) : null;
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) {
// 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())) {
Listbox editor = (Listbox) m_editors.get(i);
ListItem item = editor.getSelectedItem();
MAttributeValue value = item != null ? (MAttributeValue) item.getValue() : null;
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())) {
NumberBox editor = (NumberBox) m_editors.get(i);
BigDecimal value = 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 {
Textbox editor = (Textbox) 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) {
FDialog.error(m_WindowNo, this, "FillMandatory", mandatory);
return false;
}
return true;
}
use of org.compiere.model.MAttributeValue 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.MAttributeValue 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.MAttributeValue in project adempiere by adempiere.
the class WAttributeGrid method createGrid.
/**
* Create Grid
*/
private void createGrid() {
if (attributeCombo1 == null || m_setting)
// init
return;
Object attr1 = attributeCombo1.getSelectedItem().getValue();
Object attr2 = attributeCombo2.getSelectedItem().getValue();
if (attr1.equals(attr2)) {
FDialog.warn(m_WindowNo, "Same Attribute Selected", getTitle());
log.warning("Same Attribute Selected");
tabbox.setSelectedIndex(0);
return;
}
m_setting = true;
m_M_PriceList_Version_ID = 0;
ListItem pl = pickPriceList.getSelectedItem();
if (pl != null)
m_M_PriceList_Version_ID = Integer.valueOf(pl.getValue().toString());
m_M_Warehouse_ID = 0;
ListItem wh = pickWarehouse.getSelectedItem();
if (wh != null)
m_M_Warehouse_ID = Integer.valueOf(wh.getValue().toString());
// x dimension
int noOfCols = 2;
int indexAttr1 = 0;
MAttributeValue[] xValues = null;
if (attr1 != null) {
int value = Integer.parseInt(attr1.toString());
for (int i = 0; i < m_attributes.length; i++) {
if (m_attributes[i].getKeyNamePair().getKey() == value) {
xValues = m_attributes[i].getMAttributeValues();
indexAttr1 = i;
break;
}
}
}
if (xValues != null)
noOfCols = xValues.length;
// y dimension
int noOfRows = 2;
int indexAttr2 = 0;
MAttributeValue[] yValues = null;
if (attr2 != null) {
int value = Integer.parseInt(attr2.toString());
for (int i = 0; i < m_attributes.length; i++) {
if (m_attributes[i].getKeyNamePair().getKey() == value) {
yValues = m_attributes[i].getMAttributeValues();
indexAttr2 = i;
break;
}
}
}
if (yValues != null)
noOfRows = yValues.length;
gridView.getChildren().clear();
Rows rows = new Rows();
gridView.appendChild(rows);
log.info("Rows=" + noOfRows + " - Cols=" + noOfCols);
for (int rowIndex = 0; rowIndex < noOfRows; rowIndex++) {
Row row = new Row();
row.setWidth("100%");
rows.appendChild(row);
for (int colIndex = 0; colIndex < noOfCols; colIndex++) {
MAttributeValue xValue = null;
if (xValues != null)
xValue = xValues[colIndex];
MAttributeValue yValue = null;
if (yValues != null)
yValue = yValues[rowIndex];
if (rowIndex == 0 && colIndex == 0) {
Vbox descr = new Vbox();
descr.setWidth("100%");
if (xValues != null) {
Div div = new Div();
div.setAlign("right");
div.appendChild(new Label(m_attributes[indexAttr1].getName()));
descr.appendChild(div);
}
if (yValues != null)
descr.appendChild(new Label(m_attributes[indexAttr2].getName()));
row.appendChild(descr);
} else if (// column labels
rowIndex == 0) {
if (xValue != null) {
Div div = new Div();
div.setAlign("center");
div.appendChild(new Label(xValue.getName()));
row.appendChild(div);
} else
row.appendChild(new Label());
} else if (// row labels
colIndex == 0) {
if (yValue != null)
row.appendChild(new Label(yValue.getName()));
else
row.appendChild(new Label());
} else {
row.appendChild(getGridElement(xValue, yValue));
}
}
}
tabbox.setSelectedIndex(1);
m_setting = false;
}
Aggregations