Search in sources :

Example 1 with Info

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

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

the class AcctViewer method actionButton.

//  actionTable
/**
	 *  Action Button
	 *
	 *  @param button pressed button
	 *  @return ID
	 */
private int actionButton(CButton button) {
    String keyColumn = button.getActionCommand();
    log.info(keyColumn);
    String whereClause = "(IsSummary='N' OR IsSummary IS NULL)";
    String lookupColumn = keyColumn;
    int record_id = m_data.getButtonRecordID(keyColumn);
    if (keyColumn.equals("Account_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User1_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList1);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User2_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList2);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User3_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList3);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User4_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList4);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("M_Product_ID")) {
        whereClause = "";
    }
    if (lookupColumn.equals("UserElement1_ID")) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X1' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    }
    if (lookupColumn.equals("UserElement2_ID")) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X2' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    } else if (selDocument.isSelected())
        whereClause = "";
    if (//  Record_ID
    button == selRecord)
        record_id = m_data.Record_ID;
    else
        record_id = m_data.getButtonRecordID(keyColumn);
    String tableName = lookupColumn.substring(0, lookupColumn.length() - 3);
    Info info = Info.create(this, true, m_data.WindowNo, tableName, lookupColumn, record_id, "", false, true, whereClause);
    if (!info.loadedOK()) {
        info.dispose();
        info = null;
        button.setText("");
        m_data.whereInfo.put(keyColumn, "");
        m_data.buttonRecordID.put(keyColumn, null);
        return 0;
    }
    info.setVisible(true);
    boolean isCancelled = info.isCancelled();
    boolean isOK = info.isOk();
    Integer key = 0;
    if (// Delete the saved info
    isCancelled && !isOK) {
        key = 0;
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  no query
            m_data.whereInfo.put(keyColumn, "");
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        button.setText("");
    } else if (!isCancelled && isOK) {
        //  Save for query
        //  C_Project_ID=100 or ""
        String selectSQL = info.getSelectedSQL();
        key = (Integer) info.getSelectedKey();
        log.config(keyColumn + " - " + key);
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  Add to query
            m_data.whereInfo.put(keyColumn, keyColumn + "=" + key.intValue());
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        //  Display Selection and resize
        button.setText(m_data.getButtonText(tableName, lookupColumn, selectSQL));
        pack();
    } else if (// xor: window closed or error - no change
    !(isCancelled ^ isOK)) {
        // m_data not changed
        if (//  Record_ID
        button == selRecord)
            key = m_data.Record_ID = key.intValue();
        else
            key = m_data.getButtonRecordID(keyColumn);
    }
    info = null;
    return key.intValue();
}
Also used : Query(org.compiere.model.Query) Info(org.compiere.apps.search.Info) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Aggregations

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