Search in sources :

Example 11 with MAttributeSet

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

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

the class WPAttributeDialog method initAttributes.

//	init
/**
	 *	Dyanmic Init.
	 *  @return true if initialized
	 */
private boolean initAttributes() {
    Rows rows = new Rows();
    rows.setParent(centerLayout);
    if (m_M_Product_ID == 0 && !m_productWindow)
        return false;
    MAttributeSet as = null;
    if (m_M_Product_ID != 0) {
        //	Get Model
        m_product = MProduct.get(Env.getCtx(), m_M_Product_ID);
        if (m_product.getM_AttributeSetInstance_ID() > 0) {
            m_productASI = true;
            //  The product has an instance associated with it.
            if (m_M_AttributeSetInstance_ID != m_product.getM_AttributeSetInstance_ID()) {
                log.fine("Different ASI than what is specified on Product!");
            }
        } else {
            // Only show product attributes when in the product window.
            m_productASI = m_productWindow;
        }
        m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
        if (m_masi == null) {
            log.severe("No Model for M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + ", M_Product_ID=" + m_M_Product_ID);
            return false;
        }
        Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", m_masi.getM_AttributeSet_ID());
        //	Get Attribute Set
        as = m_masi.getMAttributeSet();
    } else {
        int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
        m_masi = new MAttributeSetInstance(Env.getCtx(), 0, M_AttributeSet_ID, null);
        as = m_masi.getMAttributeSet();
    }
    //	Product has no Attribute Set
    if (as == null) {
        FDialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
        return false;
    }
    //  always read/write.  The two are exclusive and can't co-exists.  
    if (//	Set Instance Attributes and dialog controls
    !m_productWindow || !m_productASI) {
        if (// Instance attributes possible.  Set up controls.
        !m_productASI) {
            Row row = new Row();
            //	New/Edit - Selection
            if (//	new
            m_M_AttributeSetInstance_ID == 0)
                cbNewEdit.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "NewRecord")));
            else
                cbNewEdit.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "EditRecord")));
            cbNewEdit.addEventListener(Events.ON_CHECK, this);
            row.appendChild(cbNewEdit);
            bSelect.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "SelectExisting")));
            bSelect.setImage(ServletFns.resolveThemeURL("~./images/PAttribute16.png"));
            bSelect.addEventListener(Events.ON_CLICK, this);
            row.appendChild(bSelect);
            rows.appendChild(row);
        }
        //	Add the Instance Attributes if any.  If its a product attribute set
        //  this will do nothing.
        // True = Instances
        MAttribute[] attributes = as.getMAttributes(true);
        log.fine("Instance Attributes=" + attributes.length);
        for (int i = 0; i < attributes.length; i++) addAttributeLine(rows, attributes[i], false, false);
    }
    //  Product attributes can be shown in any window but are read/write in the Product window only.
    //  This will do nothing if it is an instance attribute set. 
    // False = products
    MAttribute[] attributes = as.getMAttributes(false);
    log.fine("Product Attributes=" + attributes.length);
    for (int i = 0; i < attributes.length; i++) addAttributeLine(rows, attributes[i], true, !m_productWindow);
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        Row row = new Row();
        row.setParent(rows);
        m_row++;
        Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "Lot")));
        row.appendChild(label);
        row.appendChild(fieldLotString);
        fieldLotString.setText(m_masi.getLot());
        //	M_Lot_ID
        //	int AD_Column_ID = 9771;	//	M_AttributeSetInstance.M_Lot_ID
        //	fieldLot = new VLookup ("M_Lot_ID", false,false, true, 
        //		MLookupFactory.get(Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
        String sql = "SELECT M_Lot_ID, Name " + "FROM M_Lot l " + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p " + "WHERE p.M_AttributeSet_ID=" + m_masi.getM_AttributeSet_ID() + " AND p.M_Product_ID=l.M_Product_ID)";
        fieldLot = new Listbox();
        fieldLot.setMold("select");
        KeyNamePair[] keyNamePairs = DB.getKeyNamePairs(sql, true);
        for (KeyNamePair pair : keyNamePairs) {
            fieldLot.appendItem(pair.getName(), pair.getKey());
        }
        label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "M_Lot_ID")));
        row = new Row();
        row.setParent(rows);
        m_row++;
        row.appendChild(label);
        row.appendChild(fieldLot);
        if (m_masi.getM_Lot_ID() != 0) {
            for (int i = 1; i < fieldLot.getItemCount(); i++) {
                ListItem pp = fieldLot.getItemAtIndex(i);
                if ((Integer) pp.getValue() == m_masi.getM_Lot_ID()) {
                    fieldLot.setSelectedIndex(i);
                    fieldLotString.setReadonly(true);
                    break;
                }
            }
        }
        fieldLot.addEventListener(Events.ON_SELECT, this);
        //	New Lot Button
        if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0) {
            if (MRole.getDefault().isTableAccess(MLot.Table_ID, false) && MRole.getDefault().isTableAccess(MLotCtl.Table_ID, false) && !m_masi.isExcludeLot(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                row = new Row();
                row.setParent(rows);
                m_row++;
                row.appendChild(bLot);
                bLot.addEventListener(Events.ON_CLICK, this);
            }
        }
        //	Popup 
        //			fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this));    //  popup
        mZoom = new Menuitem(Msg.getMsg(Env.getCtx(), "Zoom"), ServletFns.resolveThemeURL("~./images/Zoom16.png"));
        mZoom.addEventListener(Events.ON_CLICK, this);
        popupMenu.appendChild(mZoom);
        this.appendChild(popupMenu);
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        Row row = new Row();
        row.setParent(rows);
        m_row++;
        Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "SerNo")));
        row.appendChild(label);
        row.appendChild(fieldSerNo);
        fieldSerNo.setText(m_masi.getSerNo());
        //	New SerNo Button
        if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0) {
            if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false) && !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                row = new Row();
                row.setParent(rows);
                m_row++;
                row.appendChild(bSerNo);
                bSerNo.addEventListener(Events.ON_CLICK, this);
            }
        }
    }
    //	GuaranteeDate
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        Row row = new Row();
        row.setParent(rows);
        m_row++;
        Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "GuaranteeDate")));
        if (m_M_AttributeSetInstance_ID == 0)
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
        else
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
        row.appendChild(label);
        row.appendChild(fieldGuaranteeDate);
    }
    if (m_row == 0) {
        FDialog.error(m_WindowNo, this, "PAttributeNoInfo");
        return false;
    }
    //	New/Edit Window
    if (!m_productWindow) {
        cbNewEdit.setChecked(m_M_AttributeSetInstance_ID == 0);
        cmd_newEdit();
    }
    //	Attrribute Set Instance Description
    Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "Description")));
    //		label.setLabelFor(fieldDescription);
    fieldDescription.setText(m_masi.getDescription());
    fieldDescription.setReadonly(true);
    Row row = new Row();
    row.setParent(rows);
    row.appendChild(label);
    row.appendChild(fieldDescription);
    return true;
}
Also used : Label(org.adempiere.webui.component.Label) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) MAttributeSet(org.compiere.model.MAttributeSet) Menuitem(org.zkoss.zul.Menuitem) Row(org.adempiere.webui.component.Row) KeyNamePair(org.compiere.util.KeyNamePair) ListItem(org.adempiere.webui.component.ListItem) Listbox(org.adempiere.webui.component.Listbox) Rows(org.adempiere.webui.component.Rows) MAttribute(org.compiere.model.MAttribute)

Example 13 with MAttributeSet

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

the class MovementGenerate method createLine.

//	generate
/**************************************************************************
	 * 	Create Line
	 *	@param Distribution order order
	 *	@param orderLine line
	 *	@param qty qty
	 *	@param storages storage info
	 *	@param force force delivery
	 */
private void createLine(MDDOrder order, MDDOrderLine orderLine, BigDecimal qty, MStorage[] storages, boolean force) {
    //	Complete last Shipment - can have multiple shipments
    if (m_lastC_BPartner_Location_ID != order.getC_BPartner_Location_ID())
        completeMovement();
    m_lastC_BPartner_Location_ID = order.getC_BPartner_Location_ID();
    //	Create New Shipment
    if (m_movement == null) {
        MLocator locator = MLocator.get(getCtx(), orderLine.getM_Locator_ID());
        m_movement = createMovement(order, m_movementDate);
        m_movement.setAD_Org_ID(locator.getAD_Org_ID());
        //m_movement.setM_Warehouse_ID(orderLine.getM_Warehouse_ID());	//	sets Org too
        m_movement.setIsInTransit(true);
        m_movement.setDD_Order_ID(order.getDD_Order_ID());
        if (order.getC_BPartner_ID() != order.getC_BPartner_ID())
            m_movement.setC_BPartner_ID(order.getC_BPartner_ID());
        if (order.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID())
            m_movement.setC_BPartner_Location_ID(order.getC_BPartner_Location_ID());
        //Look the document type based on organization
        int docTypeDO_ID = getDocType(MDocType.DOCBASETYPE_MaterialMovement, m_movement.getAD_Org_ID());
        if (docTypeDO_ID > 0)
            m_movement.setC_DocType_ID(docTypeDO_ID);
        if (!m_movement.save())
            throw new IllegalStateException("Could not create Movement");
    }
    //	Non Inventory Lines
    if (storages == null) {
        MMovementLine line = new MMovementLine(m_movement);
        line.setOrderLine(orderLine, Env.ZERO, false);
        //	Correct UOM
        line.setMovementQty(qty);
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setMovementQty(qty.multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine(line.toString());
        return;
    }
    //	Product
    MProduct product = orderLine.getProduct();
    boolean linePerASI = false;
    if (product.getM_AttributeSet_ID() != 0) {
        MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
        linePerASI = mas.isInstanceAttribute();
    }
    //	Inventory Lines
    ArrayList<MMovementLine> list = new ArrayList<MMovementLine>();
    BigDecimal toDeliver = qty;
    for (int i = 0; i < storages.length; i++) {
        MStorage storage = storages[i];
        BigDecimal deliver = toDeliver;
        //	Not enough On Hand
        if (deliver.compareTo(storage.getQtyOnHand()) > 0 && //	positive storage
        storage.getQtyOnHand().signum() >= 0) {
            if (//	Adjust to OnHand Qty  
            !force || //	if force not on last location
            (force && i + 1 != storages.length))
                deliver = storage.getQtyOnHand();
        }
        if (//	zero deliver
        deliver.signum() == 0)
            continue;
        int M_Locator_ID = storage.getM_Locator_ID();
        //
        MMovementLine line = null;
        if (//	find line with Locator
        !linePerASI) {
            for (int ll = 0; ll < list.size(); ll++) {
                MMovementLine test = (MMovementLine) list.get(ll);
                if (test.getM_Locator_ID() == M_Locator_ID) {
                    line = test;
                    break;
                }
            }
        }
        if (//	new line
        line == null) {
            line = new MMovementLine(m_movement);
            line.setOrderLine(orderLine, deliver, false);
            line.setMovementQty(deliver);
            list.add(line);
        } else
            //	existing line
            line.setMovementQty(line.getMovementQty().add(deliver));
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setMovementQty(line.getMovementQty().multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (linePerASI)
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
        toDeliver = toDeliver.subtract(deliver);
        //	Temp adjustment
        storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver));
        //
        if (toDeliver.signum() == 0)
            break;
    }
    if (toDeliver.signum() != 0)
        throw new IllegalStateException("Not All Delivered - Remainder=" + toDeliver);
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) MMovementLine(org.compiere.model.MMovementLine) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet)

Example 14 with MAttributeSet

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

the class MDDOrderLine method beforeSave.

//	setQtyOrdered
/**************************************************************************
	 * 	Before Save
	 *	@param newRecord
	 *	@return true if it can be sabed
	 */
protected boolean beforeSave(boolean newRecord) {
    if (newRecord && getParent().isComplete()) {
        log.saveError("ParentComplete", Msg.translate(getCtx(), "DD_OrderLine"));
        return false;
    }
    /*if (getC_BPartner_ID() == 0 || getC_BPartner_Location_ID() == 0
			|| getM_Warehouse_ID() == 0)
			setOrder (getParent());*/
    if (m_M_PriceList_ID == 0)
        setHeaderInfo(getParent());
    //	R/O Check - Product/Warehouse Change
    if (!newRecord && (is_ValueChanged("M_Product_ID") || is_ValueChanged("M_Locator_ID") || is_ValueChanged("M_LocatorTo_ID"))) {
        if (!canChangeWarehouse())
            return false;
    }
    //	Charge
    if (getC_Charge_ID() != 0 && getM_Product_ID() != 0)
        setM_Product_ID(0);
    //	No Product
    if (getM_Product_ID() == 0)
        setM_AttributeSetInstance_ID(0);
    //	UOM
    if (getC_UOM_ID() == 0 && (getM_Product_ID() != 0 || getC_Charge_ID() != 0)) {
        int C_UOM_ID = MUOM.getDefault_UOM_ID(getCtx());
        if (C_UOM_ID > 0)
            setC_UOM_ID(C_UOM_ID);
    }
    //	Qty Precision
    if (newRecord || is_ValueChanged("QtyEntered"))
        setQtyEntered(getQtyEntered());
    if (newRecord || is_ValueChanged("QtyOrdered"))
        setQtyOrdered(getQtyOrdered());
    //	Qty on instance ASI for SO
    if (m_IsSOTrx && getM_AttributeSetInstance_ID() != 0 && (newRecord || is_ValueChanged("M_Product_ID") || is_ValueChanged("M_AttributeSetInstance_ID") || is_ValueChanged("M_Warehouse_ID"))) {
        MProduct product = getProduct();
        if (product.isStocked()) {
            int M_AttributeSet_ID = product.getM_AttributeSet_ID();
            boolean isInstance = M_AttributeSet_ID != 0;
            if (isInstance) {
                MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
                isInstance = mas.isInstanceAttribute();
            }
            //	Max
            if (isInstance) {
                MLocator locator_from = MLocator.get(getCtx(), getM_Locator_ID());
                MStorage[] storages = MStorage.getWarehouse(getCtx(), locator_from.getM_Warehouse_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), M_AttributeSet_ID, false, null, true, get_TrxName());
                BigDecimal qty = Env.ZERO;
                for (int i = 0; i < storages.length; i++) {
                    if (storages[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID())
                        qty = qty.add(storages[i].getQtyOnHand());
                }
                if (getQtyOrdered().compareTo(qty) > 0) {
                    log.warning("Qty - Stock=" + qty + ", Ordered=" + getQtyOrdered());
                    log.saveError("QtyInsufficient", "=" + qty);
                    return false;
                }
            }
        }
    //	stocked
    }
    //	FreightAmt Not used
    if (Env.ZERO.compareTo(getFreightAmt()) != 0)
        setFreightAmt(Env.ZERO);
    //	Get Line No
    if (getLine() == 0) {
        String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM DD_OrderLine WHERE DD_Order_ID=?";
        int ii = DB.getSQLValue(get_TrxName(), sql, getDD_Order_ID());
        setLine(ii);
    }
    return true;
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet)

Example 15 with MAttributeSet

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

the class InfoPAttribute method addAttributes.

//	dynInit
/**
	 * 	Add Attributes
	 *	@return rows
	 */
private int addAttributes() {
    int row = 0;
    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) {
                CPanel group = new CPanel();
                group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsProductAttribute")));
                group.add(Box.createVerticalStrut(VLine.SPACE));
                centerPanel.add(group, new ALayoutConstraint(row++, 0));
                productLine = true;
            }
            //	Add label for Instances attributes
            if (!instanceLine && isInstanceAttribute) {
                CPanel group = new CPanel();
                group.add(Box.createVerticalStrut(VLine.SPACE));
                group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsInstanceAttribute")));
                group.add(Box.createVerticalStrut(VLine.SPACE));
                centerPanel.add(group, new ALayoutConstraint(row++, 0));
                instanceLine = true;
            }
            //
            CLabel label = new CLabel(name);
            if (description != null && description.length() > 0)
                label.setToolTipText(description);
            centerPanel.add(label, new ALayoutConstraint(row++, 0));
            Component field = null;
            if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType))
                field = new VComboBox(getAttributeList(attribute_ID));
            else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
                field = new VNumber(name, false, false, true, DisplayType.Number, name);
            else
                field = new VString(name, false, false, true, 10, 40, null, null);
            label.setLabelFor(field);
            centerPanel.add(field, null);
            //
            field.setName(String.valueOf(attribute_ID));
            if (isInstanceAttribute)
                m_instanceEditors.add(field);
            else
                m_productEditors.add(field);
            //	To (numbers)
            Component fieldTo = null;
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
                fieldTo = new VNumber(name, false, false, true, DisplayType.Number, name);
                centerPanel.add(new CLabel("-"), null);
                centerPanel.add(fieldTo, null);
            }
            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) {
            CPanel group = new CPanel();
            group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsInstanceAttribute")));
            group.add(Box.createVerticalStrut(VLine.SPACE));
            centerPanel.add(group, new ALayoutConstraint(row++, 0));
            instanceLine = true;
        }
    }
    return row;
}
Also used : CLabel(org.compiere.swing.CLabel) CPanel(org.compiere.swing.CPanel) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) PreparedStatement(java.sql.PreparedStatement) VLine(org.compiere.grid.ed.VLine) VNumber(org.compiere.grid.ed.VNumber) VString(org.compiere.grid.ed.VString) VComboBox(org.compiere.grid.ed.VComboBox) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) MAttributeSet(org.compiere.model.MAttributeSet) VString(org.compiere.grid.ed.VString) ResultSet(java.sql.ResultSet) Component(java.awt.Component)

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