Search in sources :

Example 1 with MAttributeValue

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);
    }
}
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 MAttributeValue

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;
}
Also used : Textbox(org.adempiere.webui.component.Textbox) NumberBox(org.adempiere.webui.component.NumberBox) Timestamp(java.sql.Timestamp) Date(java.util.Date) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttributeValue(org.compiere.model.MAttributeValue) ListItem(org.adempiere.webui.component.ListItem) Listbox(org.adempiere.webui.component.Listbox) MAttribute(org.compiere.model.MAttribute)

Example 3 with MAttributeValue

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);
    }
}
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 4 with MAttributeValue

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;
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) BigDecimal(java.math.BigDecimal)

Example 5 with MAttributeValue

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;
}
Also used : Div(org.zkoss.zul.Div) MAttributeValue(org.compiere.model.MAttributeValue) Label(org.adempiere.webui.component.Label) ListItem(org.adempiere.webui.component.ListItem) Row(org.adempiere.webui.component.Row) Vbox(org.zkoss.zul.Vbox) Rows(org.adempiere.webui.component.Rows)

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