Search in sources :

Example 16 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VAttributeGrid method createGrid.

/**
	 * 	Create Grid
	 */
private void createGrid() {
    if (attributeCombo1 == null || m_setting)
        //	init
        return;
    int indexAttr1 = attributeCombo1.getSelectedIndex();
    int indexAttr2 = attributeCombo2.getSelectedIndex();
    if (indexAttr1 == indexAttr2) {
        log.warning("Same Attribute Selected");
        tabbedPane.setSelectedIndex(0);
        return;
    }
    m_setting = true;
    m_M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null)
        m_M_PriceList_Version_ID = pl.getKey();
    m_M_Warehouse_ID = 0;
    KeyNamePair wh = (KeyNamePair) pickWarehouse.getSelectedItem();
    if (wh != null)
        m_M_Warehouse_ID = wh.getKey();
    //	x dimension
    int cols = 2;
    MAttributeValue[] xValues = null;
    if (indexAttr1 > 0)
        xValues = m_attributes[indexAttr1 - 1].getMAttributeValues();
    if (xValues != null) {
        cols = xValues.length;
        log.info("X - " + m_attributes[indexAttr1 - 1].getName() + " #" + xValues.length);
    }
    //	y dimension
    int rows = 2;
    MAttributeValue[] yValues = null;
    if (indexAttr2 > 0)
        yValues = m_attributes[indexAttr2 - 1].getMAttributeValues();
    if (yValues != null) {
        rows = yValues.length;
        log.info("Y - " + m_attributes[indexAttr2 - 1].getName() + " #" + yValues.length);
    }
    //
    gridPanel.removeAll();
    CPanel grid = new CPanel(new GridLayout(rows, cols, 5, 5));
    gridPanel.add(modePanel, BorderLayout.NORTH);
    gridPanel.add(new CScrollPane(grid), BorderLayout.CENTER);
    //
    log.info("Rows=" + rows + " - Cols=" + cols);
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            MAttributeValue xValue = null;
            if (xValues != null)
                xValue = xValues[col];
            MAttributeValue yValue = null;
            if (yValues != null)
                yValue = yValues[row];
            //
            if (row == 0 && col == 0) {
                CPanel descr = new CPanel(new GridLayout(2, 1, 0, 0));
                if (xValues != null)
                    descr.add(new JLabel(m_attributes[indexAttr1 - 1].getName(), JLabel.TRAILING));
                if (yValues != null)
                    descr.add(new JLabel(m_attributes[indexAttr2 - 1].getName()));
                grid.add(descr);
            } else if (//	column labels
            row == 0) {
                if (xValue != null) {
                    grid.add(new JLabel(xValue.getName(), JLabel.TRAILING));
                } else
                    grid.add(new JLabel());
            } else if (//	row labels
            col == 0) {
                if (yValue != null)
                    grid.add(new JLabel(yValue.getName()));
                else
                    grid.add(new JLabel());
            } else {
                grid.add(getGridElement(xValue, yValue));
            }
        }
    }
    //
    tabbedPane.setSelectedIndex(1);
    m_setting = false;
    m_frame.pack();
}
Also used : GridLayout(java.awt.GridLayout) CScrollPane(org.compiere.swing.CScrollPane) MAttributeValue(org.compiere.model.MAttributeValue) CPanel(org.compiere.swing.CPanel) JLabel(javax.swing.JLabel) KeyNamePair(org.compiere.util.KeyNamePair) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 17 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VCreateFromInvoiceUI method initBPShipmentDetails.

/**
	 * Load PBartner dependent Order/Invoice/Shipment Field.
	 * @param C_BPartner_ID
	 */
private void initBPShipmentDetails(int C_BPartner_ID) {
    log.config("C_BPartner_ID" + C_BPartner_ID);
    //  load Shipments (Receipts) - Completed, Closed
    shipmentField.removeActionListener(this);
    shipmentField.removeAllItems();
    //	None
    KeyNamePair pp = new KeyNamePair(0, "");
    shipmentField.addItem(pp);
    ArrayList<KeyNamePair> list = loadShipmentData(C_BPartner_ID);
    for (KeyNamePair knp : list) shipmentField.addItem(knp);
    shipmentField.setSelectedIndex(0);
    shipmentField.addActionListener(this);
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 18 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class PaySelect method getBPartnerData.

public ArrayList<KeyNamePair> getBPartnerData() {
    ArrayList<KeyNamePair> data = new ArrayList<KeyNamePair>();
    //  Optional BusinessPartner with unpaid AP Invoices
    KeyNamePair pp = new KeyNamePair(0, "");
    data.add(pp);
    String sql = MRole.getDefault().addAccessSQL("SELECT bp.C_BPartner_ID, bp.Name FROM C_BPartner bp", "bp", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO) + " AND EXISTS (SELECT * FROM C_Invoice i WHERE bp.C_BPartner_ID=i.C_BPartner_ID" + //	X_C_Order.PAYMENTRULE_DirectDebit
    " AND (i.IsSOTrx='N' OR (i.IsSOTrx='Y' AND i.PaymentRule='D'))" + " AND i.IsPaid<>'Y') " + "ORDER BY 2";
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            data.add(pp);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    return data;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair)

Example 19 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class PaySelect method loadTableInfo.

/**
	 *  Query and create TableInfo
	 */
public void loadTableInfo(BankInfo bi, Timestamp payDate, ValueNamePair paymentRule, boolean onlyDue, int C_BPartner_ID, KeyNamePair docType, IMiniTable miniTable) {
    log.config("");
    //  not yet initialized
    if (m_sql == null)
        return;
    String sql = m_sql;
    //  Parameters
    String isSOTrx = "N";
    if (paymentRule != null && X_C_Order.PAYMENTRULE_DirectDebit.equals(paymentRule.getValue())) {
        isSOTrx = "Y";
        sql += " AND i.PaymentRule='" + X_C_Order.PAYMENTRULE_DirectDebit + "'";
    }
    //
    if (onlyDue)
        sql += " AND COALESCE(ips.duedate,paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced)) <= ?";
    //
    if (C_BPartner_ID != 0)
        sql += " AND i.C_BPartner_ID=?";
    //Document Type
    KeyNamePair dt = docType;
    int c_doctype_id = dt.getKey();
    if (c_doctype_id != 0)
        sql += " AND i.c_doctype_id =?";
    sql += " ORDER BY DateDue, bp.Name, i.DocumentNo";
    log.fine(sql + " - C_Currency_ID=" + bi.C_Currency_ID + ", C_BPartner_ID=" + C_BPartner_ID + ", C_doctype_id=" + c_doctype_id);
    //  Get Open Invoices
    try {
        int index = 1;
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        //	DiscountAmt
        pstmt.setTimestamp(index++, payDate);
        //	DueAmt
        pstmt.setInt(index++, bi.C_Currency_ID);
        pstmt.setTimestamp(index++, payDate);
        //	PayAmt
        pstmt.setTimestamp(index++, payDate);
        pstmt.setInt(index++, bi.C_Currency_ID);
        pstmt.setTimestamp(index++, payDate);
        //	IsSOTrx
        pstmt.setString(index++, isSOTrx);
        pstmt.setTimestamp(index++, payDate);
        //	Client
        pstmt.setInt(index++, m_AD_Client_ID);
        if (onlyDue)
            pstmt.setTimestamp(index++, payDate);
        if (C_BPartner_ID != 0)
            pstmt.setInt(index++, C_BPartner_ID);
        if (//Document type
        c_doctype_id != 0)
            pstmt.setInt(index++, c_doctype_id);
        //
        ResultSet rs = pstmt.executeQuery();
        miniTable.loadTable(rs);
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair)

Example 20 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VBOMDrop method actionPerformed.

//	getPreferredSize
/**************************************************************************
	 *	Action Listener
	 *  @param e event
	 */
public void actionPerformed(ActionEvent e) {
    log.config(e.getActionCommand());
    Object source = e.getSource();
    //	Toggle Qty Enabled
    if (source instanceof JCheckBox || source instanceof JRadioButton) {
        cmd_selection(source);
        //	need to de-select the others in group	
        if (source instanceof JRadioButton) {
            //	find Button Group
            Iterator it = m_buttonGroups.values().iterator();
            while (it.hasNext()) {
                ButtonGroup group = (ButtonGroup) it.next();
                Enumeration en = group.getElements();
                while (en.hasMoreElements()) {
                    //	We found the group
                    if (source == en.nextElement()) {
                        Enumeration info = group.getElements();
                        while (info.hasMoreElements()) {
                            Object infoObj = info.nextElement();
                            if (source != infoObj)
                                cmd_selection(infoObj);
                        }
                    }
                }
            }
        }
    } else //	Product / Qty
    if (source == productField || source == productQty) {
        m_qty = (BigDecimal) productQty.getValue();
        KeyNamePair pp = (KeyNamePair) productField.getSelectedItem();
        m_product = MProduct.get(Env.getCtx(), pp.getKey());
        createMainPanel();
        sizeIt();
    } else //	Order
    if (source == orderField) {
        KeyNamePair pp = (KeyNamePair) orderField.getSelectedItem();
        boolean valid = (pp != null && pp.getKey() > 0);
        //
        if (invoiceField != null)
            invoiceField.setReadWrite(!valid);
        if (projectField != null)
            projectField.setReadWrite(!valid);
    } else //	Invoice
    if (source == invoiceField) {
        KeyNamePair pp = (KeyNamePair) invoiceField.getSelectedItem();
        boolean valid = (pp != null && pp.getKey() > 0);
        //
        if (orderField != null)
            orderField.setReadWrite(!valid);
        if (projectField != null)
            projectField.setReadWrite(!valid);
    } else //	Project
    if (source == projectField) {
        KeyNamePair pp = (KeyNamePair) projectField.getSelectedItem();
        boolean valid = (pp != null && pp.getKey() > 0);
        //
        if (orderField != null)
            orderField.setReadWrite(!valid);
        if (invoiceField != null)
            invoiceField.setReadWrite(!valid);
    } else //	OK
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
        if (cmd_save())
            dispose();
    } else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
        dispose();
    //	Enable OK
    boolean OK = m_product != null;
    if (OK) {
        KeyNamePair pp = null;
        if (orderField != null)
            pp = (KeyNamePair) orderField.getSelectedItem();
        if ((pp == null || pp.getKey() <= 0) && invoiceField != null)
            pp = (KeyNamePair) invoiceField.getSelectedItem();
        if ((pp == null || pp.getKey() <= 0) && projectField != null)
            pp = (KeyNamePair) projectField.getSelectedItem();
        OK = (pp != null && pp.getKey() > 0);
    }
    confirmPanel.getOKButton().setEnabled(OK);
}
Also used : JCheckBox(javax.swing.JCheckBox) JRadioButton(javax.swing.JRadioButton) Enumeration(java.util.Enumeration) ButtonGroup(javax.swing.ButtonGroup) Iterator(java.util.Iterator) KeyNamePair(org.compiere.util.KeyNamePair) BigDecimal(java.math.BigDecimal)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7