Search in sources :

Example 26 with MLookup

use of org.compiere.model.MLookup in project adempiere by adempiere.

the class WAllocation method dynInit.

//  jbInit
/**
	 *  Dynamic Init (prepare dynamic fields)
	 *  @throws Exception if Lookups cannot be initialized
	 */
public void dynInit() throws Exception {
    //  Currency
    //  C_Invoice.C_Currency_ID
    int AD_Column_ID = 3505;
    MLookup lookupCur = MLookupFactory.get(Env.getCtx(), getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
    currencyPick = new WTableDirEditor("C_Currency_ID", true, false, true, lookupCur);
    currencyPick.setValue(new Integer(m_C_Currency_ID));
    currencyPick.addValueChangeListener(this);
    // Organization filter selection
    //C_Period.AD_Org_ID (needed to allow org 0)
    AD_Column_ID = 839;
    MLookup lookupOrg = MLookupFactory.get(Env.getCtx(), getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
    organizationPick = new WTableDirEditor("AD_Org_ID", true, false, true, lookupOrg);
    organizationPick.setValue(Env.getAD_Org_ID(Env.getCtx()));
    organizationPick.addValueChangeListener(this);
    //  BPartner
    //  C_Invoice.C_BPartner_ID
    AD_Column_ID = 3499;
    MLookup lookupBP = MLookupFactory.get(Env.getCtx(), getWindowNo(), 0, AD_Column_ID, DisplayType.Search);
    bpartnerSearch = new WSearchEditor("C_BPartner_ID", true, false, true, lookupBP);
    bpartnerSearch.addValueChangeListener(this);
    //  Translation
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "AllocateStatus"));
    statusBar.setStatusDB("");
    //  Date set to Login Date
    dateField.setValue(Env.getContextAsDate(Env.getCtx(), "#Date"));
    dateField.addValueChangeListener(this);
    //  C_AllocationLine.C_Charge_ID
    AD_Column_ID = 61804;
    MLookup lookupCharge = MLookupFactory.get(Env.getCtx(), getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
    chargePick = new WTableDirEditor("C_Charge_ID", true, false, true, lookupCharge);
    chargePick.setValue(new Integer(m_C_Charge_ID));
    chargePick.addValueChangeListener(this);
    //	APAR
    //  T_InvoiceGL.APAR
    AD_Column_ID = 14082;
    MLookup lookupAPAR = MLookupFactory.get(Env.getCtx(), getWindowNo(), 0, AD_Column_ID, DisplayType.List);
    aparPick = new WTableDirEditor("APAR", true, false, true, lookupAPAR);
    aparPick.setValue(APAR_A);
    aparPick.addValueChangeListener(this);
}
Also used : WTableDirEditor(org.adempiere.webui.editor.WTableDirEditor) MLookup(org.compiere.model.MLookup) WSearchEditor(org.adempiere.webui.editor.WSearchEditor)

Example 27 with MLookup

use of org.compiere.model.MLookup in project adempiere by adempiere.

the class VLookup method actionZoom.

//	actionBPartner
/**
	 *	Action - Zoom
	 *	@param selectedItem item
	 */
private void actionZoom(Object selectedItem) {
    if (m_lookup == null)
        return;
    //
    MQuery zoomQuery = m_lookup.getZoomQuery();
    Object value = getValue();
    if (value == null)
        value = selectedItem;
    //	If not already exist or exact value
    if (zoomQuery == null || value != null) {
        //	ColumnName might be changed in MTab.validateQuery
        zoomQuery = new MQuery();
        String keyTableName = null;
        String keyColumnName = null;
        //	Check if it is a Table Reference
        if (m_lookup != null && m_lookup instanceof MLookup) {
            int AD_Reference_ID = ((MLookup) m_lookup).getAD_Reference_Value_ID();
            if (DisplayType.List == m_lookup.getDisplayType()) {
                keyColumnName = "AD_Ref_List_ID";
                keyTableName = "AD_Ref_List";
                value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
            } else {
                if (AD_Reference_ID != 0) {
                    String query = "SELECT kc.ColumnName, kt.TableName" + " FROM AD_Ref_Table rt" + " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)" + " INNER JOIN AD_Table kt ON (rt.AD_Table_ID=kt.AD_Table_ID)" + " WHERE rt.AD_Reference_ID=?";
                    PreparedStatement pstmt = null;
                    ResultSet rs = null;
                    try {
                        pstmt = DB.prepareStatement(query, null);
                        pstmt.setInt(1, AD_Reference_ID);
                        rs = pstmt.executeQuery();
                        if (rs.next()) {
                            keyColumnName = rs.getString(1);
                            keyTableName = rs.getString(2);
                        }
                    } catch (Exception e) {
                        log.log(Level.SEVERE, query, e);
                    } finally {
                        DB.close(rs, pstmt);
                        rs = null;
                        pstmt = null;
                    }
                }
            //	Table Reference
            }
        }
        if (keyColumnName != null && keyColumnName.length() != 0) {
            zoomQuery.addRestriction(keyColumnName, MQuery.EQUAL, value);
            zoomQuery.setZoomColumnName(keyColumnName);
            zoomQuery.setZoomTableName(keyTableName);
        } else {
            zoomQuery.addRestriction(m_columnName, MQuery.EQUAL, value);
            if (m_columnName.indexOf(".") > 0) {
                zoomQuery.setZoomColumnName(m_columnName.substring(m_columnName.indexOf(".") + 1));
                zoomQuery.setZoomTableName(m_columnName.substring(0, m_columnName.indexOf(".")));
            } else {
                zoomQuery.setZoomColumnName(m_columnName);
                //remove _ID to get table name
                zoomQuery.setZoomTableName(m_columnName.substring(0, m_columnName.length() - 3));
            }
        }
        zoomQuery.setZoomValue(value);
        //	guess
        zoomQuery.setRecordCount(1);
    }
    int AD_Window_ID = m_lookup.getZoom(zoomQuery);
    //
    log.info(m_columnName + " - AD_Window_ID=" + AD_Window_ID + " - Query=" + zoomQuery + " - Value=" + value);
    //
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    //
    AWindow frame = new AWindow(getGraphicsConfiguration());
    if (!frame.initWindow(AD_Window_ID, zoomQuery, false)) {
        setCursor(Cursor.getDefaultCursor());
        ValueNamePair pp = CLogger.retrieveError();
        String msg = pp == null ? "AccessTableNoView" : pp.getValue();
        ADialog.error(m_lookup.getWindowNo(), this, msg, pp == null ? "" : pp.getName());
    } else {
        AEnv.addToWindowManager(frame);
        if (Ini.isPropertyBool(Ini.P_OPEN_WINDOW_MAXIMIZED)) {
            AEnv.showMaximized(frame);
        } else {
            AEnv.showCenterScreen(frame);
        }
    }
    //  async window - not able to get feedback
    frame = null;
    //
    setCursor(Cursor.getDefaultCursor());
}
Also used : AWindow(org.compiere.apps.AWindow) MLookup(org.compiere.model.MLookup) ResultSet(java.sql.ResultSet) MQuery(org.compiere.model.MQuery) PreparedStatement(java.sql.PreparedStatement) ValueNamePair(org.compiere.util.ValueNamePair) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException)

Example 28 with MLookup

use of org.compiere.model.MLookup in project adempiere by adempiere.

the class VLookup method getDirectAccessSQL.

/**
	 * 	Determines if the lookup has searchable (text) fields.	
	 */
//	BR [ 9223372036854775807 ]
//	private boolean hasSearchableColumns()
//	{
//		boolean retValue = false;
//
//		m_tableName = MQuery.getZoomTableName(m_columnName);
//		m_keyColumnName = MQuery.getZoomColumnName(m_columnName);
//
//		if (   m_columnName.equals("M_Product_ID") 
//		    || m_columnName.equals("M_ProductBOM_ID")
//			|| m_columnName.equals("C_BPartner_ID")
//			|| m_columnName.equals("C_Order_ID")
//			|| m_columnName.equals("C_Invoice_ID")
//			|| m_columnName.equals("M_InOut_ID")
//			|| m_columnName.equals("C_Payment_ID")
//			|| m_columnName.equals("GL_JournalBatch_ID")
//			|| m_columnName.equals("SalesRep_ID"))
//		{
//			retValue = true;
//		}
//		else
//		{
//			/** Check Well Known Columns of Table - assumes TableDir	**/
//			String query = "SELECT t.TableName, c.ColumnName "
//				+ "FROM AD_Column c "
//				+ " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID AND t.IsView='N')"
//				+ " WHERE (c.ColumnName IN ('DocumentNo', 'Value', 'Name') OR c.IsIdentifier='Y')"
//				+ " AND c.AD_Reference_ID IN (10,14)"
//				+ " AND EXISTS (SELECT * FROM AD_Column cc WHERE cc.AD_Table_ID=t.AD_Table_ID"
//					+ " AND cc.IsKey='Y' AND cc.ColumnName=?)";
//			PreparedStatement pstmt = null;
//			ResultSet rs = null;
//			try
//			{
//				pstmt = DB.prepareStatement(query, null);
//				pstmt.setString(1, m_keyColumnName);
//				rs = pstmt.executeQuery();
//				if (rs.next())
//				{
//					retValue = true;
//				}
//			}
//			catch (SQLException ex)
//			{
//				log.log(Level.SEVERE, query, ex);
//			}
//			finally
//			{
//				DB.close(rs, pstmt);
//				rs = null; pstmt = null;
//			}
//		}
//		return retValue;
//	}
/**
	 * 	Generate Access SQL for Search.
	 * 	The SQL returns the ID of the value entered
	 *	@param text uppercase text for LIKE comparison
	 *	@return sql or ""
	 *  Example
	 *	SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE x OR ...
	 */
private String getDirectAccessSQL(String text) {
    //	Load Table and key Column
    m_tableName = MQuery.getZoomTableName(m_columnName);
    m_keyColumnName = MQuery.getZoomColumnName(m_columnName);
    StringBuffer sql = new StringBuffer();
    //
    if (m_columnName.equals("M_Product_ID")) {
        sql.append("SELECT M_Product_ID FROM M_Product WHERE (");
        if (text.startsWith("@") && text.endsWith("@")) {
            sql.append("UPPER(Name) LIKE  ").append(DB.TO_STRING(text.substring(1, text.length() - 1))).append(")");
        } else {
            sql.append("UPPER(Value) LIKE ").append(DB.TO_STRING(text)).append(" OR UPPER(Name) LIKE ").append(DB.TO_STRING(text)).append(" OR UPPER(SKU) LIKE ").append(DB.TO_STRING(text)).append(" OR UPPER(UPC) LIKE ").append(DB.TO_STRING(text)).append(")");
        }
    } else if (m_columnName.equals("C_BPartner_ID")) {
        sql.append("SELECT C_BPartner_ID FROM C_BPartner WHERE (");
        //	Put query string in Name if not fully numeric
        if (// If text has no non-digit characters ...
        !text.matches(".*\\D+.*"))
            //  search against the Value field
            sql.append("UPPER(Value) LIKE ").append(DB.TO_STRING(text));
        else
            // A few non-digit characters might be in the name. E.g. 451Group, 1st Choice, ...
            sql.append("UPPER(Name) LIKE ").append(DB.TO_STRING(text));
        sql.append(")");
    } else if (m_columnName.equals("C_Order_ID")) {
        sql.append("SELECT C_Order_ID FROM C_Order WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("C_Invoice_ID")) {
        sql.append("SELECT C_Invoice_ID FROM C_Invoice WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("M_InOut_ID")) {
        sql.append("SELECT M_InOut_ID FROM M_InOut WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("C_Payment_ID")) {
        sql.append("SELECT C_Payment_ID FROM C_Payment WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("GL_JournalBatch_ID")) {
        sql.append("SELECT GL_JournalBatch_ID FROM GL_JournalBatch WHERE UPPER(DocumentNo) LIKE ").append(DB.TO_STRING(text));
    } else if (m_columnName.equals("SalesRep_ID")) {
        sql.append("SELECT AD_User_ID FROM AD_User WHERE UPPER(Name) LIKE ").append(DB.TO_STRING(text));
        m_tableName = "AD_User";
        m_keyColumnName = "AD_User_ID";
    }
    //	Predefined
    if (sql.length() > 0) {
        String wc = getWhereClause();
        if (wc != null && wc.length() > 0)
            sql.append(" AND ").append(wc);
        sql.append(" AND IsActive='Y'");
        //	***
        log.finest(m_columnName + " (predefined) " + sql.toString());
        return MRole.getDefault().addAccessSQL(sql.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    }
    //	Check if it is a Table Reference
    if (m_lookup != null && m_lookup instanceof MLookup) {
        int AD_Reference_ID = ((MLookup) m_lookup).getAD_Reference_Value_ID();
        if (AD_Reference_ID != 0) {
            String query = "SELECT kc.ColumnName, dc.ColumnName, t.TableName " + "FROM AD_Ref_Table rt" + " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)" + " INNER JOIN AD_Column dc ON (rt.AD_Display=dc.AD_Column_ID)" + " INNER JOIN AD_Table t ON (rt.AD_Table_ID=t.AD_Table_ID) " + "WHERE rt.AD_Reference_ID=?";
            String displayColumnName = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                pstmt = DB.prepareStatement(query, null);
                pstmt.setInt(1, AD_Reference_ID);
                rs = pstmt.executeQuery();
                if (rs.next()) {
                    m_keyColumnName = rs.getString(1);
                    displayColumnName = rs.getString(2);
                    m_tableName = rs.getString(3);
                }
            } catch (Exception e) {
                log.log(Level.SEVERE, query, e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
            if (displayColumnName != null) {
                sql = new StringBuffer();
                sql.append("SELECT ").append(m_keyColumnName).append(" FROM ").append(m_tableName).append(" WHERE UPPER(").append(displayColumnName).append(") LIKE ").append(DB.TO_STRING(text)).append(" AND IsActive='Y'");
                String wc = getWhereClause();
                if (wc != null && wc.length() > 0)
                    sql.append(" AND ").append(wc);
                //	***
                log.finest(m_columnName + " (Table) " + sql.toString());
                return MRole.getDefault().addAccessSQL(sql.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
            }
        }
    //	Table Reference
    }
    //	MLookup
    // Check Well Known Columns of Table - assumes TableDir
    String query = "SELECT t.TableName, c.ColumnName " + "FROM AD_Column c " + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID AND t.IsView='N') " + "WHERE (c.ColumnName IN ('DocumentNo', 'Value', 'Name') OR c.IsIdentifier='Y')" + " AND c.AD_Reference_ID IN (10,14)" + " AND EXISTS (SELECT * FROM AD_Column cc WHERE cc.AD_Table_ID=t.AD_Table_ID" + " AND cc.IsKey='Y' AND cc.ColumnName=?)";
    sql = new StringBuffer();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(query, null);
        pstmt.setString(1, m_keyColumnName);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            if (sql.length() != 0)
                sql.append(" OR ");
            m_tableName = rs.getString(1);
            sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
        }
    } catch (SQLException ex) {
        log.log(Level.SEVERE, query, ex);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    // Return null if nothing found.
    if (sql.length() == 0) {
        log.finest(m_columnName + " (TableDir) - no standard/identifier columns");
        return "";
    }
    //
    StringBuffer retValue = new StringBuffer("SELECT ").append(m_columnName).append(" FROM ").append(m_tableName).append(" WHERE (").append(sql).append(")").append(" AND IsActive='Y'");
    String wc = getWhereClause();
    if (wc != null && wc.length() > 0)
        retValue.append(" AND ").append(wc);
    //	***
    log.finest(m_columnName + " (TableDir) " + sql.toString());
    return MRole.getDefault().addAccessSQL(retValue.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
}
Also used : SQLException(java.sql.SQLException) MLookup(org.compiere.model.MLookup) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException)

Example 29 with MLookup

use of org.compiere.model.MLookup in project adempiere by adempiere.

the class WCollectDetail method loadCreditPanel.

/**
	 * Load Credit Panel
	 * @return void
	 */
public void loadCreditPanel() {
    v_CreditPanel = GridFactory.newGridLayout();
    v_CreditPanel.setWidth("100%");
    v_CreditPanel.setHeight("175px");
    Rows rows = v_CreditPanel.newRows();
    Row row = rows.newRow();
    row.setStyle("303px");
    //C_Payment_v.TenderType
    int AD_Column_ID = 8374;
    MLookup cardlookup = MLookupFactory.get(Env.getCtx(), 0, 0, AD_Column_ID, DisplayType.List);
    ArrayList<Object> cards = cardlookup.getData(true, false, true, true);
    row = rows.newRow();
    fCCardType = ListboxFactory.newDropdownListbox();
    row.appendChild(fCCardType);
    fCCardType.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    fCCardType.setValue(Msg.translate(p_ctx, "CreditCardType"));
    fCCardType.addActionListener(this);
    /**
		 *	Load Credit Cards
		 */
    for (Object obj : cards) {
        if (obj instanceof ValueNamePair) {
            ValueNamePair key = (ValueNamePair) obj;
            fCCardType.appendItem(key.getName(), key.getID());
        }
    }
    row.setSpans("1,2");
    fCCardNo = new WPOSTextField(Msg.translate(p_ctx, "CreditCardNumber"), keyboard);
    fCCardNo.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    row.appendChild(fCCardNo);
    fCCardNo.addEventListener("onFocus", this);
    fCCardName = new WPOSTextField(Msg.translate(p_ctx, "Name"), keyboard);
    row = rows.newRow();
    row.appendChild(fCCardName);
    fCCardName.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    fCCardName.addEventListener("onFocus", this);
    //	For Card Month
    fCreditCardExpMM = ListboxFactory.newDropdownListbox();
    ValueNamePair[] data = getCCMonths();
    for (ValueNamePair pp : data) {
        fCreditCardExpMM.appendItem(String.valueOf(pp.getName()), pp.getID());
        fCreditCardExpMM.setName(String.valueOf(pp.getID()));
    }
    fCreditCardExpMM.setName("CreditCardExpMM");
    fCreditCardExpMM.addActionListener(this);
    fCreditCardExpMM.setStyle(HEIGHT + "width:" + 75 + "px;" + FONT_SIZE);
    //	For Card Year
    fCreditCardExpYY = ListboxFactory.newDropdownListbox();
    data = getCCYears();
    for (ValueNamePair pp : data) {
        fCreditCardExpYY.appendItem(String.valueOf(pp.getName()), pp.getID());
        fCreditCardExpYY.setName(String.valueOf(pp.getID()));
    }
    fCreditCardExpYY.setName("CreditCardExpYY");
    fCreditCardExpYY.addActionListener(this);
    fCreditCardExpYY.setStyle("margin: 0px 50px 0px 0px;" + HEIGHT + "width:" + 60 + "px;" + FONT_SIZE);
    //	For Card VV
    row.appendChild(fCreditCardExpMM);
    row.appendChild(fCreditCardExpYY);
    fCCardVC = new WPOSTextField(Msg.translate(p_ctx, "CVC"), keyboard);
    row = rows.newRow();
    row.appendChild(fCCardVC);
    fCCardVC.addEventListener("onFocus", this);
    fCCardVC.setStyle(HEIGHT + WIDTH + FONT_SIZE);
}
Also used : MLookup(org.compiere.model.MLookup) Row(org.adempiere.webui.component.Row) ValueNamePair(org.compiere.util.ValueNamePair) Rows(org.adempiere.webui.component.Rows)

Example 30 with MLookup

use of org.compiere.model.MLookup in project adempiere by adempiere.

the class WTreeBOM method preInit.

//  dynInit
private void preInit() throws Exception {
    Properties ctx = getCtx();
    // Base Language
    Language language = Language.getLoginLanguage();
    MLookup m_fieldProduct = MLookupFactory.get(ctx, m_WindowNo, MColumn.getColumn_ID(MProduct.Table_Name, "M_Product_ID"), DisplayType.Search, language, MProduct.COLUMNNAME_M_Product_ID, 0, false, " M_Product.IsSummary = 'N'");
    fieldProduct = new WSearchEditor("M_Product_ID", true, false, true, m_fieldProduct) {

        public void setValue(Object value) {
            super.setValue(value);
            action_loadBOM();
        }
    };
    implosion.addActionListener(this);
}
Also used : Language(org.compiere.util.Language) MLookup(org.compiere.model.MLookup) WSearchEditor(org.adempiere.webui.editor.WSearchEditor) Properties(java.util.Properties)

Aggregations

MLookup (org.compiere.model.MLookup)62 VLookup (org.compiere.grid.ed.VLookup)25 WSearchEditor (org.adempiere.webui.editor.WSearchEditor)17 Properties (java.util.Properties)14 SQLException (java.sql.SQLException)9 WTableDirEditor (org.adempiere.webui.editor.WTableDirEditor)9 KeyNamePair (org.compiere.util.KeyNamePair)9 Language (org.compiere.util.Language)7 MLocatorLookup (org.compiere.model.MLocatorLookup)6 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 Dimension (java.awt.Dimension)4 Insets (java.awt.Insets)4 BigDecimal (java.math.BigDecimal)4 Row (org.adempiere.webui.component.Row)4 Rows (org.adempiere.webui.component.Rows)4 GridField (org.compiere.model.GridField)4 MColumn (org.compiere.model.MColumn)4 CPanel (org.compiere.swing.CPanel)4 GridBagConstraints (java.awt.GridBagConstraints)3