Search in sources :

Example 1 with InfoBPartner

use of org.compiere.apps.search.InfoBPartner in project adempiere by adempiere.

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 && !cancelled
		 */
    Object[] result = null;
    boolean cancelled = false;
    boolean multipleSelection = false;
    int record_id = 0;
    //
    //	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 + ")");
    //  If the record has a value (ID) find the name.  The displayed text could be different.
    if (queryValue.length() == 0 && getValue() != null && !getValue().equals("")) {
        Object currentValue = getValue();
        try {
            record_id = ((Number) currentValue).intValue();
            queryValue = "";
        } catch (Exception e) {
        //  Can't cast the string "" to a number.
        }
    }
    //
    //	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 (m_tableName == null) {
                //	sets table name & key column
                String rsql = getDirectAccessSQL("*");
                if (rsql == null || rsql.length() == 0) {
                    m_button.setEnabled(false);
                    return;
                }
            }
            // multipleSelection assumed false for custom info windows
            Info ig = factory.create(frame, true, m_lookup.getWindowNo(), m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, 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();
        //
        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);
            // TODO hard-coded - add to AD_Column?
            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, record_id, queryValue, multipleSelection, true, whereClause);
        ip.setVisible(true);
        cancelled = ip.isCancelled();
        result = ip.getSelectedKeys();
        resetValue = true;
    } else if (col.equals("C_BPartner_ID")) {
        resetTabInfo();
        //
        setIsSOTrx(m_isSOTrxEnvOverride, false);
        //  If we have a record id, set isSOMatch
        if (record_id > 0) {
            String trxName = Trx.createTrxName();
            MBPartner bp = new MBPartner(Env.getCtx(), record_id, trxName);
            m_isSOMatch = (m_isSOTrx && bp.isCustomer()) || (!m_isSOTrx && bp.isVendor());
            Trx.get(trxName, false).close();
        }
        //
        InfoBPartner ip = new InfoBPartner(frame, true, m_lookup.getWindowNo(), record_id, queryValue, m_isSOTrx, m_isSOMatch, multipleSelection, true, whereClause);
        ip.setVisible(true);
        cancelled = ip.isCancelled();
        result = ip.getSelectedKeys();
    } else //	General Info
    {
        if (m_tableName == null) {
            //	sets table name & key column
            String rsql = getDirectAccessSQL("*");
            if (rsql == null || rsql.length() == 0) {
                m_button.setEnabled(false);
                return;
            }
        }
        //
        Info ig = Info.create(frame, true, m_lookup.getWindowNo(), m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, true, whereClause);
        ig.setVisible(true);
        cancelled = ig.isCancelled();
        result = ig.getSelectedKeys();
    }
    if (isReadWrite()) {
        //  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_text.requestFocus();
    } else
        log.config(m_columnName + " - Field not writable.  No change.");
    m_button.setEnabled(true);
}
Also used : Frame(java.awt.Frame) MBPartner(org.compiere.model.MBPartner) InfoBPartner(org.compiere.apps.search.InfoBPartner) InfoFactory(org.compiere.apps.search.InfoFactory) Info(org.compiere.apps.search.Info) RecordInfo(org.compiere.apps.RecordInfo) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) InfoProduct(org.compiere.apps.search.InfoProduct)

Example 2 with InfoBPartner

use of org.compiere.apps.search.InfoBPartner 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)2 PropertyVetoException (java.beans.PropertyVetoException)2 SQLException (java.sql.SQLException)2 Info (org.compiere.apps.search.Info)2 InfoBPartner (org.compiere.apps.search.InfoBPartner)2 InfoFactory (org.compiere.apps.search.InfoFactory)2 InfoProduct (org.compiere.apps.search.InfoProduct)2 FieldRecordInfo (org.compiere.apps.FieldRecordInfo)1 RecordInfo (org.compiere.apps.RecordInfo)1 InfoInvoice (org.compiere.apps.search.InfoInvoice)1 MBPartner (org.compiere.model.MBPartner)1