Search in sources :

Example 1 with InfoFactory

use of org.compiere.apps.search.InfoFactory 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)

Aggregations

Frame (java.awt.Frame)1 PropertyVetoException (java.beans.PropertyVetoException)1 SQLException (java.sql.SQLException)1 RecordInfo (org.compiere.apps.RecordInfo)1 Info (org.compiere.apps.search.Info)1 InfoBPartner (org.compiere.apps.search.InfoBPartner)1 InfoFactory (org.compiere.apps.search.InfoFactory)1 InfoProduct (org.compiere.apps.search.InfoProduct)1 MBPartner (org.compiere.model.MBPartner)1