Search in sources :

Example 41 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WAcctViewerData method fillAcctSchema.

// dispose
/**************************************************************************
	 *  Fill Accounting Schema
	 *  @param cb Listbox to be filled
	 */
protected void fillAcctSchema(Listbox cb) {
    for (int i = 0; i < ASchemas.length; i++) {
        KeyNamePair key = new KeyNamePair(ASchemas[i].getC_AcctSchema_ID(), ASchemas[i].getName());
        cb.appendItem(key.getName(), key);
    }
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 42 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class ZkReportViewer method fillComboReport.

//	dynInit
/**
	 * 	Fill ComboBox comboReport (report options)
	 *  @param AD_PrintFormat_ID item to be selected
	 */
private void fillComboReport(int AD_PrintFormat_ID) {
    comboReport.removeEventListener(Events.ON_SELECT, this);
    comboReport.getItems().clear();
    Listitem selectValue = null;
    //	fill Report Options
    String sql = MRole.getDefault().addAccessSQL("SELECT AD_PrintFormat_ID, Name, Description " + "FROM AD_PrintFormat " + "WHERE AD_Table_ID=? " + //Added Lines by Armen
    "AND IsActive='Y' " + //End of Added Lines
    "ORDER BY Name", "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Table_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            Listitem li = comboReport.appendItem(pp.getName(), pp.getKey());
            if (rs.getInt(1) == AD_PrintFormat_ID) {
                selectValue = li;
                comboReport.setSelectedItem(li);
            }
        }
        //	Select Default
        if (selectValue != null) {
            comboReport.setSelectedItem(selectValue);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    StringBuffer sb = new StringBuffer("** ").append(Msg.getMsg(Env.getCtx(), "NewReport")).append(" **");
    KeyNamePair pp = new KeyNamePair(-1, sb.toString());
    comboReport.appendItem(pp.getName(), pp.getKey());
    sb = new StringBuffer("** ").append(Msg.getMsg(m_ctx, "CopyReport")).append(" **");
    pp = new KeyNamePair(-2, sb.toString());
    comboReport.addItem(pp);
    comboReport.addEventListener(Events.ON_SELECT, this);
    //	FR [ 237 ]
    fillComboReportView();
}
Also used : SQLException(java.sql.SQLException) Listitem(org.zkoss.zul.Listitem) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair)

Example 43 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class MLookup method getData.

//	getData
/**
	 *	Return data as Array containing Value/KeyNamePair
	 *  @param mandatory if not mandatory, an additional empty value is inserted
	 *  @param onlyValidated only validated
	 *  @param onlyActive only active
	 * 	@param temporary force load for temporary display
	 *  @return list
	 */
public ArrayList<Object> getData(boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary) {
    //	create list
    ArrayList<Object> list = getData(onlyValidated, true);
    //  Remove inactive choices
    if (onlyActive && m_hasInactive) {
        //  list from the back
        for (int i = list.size(); i > 0; i--) {
            Object o = list.get(i - 1);
            if (o != null) {
                String s = o.toString();
                if (s.startsWith(INACTIVE_S) && s.endsWith(INACTIVE_E))
                    list.remove(i - 1);
            }
        }
    }
    //	Add Optional (empty) selection
    if (!mandatory) {
        NamePair p = null;
        if (m_info.KeyColumn != null && m_info.KeyColumn.endsWith("_ID"))
            p = new KeyNamePair(-1, "");
        else
            p = new ValueNamePair("", "");
        list.add(0, p);
    }
    return list;
}
Also used : NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair)

Example 44 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class MLookup method getDirect.

/**
	 *	Get Data Direct from Table.
	 *  @param key key
	 *  @param saveInCache save in cache for r/w
	 * 	@param cacheLocal cache locally for r/o
	 *  @return value
	 */
public NamePair getDirect(Object key, boolean saveInCache, boolean cacheLocal) {
    //	Nothing to query
    if (key == null || m_info.QueryDirect == null || m_info.QueryDirect.length() == 0)
        return null;
    if (key.equals(m_directNullKey))
        return null;
    //
    NamePair directValue = null;
    if (//	Lookup cache
    m_lookupDirect != null) {
        directValue = (NamePair) m_lookupDirect.get(key);
        if (directValue != null)
            return directValue;
    }
    log.finer(m_info.KeyColumn + ": " + key + ", SaveInCache=" + saveInCache + ",Local=" + cacheLocal);
    boolean isNumber = m_info.KeyColumn.endsWith("_ID");
    try {
        //	SELECT Key, Value, Name FROM ...
        PreparedStatement pstmt = DB.prepareStatement(m_info.QueryDirect, null);
        if (isNumber)
            pstmt.setInt(1, Integer.parseInt(key.toString()));
        else
            pstmt.setString(1, key.toString());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            String name = rs.getString(3);
            if (isNumber) {
                int keyValue = rs.getInt(1);
                KeyNamePair p = new KeyNamePair(keyValue, name);
                if (//	save if
                saveInCache)
                    m_lookup.put(new Integer(keyValue), p);
                directValue = p;
            } else {
                String value = rs.getString(2);
                ValueNamePair p = new ValueNamePair(value, name);
                if (//	save if
                saveInCache)
                    m_lookup.put(value, p);
                directValue = p;
            }
            if (rs.next())
                log.log(Level.SEVERE, m_info.KeyColumn + ": Not unique (first returned) for " + key + " SQL=" + m_info.QueryDirect);
        } else {
            m_directNullKey = key;
            directValue = null;
        }
        rs.close();
        pstmt.close();
        if (CLogMgt.isLevelFinest())
            log.finest(m_info.KeyColumn + ": " + directValue + " - " + m_info);
    } catch (Exception e) {
        log.log(Level.SEVERE, m_info.KeyColumn + ": SQL=" + m_info.QueryDirect + "; Key=" + key, e);
        directValue = null;
    }
    //	Cache Local if not added to R/W cache
    if (cacheLocal && !saveInCache && directValue != null) {
        if (m_lookupDirect == null)
            m_lookupDirect = new HashMap<Object, Object>();
        m_lookupDirect.put(key, directValue);
    }
    m_hasInactive = true;
    return directValue;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair) SQLException(java.sql.SQLException)

Example 45 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class MLocatorLookup method getDirect.

//  containsKey
/**
	 *	Get Data Direct from Table
	 *  @param keyValue integer key value
	 *  @param saveInCache save in cache
	 *  @param trxName transaction
	 *  @return Object directly loaded
	 */
public NamePair getDirect(Object keyValue, boolean saveInCache, String trxName) {
    MLocator loc = getMLocator(keyValue, trxName);
    if (loc == null)
        return null;
    //
    int key = loc.getM_Locator_ID();
    if (saveInCache)
        m_lookup.put(new Integer(key), loc);
    NamePair retValue = new KeyNamePair(key, loc.toString());
    return retValue;
}
Also used : NamePair(org.compiere.util.NamePair) KeyNamePair(org.compiere.util.KeyNamePair) KeyNamePair(org.compiere.util.KeyNamePair)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7