Search in sources :

Example 1 with VLine

use of org.compiere.grid.ed.VLine 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

Component (java.awt.Component)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)1 VComboBox (org.compiere.grid.ed.VComboBox)1 VLine (org.compiere.grid.ed.VLine)1 VNumber (org.compiere.grid.ed.VNumber)1 VString (org.compiere.grid.ed.VString)1 MAttributeSet (org.compiere.model.MAttributeSet)1 CLabel (org.compiere.swing.CLabel)1 CPanel (org.compiere.swing.CPanel)1