Search in sources :

Example 1 with InfoBPartnerPanel

use of org.adempiere.webui.panel.InfoBPartnerPanel in project adempiere by adempiere.

the class WSearchEditor method actionButton.

//	actionBPartner
private void actionButton(String queryValue) {
    if (m_lookup == null)
        //	leave button disabled
        return;
    // If an infoPanel is already open, close it.
    if (infoPanel != null) {
        infoPanel.detach();
        infoPanel = null;
    }
    /**
		 *  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
		 */
    // We're changing something - ignore other events;
    m_settingValue = true;
    //
    Object[] result = null;
    boolean cancelled = false;
    boolean multipleSelection = false;
    boolean modal = true;
    boolean saveResults = true;
    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.
        }
    }
    //
    String infoPanelFactoryClass = m_lookup.getInfoPanelFactoryClass();
    if (infoPanelFactoryClass != null && infoPanelFactoryClass.trim().length() > 0) {
        try {
            @SuppressWarnings("unchecked") Class<InfoPanelFactory> clazz = (Class<InfoPanelFactory>) this.getClass().getClassLoader().loadClass(infoPanelFactoryClass);
            InfoPanelFactory factory = clazz.newInstance();
            if (//	sets table name & key column
            m_tableName == null) {
                if (!hasSearchableColumns()) {
                    // Search should have been disabled for this field.
                    log.severe("Search enabled on field " + m_columnName + ". Associated table has no standard/identifier columns.");
                    return;
                }
            }
            // multipleSelection assumed false for custom info windows
            infoPanel = factory.create(m_lookup.getWindowNo(), modal, m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, saveResults, whereClause);
        //
        } 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
        infoPanel = new InfoProductPanel(m_lookup.getWindowNo(), modal, M_Warehouse_ID, M_PriceList_ID, record_id, queryValue, multipleSelection, saveResults, whereClause);
    } 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();
        }
        //
        infoPanel = new InfoBPartnerPanel(m_lookup.getWindowNo(), modal, record_id, queryValue, m_isSOTrx, m_isSOMatch, multipleSelection, saveResults, whereClause);
    } else //	General Info
    {
        if (//	sets table name & key column
        m_tableName == null)
            getDirectAccessSQL("*");
        //
        infoPanel = InfoPanel.create(m_lookup.getWindowNo(), modal, m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, saveResults, whereClause);
    }
    //
    if (infoPanel != null) {
        infoPanel.addValueChangeListener(this);
        AEnv.showWindow(infoPanel);
        //
        cancelled = infoPanel.isCancelled();
        result = infoPanel.getSelectedKeys();
        //
        infoPanel = null;
    }
    //  Result
    if (isReadWrite()) {
        if (result != null && result.length > 0) {
            //ensure data binding happen
            if (result.length > 1)
                actionCombo(result);
            else
                actionCombo(result[0]);
        } else if (cancelled) {
            log.config(getColumnName() + " - Result = null (cancelled)");
            actionCombo(null);
        } else {
            log.config(getColumnName() + " - Result = null (not cancelled)");
            //Reset the combo box to the current value
            actionCombo(getValue());
        }
    } else
        m_settingValue = false;
}
Also used : InfoBPartnerPanel(org.adempiere.webui.panel.InfoBPartnerPanel) MBPartner(org.compiere.model.MBPartner) SQLException(java.sql.SQLException) InfoProductPanel(org.adempiere.webui.panel.InfoProductPanel) InfoPanelFactory(org.adempiere.webui.panel.InfoPanelFactory)

Aggregations

SQLException (java.sql.SQLException)1 InfoBPartnerPanel (org.adempiere.webui.panel.InfoBPartnerPanel)1 InfoPanelFactory (org.adempiere.webui.panel.InfoPanelFactory)1 InfoProductPanel (org.adempiere.webui.panel.InfoProductPanel)1 MBPartner (org.compiere.model.MBPartner)1