Search in sources :

Example 1 with VComboBox

use of org.compiere.grid.ed.VComboBox in project adempiere by adempiere.

the class VPaySelect method actionPerformed.

//	dispose
/**************************************************************************
	 *  ActionListener
	 *  @param e event
	 */
public void actionPerformed(ActionEvent e) {
    boolean triggerRefresh = false;
    if (!m_loadedOK)
        return;
    Object source = e.getSource();
    String cmd = e.getActionCommand();
    //  Trigger an update if any criteria change
    if (source instanceof VComboBox && ((VComboBox) source).getParent() instanceof VLookup) {
        source = ((VComboBox) source).getParent();
        VLookup vl = ((VLookup) source);
        //  events that don't have changes from the last action.
        if (cmd.equals("comboBoxChanged")) {
            if (!vl.hasChanged())
                return;
            else
                triggerRefresh = true;
        } else if (cmd.equals("comboBoxEdited")) {
            if (!vl.hasChanged()) {
                vl.requestFocus();
                return;
            }
            triggerRefresh = true;
        }
    } else if (source instanceof CTextField) {
        CTextField tf = ((CTextField) source);
        if (tf.getParent() instanceof VLookup) {
            // instead.
            return;
        } else if (//  The change may have come from another field
        tf.hasChanged()) {
            triggerRefresh = true;
        }
    } else if (e.getSource() instanceof VCheckBox) {
        //  Check box changes generally always cause a refresh
        //  Capture changes that don't 
        triggerRefresh = true;
        VCheckBox cb = (VCheckBox) e.getSource();
        if (cb.getName().equals("AutoQuery")) {
            //  Only trigger a refresh if the check box is selected
            if (!cb.isSelected()) {
                return;
            }
        }
    } else if (cmd.equals("comboBoxChanged")) {
        VComboBox vcb = (VComboBox) source;
        if (!vcb.hasChanged()) {
            return;
        } else {
            triggerRefresh = true;
        }
    } else if (cmd.equals("comboBoxEdited")) {
        VComboBox vcb = (VComboBox) source;
        if (!vcb.hasChanged()) {
            vcb.requestFocus();
            return;
        }
        triggerRefresh = true;
    }
    if (triggerRefresh && e.getSource() == fieldBankAccount) {
        loadBankInfo();
    }
    //  Generate PaySelection
    if (e.getSource() == bGenerate) {
        generatePaySelect();
        dispose();
    } else if (e.getSource() == bCancel)
        dispose();
    // Refresh if the autoquery feature is selected or the refresh button is clicked.
    if (e.getSource() == bRefresh || (checkAutoQuery.isSelected() && triggerRefresh)) {
        setFieldOldValues();
        loadTableInfo();
    }
}
Also used : CTextField(org.compiere.swing.CTextField) VLookup(org.compiere.grid.ed.VLookup) VComboBox(org.compiere.grid.ed.VComboBox) VCheckBox(org.compiere.grid.ed.VCheckBox)

Example 2 with VComboBox

use of org.compiere.grid.ed.VComboBox in project adempiere by adempiere.

the class InfoPAttribute method createQuery.

//	actionPerformed
/**
	 * 	Create Query
	 *  <code>
	 * 	Available synonyms:
	 *		M_Product p
	 *		M_ProductPrice pr
	 *		M_AttributeSet pa
	 *	</code>
	 *	@return query
	 */
private String createQuery() {
    /** Base Query
		SELECT *
		FROM M_Product p
 		 INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID)
 		 LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)
		WHERE
		**/
    /***	Instance Attributes		*/
    StringBuffer sb = new StringBuffer();
    //	Serial No
    String s = serNoField.getText();
    if (s != null && s.length() > 0) {
        sb.append(" AND asi.SerNo");
        if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
            sb.append("=");
        else
            sb.append(" LIKE ");
        sb.append(DB.TO_STRING(s));
    }
    //	Lot Number
    s = lotField.getText();
    if (s != null && s.length() > 0) {
        sb.append(" AND asi.Lot");
        if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
            sb.append("=");
        else
            sb.append(" LIKE ");
        sb.append(DB.TO_STRING(s));
    }
    //	Lot ID
    KeyNamePair pp = (KeyNamePair) lotSelection.getSelectedItem();
    if (pp != null && pp.getKey() != -1) {
        int ID = pp.getKey();
        sb.append(" AND asi.M_Lot_ID=").append(ID);
    }
    //	Guarantee Date
    Timestamp ts = (Timestamp) guaranteeDateField.getValue();
    if (ts != null) {
        sb.append(" AND TRUNC(asi.GuaranteeDate, 'DD')");
        //	 < = >
        int index = guaranteeDateSelection.getSelectedIndex();
        if (index == 0)
            sb.append("<");
        else if (index == 1)
            sb.append("=");
        else
            sb.append(">");
        sb.append(DB.TO_DATE(ts, true));
    }
    //	Instance Editors
    for (int i = 0; i < m_instanceEditors.size(); i++) {
        StringBuffer iAttr = new StringBuffer();
        Component c = (Component) m_instanceEditors.get(i);
        Component cTo = (Component) m_instanceEditorsTo.get(i);
        int M_Attribute_ID = Integer.parseInt(c.getName());
        if (c instanceof VComboBox) {
            VComboBox field = (VComboBox) c;
            pp = (KeyNamePair) field.getSelectedItem();
            if (pp != null && pp.getKey() != -1) {
                iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND M_AttributeValue_ID=").append(pp.getKey());
            }
        } else if (c instanceof VNumber) {
            VNumber field = (VNumber) c;
            BigDecimal value = (BigDecimal) field.getValue();
            VNumber fieldTo = (VNumber) cTo;
            BigDecimal valueTo = (BigDecimal) fieldTo.getValue();
            if (value != null || valueTo != null) {
                iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND ValueNumber");
                if (value != null && valueTo == null)
                    iAttr.append("=").append(value);
                else if (value == null && valueTo != null)
                    iAttr.append("<=").append(valueTo);
                else if (value != null && valueTo != null)
                    iAttr.append(" BETWEEN ").append(value).append(" AND ").append(valueTo);
            }
        } else {
            VString field = (VString) c;
            String value = field.getText();
            if (value != null && value.length() > 0) {
                iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND Value");
                if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
                    iAttr.append("=");
                else
                    iAttr.append(" LIKE ");
                iAttr.append(DB.TO_STRING(value));
            }
        }
        //	Add to where
        if (iAttr.length() > 0)
            sb.append(" AND asi.M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance " + "WHERE ").append(iAttr).append(")");
    }
    //	finish Instance Attributes
    if (sb.length() > 0) {
        sb.insert(0, " AND EXISTS (SELECT * FROM M_Storage s" + " INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) " + "WHERE s.M_Product_ID=p.M_Product_ID");
        sb.append(")");
    }
    //	Product Attributes 
    for (int i = 0; i < m_productEditors.size(); i++) {
        StringBuffer pAttr = new StringBuffer();
        Component c = (Component) m_productEditors.get(i);
        Component cTo = (Component) m_productEditorsTo.get(i);
        int M_Attribute_ID = Integer.parseInt(c.getName());
        if (c instanceof VComboBox) {
            VComboBox field = (VComboBox) c;
            pp = (KeyNamePair) field.getSelectedItem();
            if (pp != null && pp.getKey() != -1) {
                pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND M_AttributeValue_ID=").append(pp.getKey());
            }
        } else if (c instanceof VNumber) {
            VNumber field = (VNumber) c;
            BigDecimal value = (BigDecimal) field.getValue();
            VNumber fieldTo = (VNumber) cTo;
            BigDecimal valueTo = (BigDecimal) fieldTo.getValue();
            if (value != null || valueTo != null) {
                pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND ValueNumber");
                if (value != null && valueTo == null)
                    pAttr.append("=").append(value);
                else if (value == null && valueTo != null)
                    pAttr.append("<=").append(valueTo);
                else if (value != null && valueTo != null)
                    pAttr.append(" BETWEEN ").append(value).append(" AND ").append(valueTo);
            }
        } else {
            VString field = (VString) c;
            String value = field.getText();
            if (value != null && value.length() > 0) {
                pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND Value");
                if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
                    pAttr.append("=");
                else
                    pAttr.append(" LIKE ");
                pAttr.append(DB.TO_STRING(value));
            }
        }
        //	Add to Where
        if (pAttr.length() > 0)
            sb.append(" AND p.M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID " + "FROM M_AttributeInstance WHERE ").append(pAttr).append(")");
    }
    //
    m_query = null;
    if (sb.length() > 0)
        m_query = sb.toString();
    log.config(m_query);
    return m_query;
}
Also used : VString(org.compiere.grid.ed.VString) VNumber(org.compiere.grid.ed.VNumber) VString(org.compiere.grid.ed.VString) KeyNamePair(org.compiere.util.KeyNamePair) VComboBox(org.compiere.grid.ed.VComboBox) Component(java.awt.Component) Timestamp(java.sql.Timestamp) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) BigDecimal(java.math.BigDecimal)

Example 3 with VComboBox

use of org.compiere.grid.ed.VComboBox 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 4 with VComboBox

use of org.compiere.grid.ed.VComboBox in project adempiere by adempiere.

the class InfoPAttribute method setDisplay.

/**
	 *   Set the display text
	 */
private void setDisplay() {
    StringBuffer display = new StringBuffer();
    if (serNoField != null && serNoField.getValue().toString().length() > 0)
        display.append(serNoField.getValue().toString() + "-");
    if (lotField != null && lotField.getValue().toString().length() > 0)
        display.append(lotField.getValue().toString() + "-");
    if (lotSelection != null && lotSelection.getDisplay().length() > 0)
        display.append(lotSelection.getDisplay() + "-");
    if (guaranteeDateField != null && guaranteeDateField.getValue() != null)
        display.append(guaranteeDateSelection.getDisplay() + guaranteeDateField.getValue().toString() + "-");
    for (int i = 0; i < m_productEditors.size(); i++) {
        Component c = (Component) m_productEditors.get(i);
        Component cTo = (Component) m_productEditorsTo.get(i);
        if (c instanceof VComboBox) {
            VComboBox field = (VComboBox) c;
            display.append(field.getDisplay() + "-");
        } else if (c instanceof VNumber) {
            VNumber field = (VNumber) c;
            display.append(field.getDisplay() + "-");
            VNumber fieldTo = (VNumber) cTo;
            display.append(fieldTo.getDisplay() + "-");
        } else {
            VString field = (VString) c;
            display.append(field.getDisplay() + "-");
        }
    }
    for (int i = 0; i < m_instanceEditors.size(); i++) {
        Component c = (Component) m_instanceEditors.get(i);
        Component cTo = (Component) m_instanceEditorsTo.get(i);
        if (c instanceof VComboBox) {
            VComboBox field = (VComboBox) c;
            display.append(field.getDisplay() + "-");
        } else if (c instanceof VNumber) {
            VNumber field = (VNumber) c;
            display.append(field.getDisplay() + "-");
            VNumber fieldTo = (VNumber) cTo;
            display.append(fieldTo.getDisplay() + "-");
        } else {
            VString field = (VString) c;
            display.append(field.getDisplay() + "-");
        }
    }
    //  TODO - there is a more elegant way to do this.
    while (display.toString().contains("--") && display.length() > 1) {
        display.delete(display.indexOf("--"), display.indexOf("--") + 1);
    }
    while (display.toString().startsWith("-") && display.length() >= 1) {
        display.delete(0, 1);
    }
    while (display.toString().endsWith("-") && display.length() >= 1) {
        display.delete(display.length() - 1, display.length());
    }
    m_display = display.toString();
}
Also used : VString(org.compiere.grid.ed.VString) VNumber(org.compiere.grid.ed.VNumber) VComboBox(org.compiere.grid.ed.VComboBox) Component(java.awt.Component) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 5 with VComboBox

use of org.compiere.grid.ed.VComboBox in project adempiere by adempiere.

the class InfoPAttribute method initLotSelection.

//	getAttributeList
/**
	 * 	Initialize Lot Selection
	 */
private void initLotSelection() {
    ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
    list.add(new KeyNamePair(-1, ""));
    String whereAttributeSet;
    if (p_M_AttributeSet_ID > 0)
        whereAttributeSet = "AND M_Product_ID IN (SELECT M_Product_ID FROM M_Product WHERE M_AttributeSet_ID=" + p_M_AttributeSet_ID + ")";
    else
        whereAttributeSet = "";
    String sql = MRole.getDefault().addAccessSQL("SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY 2", "M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Create List
    KeyNamePair[] items = new KeyNamePair[list.size()];
    list.toArray(items);
    lotSelection = new VComboBox(items);
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) VString(org.compiere.grid.ed.VString) VComboBox(org.compiere.grid.ed.VComboBox)

Aggregations

VComboBox (org.compiere.grid.ed.VComboBox)11 VLookup (org.compiere.grid.ed.VLookup)6 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)5 VString (org.compiere.grid.ed.VString)5 VNumber (org.compiere.grid.ed.VNumber)4 Component (java.awt.Component)3 Dimension (java.awt.Dimension)3 VCheckBox (org.compiere.grid.ed.VCheckBox)3 CPanel (org.compiere.swing.CPanel)3 CTextField (org.compiere.swing.CTextField)3 GridBagConstraints (java.awt.GridBagConstraints)2 Insets (java.awt.Insets)2 BigDecimal (java.math.BigDecimal)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 MAttributeSet (org.compiere.model.MAttributeSet)2 MLookup (org.compiere.model.MLookup)2 KeyNamePair (org.compiere.util.KeyNamePair)2 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1