Search in sources :

Example 1 with InfoInvoice

use of org.compiere.apps.search.InfoInvoice in project lar_361 by comitsrl.

the class VLookup method actionButton.

// actionCombo
/**
 *	Action - Button.
 *	- Call Info
 *	@param queryValue initial query value
 */
private void actionButton(String queryValue) {
    // disable double click
    m_button.setEnabled(false);
    if (m_lookup == null)
        // leave button disabled
        return;
    // closes other editors
    m_text.requestFocus();
    Frame frame = Env.getFrame(this);
    /**
     *  Three return options:
     *  - Value Selected & OK pressed   => store result => result has value
     *  - Cancel pressed                => store null   => result == null && cancelled
     *  - Window closed                 -> ignore       => result == null && !cancalled
     */
    Object[] result = null;
    boolean cancelled = false;
    boolean multipleSelection = false;
    // 
    // fully qualified name
    String col = m_lookup.getColumnName();
    if (col.indexOf('.') != -1)
        col = col.substring(col.indexOf('.') + 1);
    // Zoom / Validation
    String whereClause = getWhereClause();
    // 
    log.fine(col + ", Zoom=" + m_lookup.getZoom() + " (" + whereClause + ")");
    // 
    // reset value so that is always treated as new entry
    boolean resetValue = false;
    String infoFactoryClass = m_lookup.getInfoFactoryClass();
    if (infoFactoryClass != null && infoFactoryClass.trim().length() > 0) {
        try {
            Class<InfoFactory> clazz = (Class<InfoFactory>) this.getClass().getClassLoader().loadClass(infoFactoryClass);
            InfoFactory factory = clazz.newInstance();
            if (// sets table name & key column
            m_tableName == null)
                getDirectAccessSQL("*");
            Info ig = factory.create(frame, true, m_lookup.getWindowNo(), m_tableName, m_keyColumnName, queryValue, false, whereClause);
            ig.setVisible(true);
            cancelled = ig.isCancelled();
            result = ig.getSelectedKeys();
        } catch (Exception e) {
            log.log(Level.SEVERE, "Failed to load custom InfoFactory - " + e.getLocalizedMessage(), e);
        }
    } else if (col.equals("M_Product_ID")) {
        // Reset
        resetTabInfo();
        // Replace Value with name if no value exists
        if (queryValue.length() == 0 && m_text.getText().length() > 0)
            // Name indicator - otherwise Value
            queryValue = "@" + m_text.getText() + "@";
        int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), m_lookup.getWindowNo(), "M_Warehouse_ID");
        int M_PriceList_ID = Env.getContextAsInt(Env.getCtx(), m_lookup.getWindowNo(), "M_PriceList_ID");
        if (m_mField != null) {
            int AD_Table_ID = MColumn.getTable_ID(Env.getCtx(), m_mField.getAD_Column_ID(), null);
            multipleSelection = (MOrderLine.Table_ID == AD_Table_ID) || (MInvoiceLine.Table_ID == AD_Table_ID) || (I_PP_Product_BOMLine.Table_ID == AD_Table_ID) || (MProductPrice.Table_ID == AD_Table_ID);
        }
        // Show Info
        InfoProduct ip = new InfoProduct(frame, true, m_lookup.getWindowNo(), M_Warehouse_ID, M_PriceList_ID, queryValue, multipleSelection, whereClause);
        ip.setVisible(true);
        cancelled = ip.isCancelled();
        result = ip.getSelectedKeys();
        resetValue = true;
    } else if (col.equals("C_BPartner_ID")) {
        // Replace Value with name if no value exists
        if (queryValue.length() == 0 && m_text.getText().length() > 0)
            queryValue = m_text.getText();
        // default
        boolean isSOTrx = true;
        if (Env.getContext(Env.getCtx(), m_lookup.getWindowNo(), "IsSOTrx").equals("N"))
            isSOTrx = false;
        InfoBPartner ip = new InfoBPartner(frame, true, m_lookup.getWindowNo(), queryValue, isSOTrx, multipleSelection, whereClause);
        ip.setVisible(true);
        cancelled = ip.isCancelled();
        result = ip.getSelectedKeys();
    } else // @marcos - commit 9824b69
    if (col.equals("C_Invoice_ID")) {
        // Replace Value with name if no value exists
        if (queryValue.length() == 0 && m_text.getText().length() > 0)
            queryValue = m_text.getText();
        // @fchiappano Chequear que mField no sea nulo.
        if (m_mField != null) {
            int AD_Table_ID = MColumn.getTable_ID(Env.getCtx(), m_mField.getAD_Column_ID(), null);
            multipleSelection = (MPaymentAllocate.Table_ID == AD_Table_ID);
        }
        InfoInvoice ii = new InfoInvoice(frame, true, m_lookup.getWindowNo(), queryValue, multipleSelection, whereClause);
        ii.setVisible(true);
        cancelled = ii.isCancelled();
        result = ii.getSelectedKeys();
    } else // @marcos - commit 9824b69
    // General Info
    {
        if (// sets table name & key column
        m_tableName == null)
            getDirectAccessSQL("*");
        Info ig = Info.create(frame, true, m_lookup.getWindowNo(), m_tableName, m_keyColumnName, queryValue, multipleSelection, whereClause);
        ig.setVisible(true);
        cancelled = ig.isCancelled();
        result = ig.getSelectedKeys();
    }
    // Result
    if (result != null && result.length > 0) {
        log.config(m_columnName + " - Result = " + result.toString() + " (" + result.getClass().getName() + ")");
        // make sure that value is in cache
        m_lookup.getDirect(result[0], false, true);
        if (resetValue)
            actionCombo(null);
        // juddm added logic for multi-select handling
        if (result.length > 1)
            // data binding
            actionCombo(result);
        else
            actionCombo(result[0]);
    } else if (cancelled) {
        log.config(m_columnName + " - Result = null (cancelled)");
        actionCombo(null);
    } else {
        log.config(m_columnName + " - Result = null (not cancelled)");
        // to re-display value
        setValue(m_value);
    }
    // 
    m_button.setEnabled(true);
    m_text.requestFocus();
}
Also used : Frame(java.awt.Frame) InfoInvoice(org.compiere.apps.search.InfoInvoice) InfoBPartner(org.compiere.apps.search.InfoBPartner) InfoFactory(org.compiere.apps.search.InfoFactory) Info(org.compiere.apps.search.Info) FieldRecordInfo(org.compiere.apps.FieldRecordInfo) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) InfoProduct(org.compiere.apps.search.InfoProduct)

Aggregations

Frame (java.awt.Frame)1 PropertyVetoException (java.beans.PropertyVetoException)1 SQLException (java.sql.SQLException)1 FieldRecordInfo (org.compiere.apps.FieldRecordInfo)1 Info (org.compiere.apps.search.Info)1 InfoBPartner (org.compiere.apps.search.InfoBPartner)1 InfoFactory (org.compiere.apps.search.InfoFactory)1 InfoInvoice (org.compiere.apps.search.InfoInvoice)1 InfoProduct (org.compiere.apps.search.InfoProduct)1