Search in sources :

Example 6 with MAttributeSet

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

the class InfoPAttribute method dynInit.

//	jbInit
/**
	 * 	Dynamic Init of the Center Panel
	 */
private void dynInit() {
    int row = addAttributes();
    boolean isGuarantee = true;
    boolean isSerial = true;
    boolean isLot = true;
    if (p_M_AttributeSet_ID > 0) {
        MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
        isGuarantee = as.isGuaranteeDate();
        isSerial = as.isSerNo();
        isLot = as.isLot();
    }
    //
    String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
    guaranteeDateSelection = new VComboBox(new Object[] { s + " <", s + " =", s + " >" });
    //	guaranteeDateSelection.setPreferredSize();
    initLotSelection();
    //	Fixed Instance Selection Fields		
    if (isSerial) {
        centerPanel.add(serNoLabel, new ALayoutConstraint(row++, 0));
        centerPanel.add(serNoField, null);
    }
    if (isLot) {
        centerPanel.add(lotLabel, new ALayoutConstraint(row++, 0));
        centerPanel.add(lotField, null);
        centerPanel.add(lotLabel2, new ALayoutConstraint(row++, 0));
        centerPanel.add(lotSelection, null);
    }
    if (isGuarantee) {
        centerPanel.add(guaranteeDateSelection, new ALayoutConstraint(row++, 0));
        centerPanel.add(guaranteeDateField, null);
    }
    //
    Dimension d = centerPanel.getPreferredSize();
    d.width = 400;
    centerPanel.setPreferredSize(d);
}
Also used : ALayoutConstraint(org.compiere.apps.ALayoutConstraint) VString(org.compiere.grid.ed.VString) VComboBox(org.compiere.grid.ed.VComboBox) Dimension(java.awt.Dimension) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) MAttributeSet(org.compiere.model.MAttributeSet)

Example 7 with MAttributeSet

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

the class InfoPAttributePanel method dynInit.

//	jbInit
/**
	 * 	Dynamic Init of the Center Panel
	 */
private void dynInit() {
    addAttributes();
    boolean isGuarantee = true;
    boolean isSerial = true;
    boolean isLot = true;
    if (p_M_AttributeSet_ID > 0) {
        MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
        isGuarantee = as.isGuaranteeDate();
        isSerial = as.isSerNo();
        isLot = as.isLot();
    }
    //
    String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
    guaranteeDateSelection = new Listbox();
    guaranteeDateSelection.setRows(0);
    guaranteeDateSelection.setMultiple(false);
    guaranteeDateSelection.setMold("select");
    guaranteeDateSelection.setWidth("150px");
    guaranteeDateSelection.appendItem(s + " <", s + " <");
    guaranteeDateSelection.appendItem(s + " =", s + " =");
    guaranteeDateSelection.appendItem(s + " >", s + " >");
    guaranteeDateSelection.setAttribute("zk_component_ID", "InfoPAttributePanel_guaranteeDateSelection");
    initLotSelection();
    //	Fixed Instance Selection Fields
    Row row;
    Div div;
    if (isSerial) {
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(serNoLabel);
        row.appendChild(div);
        row.appendChild(serNoField.getComponent());
        serNoField.getComponent().setWidth("150px");
        serNoField.getComponent().setAttribute("zk_component_ID", "InfoPAttributePanel_serNoField");
    }
    if (isLot) {
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(lotLabel);
        row.appendChild(div);
        row.appendChild(lotField.getComponent());
        lotField.getComponent().setWidth("150px");
        lotField.getComponent().setAttribute("zk_component_ID", "InfoPAttributePanel_lotField");
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(lotLabel2);
        row.appendChild(div);
        row.appendChild(lotSelection);
    }
    if (isGuarantee) {
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(guaranteeDateSelection);
        row.appendChild(div);
        row.appendChild(guaranteeDateField);
        guaranteeDateField.setAttribute("zk_component_ID", "InfoPAttributePanel_guaranteeDateField");
    }
}
Also used : Div(org.zkoss.zul.Div) Row(org.adempiere.webui.component.Row) Listbox(org.adempiere.webui.component.Listbox) MAttributeSet(org.compiere.model.MAttributeSet)

Example 8 with MAttributeSet

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

the class InfoPAttributePanel method addAttributes.

//	dynInit
/**
	 * 	Add Attributes
	 *	@return rows
	 */
private int addAttributes() {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String whereAttributeSet;
    if (p_M_AttributeSet_ID > 0)
        whereAttributeSet = "AND M_Attribute_ID IN (SELECT M_Attribute_ID FROM M_AttributeUse WHERE M_AttributeSet_ID=" + p_M_AttributeSet_ID + ")";
    else
        whereAttributeSet = "";
    String sql = MRole.getDefault().addAccessSQL("SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute " + "FROM M_Attribute " + "WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY IsInstanceAttribute, Name", "M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    boolean instanceLine = false;
    boolean productLine = false;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int attribute_ID = rs.getInt(1);
            String name = rs.getString(2);
            String description = rs.getString(3);
            String attributeValueType = rs.getString(4);
            boolean isInstanceAttribute = "Y".equals(rs.getString(5));
            // Add label for product attributes if there are any
            if (!productLine && !isInstanceAttribute) {
                Row row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Label group = new Label(Msg.translate(Env.getCtx(), "IsProductAttribute"));
                row.appendChild(group);
                rows.appendChild(row);
                row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Separator separator = new Separator();
                separator.setBar(true);
                row.appendChild(separator);
                rows.appendChild(row);
                productLine = true;
            }
            //	Add label for Instances attributes
            if (!instanceLine && isInstanceAttribute) {
                Row row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
                row.appendChild(group);
                rows.appendChild(row);
                row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Separator separator = new Separator();
                separator.setBar(true);
                row.appendChild(separator);
                rows.appendChild(row);
                instanceLine = true;
            }
            //
            Row row = new Row();
            rows.appendChild(row);
            Label label = new Label(name);
            if (description != null && description.length() > 0)
                label.setTooltiptext(description);
            Div div = new Div();
            div.setAlign("right");
            div.appendChild(label);
            row.appendChild(div);
            Component field = null;
            if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
                field = new Listbox();
                ((Listbox) field).setRows(0);
                ((Listbox) field).setMultiple(false);
                ((Listbox) field).setMold("select");
                ((Listbox) field).setWidth("150px");
                KeyNamePair[] knp = getAttributeList(attribute_ID);
                for (int i = 0; i < knp.length; i++) ((Listbox) field).appendItem(knp[i].getName(), knp[i]);
            } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
                field = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
                ((NumberBox) field).setWidth("150px");
            } else {
                field = new WStringEditor(name, false, false, true, 10, 40, null, null).getComponent();
                ((Textbox) field).setWidth("150px");
            }
            row.appendChild(field);
            //
            field.setId(String.valueOf(attribute_ID));
            // If name is null, replace it with "_"
            if (name.equals("")) {
                name = "_";
            }
            field.setAttribute("zk_component_ID", "InfoPAttributePanel_field_" + name.replaceAll("[^a-zA-Z0-9_]", "_"));
            //
            if (isInstanceAttribute)
                m_instanceEditors.add(field);
            else
                m_productEditors.add(field);
            //	To (numbers)
            Component fieldTo = null;
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
                fieldTo = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
                ((NumberBox) fieldTo).setWidth("150px");
                row = new Row();
                rows.appendChild(row);
                div = new Div();
                div.setAlign("right");
                div.appendChild(new Label("-"));
                row.appendChild(div);
                row.appendChild(fieldTo);
            }
            if (fieldTo != null)
                fieldTo.setAttribute("zk_component_ID", "InfoPAttributePanel_fieldTo_" + name);
            if (isInstanceAttribute)
                m_instanceEditorsTo.add(fieldTo);
            else
                m_productEditorsTo.add(fieldTo);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    // print instance line if not printed
    if (!instanceLine) {
        boolean isGuarantee = true;
        boolean isSerial = true;
        boolean isLot = true;
        if (p_M_AttributeSet_ID > 0) {
            MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
            isGuarantee = as.isGuaranteeDate();
            isSerial = as.isSerNo();
            isLot = as.isLot();
        }
        if (isGuarantee || isSerial || isLot) {
            Row row = new Row();
            rows.appendChild(row);
            row.setSpans("2");
            Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
            row.appendChild(group);
            rows.appendChild(row);
            row = new Row();
            rows.appendChild(row);
            row.setSpans("2");
            Separator separator = new Separator();
            separator.setBar(true);
            row.appendChild(separator);
            rows.appendChild(row);
            instanceLine = true;
        }
    }
    return 0;
}
Also used : Label(org.adempiere.webui.component.Label) PreparedStatement(java.sql.PreparedStatement) NumberBox(org.adempiere.webui.component.NumberBox) WStringEditor(org.adempiere.webui.editor.WStringEditor) MAttributeSet(org.compiere.model.MAttributeSet) Div(org.zkoss.zul.Div) ResultSet(java.sql.ResultSet) Row(org.adempiere.webui.component.Row) KeyNamePair(org.compiere.util.KeyNamePair) Component(org.zkoss.zk.ui.Component) Listbox(org.adempiere.webui.component.Listbox) Separator(org.zkoss.zul.Separator) WNumberEditor(org.adempiere.webui.editor.WNumberEditor)

Example 9 with MAttributeSet

use of org.compiere.model.MAttributeSet 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 10 with MAttributeSet

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

the class HTMLMessenger method getAttributeSetInstanceInfo.

public String getAttributeSetInstanceInfo(MAttributeSetInstance asi, boolean singleRow) {
    MAttributeSet as = new MAttributeSet(Env.getCtx(), asi.getM_AttributeSet_ID(), null);
    StorageReasoner mr = new StorageReasoner();
    int[] ids = mr.getAttributeIDs(asi);
    MAttributeInstance ai = null;
    MAttribute a = null;
    MAttributeValue av = null;
    StringBuffer sb = new StringBuffer();
    String value = null;
    Object[] obj = null;
    for (int i = 0; i < ids.length; i++) {
        ai = new MAttributeInstance(Env.getCtx(), ids[i], asi.get_ID(), (String) null, null);
        ai.load(null);
        a = new MAttribute(Env.getCtx(), ai.getM_Attribute_ID(), null);
        av = new MAttributeValue(Env.getCtx(), ai.getM_AttributeValue_ID(), null);
        // e.g. the list validation type 'L'
        if (ai.getValue() == null) {
            value = av.getValue();
        } else // Takes the value of the M_AttributeInstance itself
        {
            // Round number values to a scale of 2, if type is 'N'
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) {
                BigDecimal number = ai.getValueNumber();
                value = number.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            } else {
                value = ai.getValue();
            }
        }
        obj = new Object[] { a.getName(), value };
        sb.append(MessageFormat.format(ATTRIBUTE_INFO_PATTERN, obj));
        if (singleRow) {
            sb.append("&nbsp;");
        } else {
            sb.append("<br>");
        }
    }
    return sb.toString();
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) StorageReasoner(org.eevolution.model.reasoner.StorageReasoner) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Aggregations

MAttributeSet (org.compiere.model.MAttributeSet)22 BigDecimal (java.math.BigDecimal)7 MAttribute (org.compiere.model.MAttribute)7 MProduct (org.compiere.model.MProduct)6 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)5 Listbox (org.adempiere.webui.component.Listbox)4 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Timestamp (java.sql.Timestamp)3 Row (org.adempiere.webui.component.Row)3 MAttributeInstance (org.compiere.model.MAttributeInstance)3 MAttributeValue (org.compiere.model.MAttributeValue)3 KeyNamePair (org.compiere.util.KeyNamePair)3 Dimension (java.awt.Dimension)2 Label (org.adempiere.webui.component.Label)2 ListItem (org.adempiere.webui.component.ListItem)2 NumberBox (org.adempiere.webui.component.NumberBox)2 VComboBox (org.compiere.grid.ed.VComboBox)2 VString (org.compiere.grid.ed.VString)2