Search in sources :

Example 1 with InfoProduct

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

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

the class VPAttribute method actionPerformed.

//  addActionListener
/**
	 * 	Action Listener - start dialog
	 * 	@param e Event
	 */
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(RecordInfo.CHANGE_LOG_COMMAND)) {
        RecordInfo.start(m_GridField);
        return;
    }
    if (!m_button.isEnabled())
        return;
    m_button.setEnabled(false);
    //
    Integer oldValue = 0;
    try {
        oldValue = (Integer) getValue();
    } catch (ClassCastException cce) {
    // Possible Invalid Cast exception if getValue() return new instance of Object.
    }
    int oldValueInt = oldValue == null ? 0 : oldValue.intValue();
    int M_AttributeSetInstance_ID = oldValueInt;
    int M_Product_ID = 0;
    int M_ProductBOM_ID = 0;
    if (m_GridTab != null) {
        M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, m_GridTab.getTabNo(), "M_Product_ID");
        M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, m_GridTab.getTabNo(), "M_ProductBOM_ID");
    } else {
        M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_Product_ID");
        M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductBOM_ID");
    }
    int M_Locator_ID = -1;
    log.config("M_Product_ID=" + M_Product_ID + "/" + M_ProductBOM_ID + ",M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", AD_Column_ID=" + m_AD_Column_ID);
    //	M_Product.M_AttributeSetInstance_ID = 8418
    //	HARDCODED
    boolean productWindow = m_AD_Column_ID == 8418;
    //	Exclude ability to enter ASI
    boolean exclude = false;
    if (M_Product_ID != 0) {
        MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
        int M_AttributeSet_ID = product.getM_AttributeSet_ID();
        if (M_AttributeSet_ID != 0) {
            MAttributeSet mas = MAttributeSet.get(Env.getCtx(), M_AttributeSet_ID);
            exclude = mas.excludeEntry(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNo));
        }
    }
    boolean changed = false;
    if (//	Use BOM Component
    M_ProductBOM_ID != 0)
        M_Product_ID = M_ProductBOM_ID;
    // If the VPAttribute component is in a dialog, use the search
    if (m_searchOnly) {
        // The component is an element in a CPanel, which is part of a JPanel
        // which is in a JLayeredPane which is in ...  the InfoProduct window
        Container me = ((Container) this).getParent();
        while (me != null) {
            if (me instanceof InfoProduct)
                break;
            me = me.getParent();
        }
        InfoPAttribute ia = new InfoPAttribute((CDialog) me);
        m_pAttributeWhere = ia.getWhereClause();
        String oldText = m_text.getText();
        m_text.setText(ia.getDisplay());
        // The text can be long.  Use the tooltip to help display the info.
        m_text.setToolTipText(m_text.getText());
        ActionEvent ae = new ActionEvent(m_text, 1001, "updated");
        //  TODO not the generally correct way to fire an event
        ((InfoProduct) me).actionPerformed(ae);
    } else if (!productWindow && (M_Product_ID == 0 || exclude)) {
        changed = true;
        m_text.setText(null);
        M_AttributeSetInstance_ID = 0;
    } else {
        VPAttributeDialog vad = new VPAttributeDialog(Env.getFrame(this), M_AttributeSetInstance_ID, M_Product_ID, m_C_BPartner_ID, productWindow, m_AD_Column_ID, m_WindowNo, isReadWrite());
        if (vad.isChanged()) {
            m_text.setText(vad.getM_AttributeSetInstanceName());
            // The text can be long.  Use the tooltip to help display the info.
            m_text.setToolTipText(vad.getM_AttributeSetInstanceName());
            M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
            if (!productWindow && vad.getM_Locator_ID() > 0) {
                M_Locator_ID = vad.getM_Locator_ID();
            }
            changed = true;
        }
    }
    //	Set Value
    if (changed) {
        log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
        //	force re-query display
        m_value = new Object();
        if (M_AttributeSetInstance_ID == 0)
            setValue(null);
        else
            setValue(new Integer(M_AttributeSetInstance_ID));
        // Change Locator
        if (m_GridTab != null && M_Locator_ID > 0) {
            log.finest("Change M_Locator_ID=" + M_Locator_ID);
            m_GridTab.setValue("M_Locator_ID", M_Locator_ID);
        }
        //
        try {
            String columnName = "M_AttributeSetInstance_ID";
            if (m_GridField != null) {
                columnName = m_GridField.getColumnName();
            }
            fireVetoableChange(columnName, new Object(), getValue());
        } catch (PropertyVetoException pve) {
            log.log(Level.SEVERE, "", pve);
        }
        if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && m_GridField != null) {
            //  force Change - user does not realize that embedded object is already saved.
            m_GridTab.processFieldChange(m_GridField);
        }
    }
    //	change
    m_button.setEnabled(true);
    requestFocus();
}
Also used : MProduct(org.compiere.model.MProduct) ActionEvent(java.awt.event.ActionEvent) MAttributeSet(org.compiere.model.MAttributeSet) PropertyVetoException(java.beans.PropertyVetoException) Container(java.awt.Container) InfoProduct(org.compiere.apps.search.InfoProduct) InfoPAttribute(org.compiere.apps.search.InfoPAttribute)

Example 3 with InfoProduct

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

Example 4 with InfoProduct

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

the class POSActionPanel method showWindowProduct.

//	actionPerformed
/**
	 * Show Window Product
	 */
private void showWindowProduct(String query) {
    //	Show Info
    posPanel.getFrame().getContentPane().invalidate();
    InfoProduct infoProduct = new InfoProduct(posPanel.getFrame(), true, posPanel.getWindowNo(), posPanel.getM_Warehouse_ID(), posPanel.getM_PriceList_ID(), 0, query, true, true, null);
    infoProduct.setVisible(true);
    Object[] result = infoProduct.getSelectedKeys();
    if (result == null)
        return;
    if (infoProduct.isCancelled())
        return;
    for (Object item : result) {
        int productId = (Integer) item;
        if (productId > 0) {
            String value = posPanel.getProductValue(productId);
            //fieldProductName.setPlaceholder(value);
            posPanel.updateProductPlaceholder(value);
            try {
                posPanel.setAddQty(true);
                findProduct(true);
            } catch (Exception exception) {
                ADialog.error(0, null, exception.getLocalizedMessage());
            }
            fieldProductName.setText("");
            fieldProductName.repaint();
        }
    }
}
Also used : InfoProduct(org.compiere.apps.search.InfoProduct) AdempiereException(org.adempiere.exceptions.AdempiereException)

Aggregations

InfoProduct (org.compiere.apps.search.InfoProduct)4 PropertyVetoException (java.beans.PropertyVetoException)3 Frame (java.awt.Frame)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 Container (java.awt.Container)1 ActionEvent (java.awt.event.ActionEvent)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 FieldRecordInfo (org.compiere.apps.FieldRecordInfo)1 RecordInfo (org.compiere.apps.RecordInfo)1 InfoInvoice (org.compiere.apps.search.InfoInvoice)1 InfoPAttribute (org.compiere.apps.search.InfoPAttribute)1 MAttributeSet (org.compiere.model.MAttributeSet)1 MBPartner (org.compiere.model.MBPartner)1 MProduct (org.compiere.model.MProduct)1