use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class RModelData method query.
// dispose
/**************************************************************************
* Query
* @param ctx
* @param whereClause the SQL where clause (w/o the WHERE)
* @param orderClause
*/
public void query(Properties ctx, String whereClause, String orderClause) {
RColumn rc = null;
// Create SQL
StringBuffer sql = new StringBuffer("SELECT ");
int size = cols.size();
for (int i = 0; i < size; i++) {
rc = cols.get(i);
if (i > 0)
sql.append(",");
sql.append(rc.getColSQL());
}
sql.append(" FROM ").append(m_TableName).append(" ").append(RModel.TABLE_ALIAS);
if (whereClause != null && whereClause.length() > 0)
sql.append(" WHERE ").append(whereClause);
String finalSQL = MRole.getDefault(ctx, false).addAccessSQL(sql.toString(), RModel.TABLE_ALIAS, MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
if (orderClause != null && orderClause.length() > 0)
finalSQL += " ORDER BY " + orderClause;
log.fine(finalSQL);
// FillData
// rowset index
int index = 0;
m_rows.clear();
try {
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(finalSQL);
while (rs.next()) {
ArrayList<Object> row = new ArrayList<Object>(size);
index = 1;
// Columns
for (int i = 0; i < size; i++) {
rc = cols.get(i);
// Get ID
if (rc.isIDcol())
row.add(new KeyNamePair(rs.getInt(index++), rs.getString(index++)));
else // Null check
if (rs.getObject(index) == null) {
index++;
row.add(null);
} else if (rc.getColClass() == String.class)
row.add(rs.getString(index++));
else if (rc.getColClass() == BigDecimal.class)
row.add(rs.getBigDecimal(index++));
else if (rc.getColClass() == Double.class)
row.add(new Double(rs.getDouble(index++)));
else if (rc.getColClass() == Integer.class)
row.add(new Integer(rs.getInt(index++)));
else if (rc.getColClass() == Timestamp.class)
row.add(rs.getTimestamp(index++));
else if (rc.getColClass() == Boolean.class)
row.add(new Boolean("Y".equals(rs.getString(index++))));
else // should not happen
{
row.add(rs.getString(index++));
}
}
m_rows.add(row);
}
rs.close();
stmt.close();
} catch (SQLException e) {
if (index == 0)
log.log(Level.SEVERE, finalSQL, e);
else
log.log(Level.SEVERE, "Index=" + index + "," + rc, e);
e.printStackTrace();
}
process();
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class ASearch method actionPerformed.
// getSearchTargets
/**
* Action Listener
* @param e event
*/
public void actionPerformed(ActionEvent e) {
m_popup.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
String cmd = e.getActionCommand();
for (int i = 0; i < m_list.size(); i++) {
KeyNamePair pp = (KeyNamePair) m_list.get(i);
if (cmd.equals(pp.getName())) {
launchSearch(pp);
return;
}
}
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class VLookupAutoCompleter method fetchUserObject.
@Override
protected Object fetchUserObject(ResultSet rs) throws SQLException {
final boolean isNumber = lookup.getColumnName().endsWith("_ID");
String name = rs.getString(3);
if (isNumber) {
int key = rs.getInt(1);
KeyNamePair p = new KeyNamePair(key, name);
return p;
} else {
String value = rs.getString(2);
ValueNamePair p = new ValueNamePair(value, name);
return p;
}
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class VLocatorDialog method displayLocator.
/**
* Display value of current locator
*/
private void displayLocator() {
MLocator l = (MLocator) fLocator.getSelectedItem();
if (l == null)
return;
//
m_M_Locator_ID = l.getM_Locator_ID();
fWarehouseInfo.setText(l.getWarehouseName());
fX.setText(l.getX());
fY.setText(l.getY());
fZ.setText(l.getZ());
fValue.setText(l.getValue());
getWarehouseInfo(l.getM_Warehouse_ID());
// Set Warehouse
int size = fWarehouse.getItemCount();
for (int i = 0; i < size; i++) {
KeyNamePair pp = (KeyNamePair) fWarehouse.getItemAt(i);
if (pp.getKey() == l.getM_Warehouse_ID()) {
fWarehouse.setSelectedIndex(i);
continue;
}
}
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class VPAttributeDialog method initAttributes.
// jbInit
/**
* Dyanmic Init.
* @return true if initialized
*/
private boolean initAttributes() {
if (m_M_Product_ID == 0 && !m_productWindow)
return false;
MAttributeSet as = null;
if (m_M_Product_ID != 0) {
// Get Model
m_product = MProduct.get(Env.getCtx(), m_M_Product_ID);
if (m_product.getM_AttributeSetInstance_ID() > 0) {
m_productASI = true;
// The product has an instance associated with it.
if (m_M_AttributeSetInstance_ID != m_product.getM_AttributeSetInstance_ID()) {
log.fine("Different ASI than what is specified on Product!");
}
} else {
// Only show product attributes when in the product window.
m_productASI = m_productWindow;
}
m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
if (m_masi == null) {
log.severe("No Model for M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + ", M_Product_ID=" + m_M_Product_ID);
return false;
}
Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", m_masi.getM_AttributeSet_ID());
// Get Attribute Set
as = m_masi.getMAttributeSet();
} else {
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
m_masi = new MAttributeSetInstance(Env.getCtx(), 0, M_AttributeSet_ID, null);
as = m_masi.getMAttributeSet();
}
// Product has no Attribute Set
if (as == null) {
//ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
//return false;
}
// always read/write. The two are exclusive and can't co-exist.
if (// Set Instance Attributes and dialog controls
!m_productWindow || !m_productASI) {
if (// Instance attributes possible. Set up controls.
!m_productASI) {
// New/Edit - Selection
if (// new
m_M_AttributeSetInstance_ID == 0)
cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "NewRecord"));
else
cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "EditRecord"));
cbNewEdit.addActionListener(this);
centerPanel.add(cbNewEdit, new ALayoutConstraint(m_row++, 0));
bSelect.setText(Msg.getMsg(Env.getCtx(), "SelectExisting"));
bSelect.addActionListener(this);
centerPanel.add(bSelect, null);
}
// Add the Instance Attributes if any. If its a product attribute set
// this will do nothing.
MAttribute[] attributes = as.getMAttributes(true);
log.fine("Instance Attributes=" + attributes.length);
for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], false, false);
}
if (as != null) {
// Product attributes can be shown in any window but are read/write in the Product window only.
// This will do nothing if it is an instance attribute set.
// False = product attribute instances
MAttribute[] attributes = as.getMAttributes(false);
log.fine("Product Attributes=" + attributes.length);
for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], true, !m_productWindow);
}
// Lot
if ((!m_productWindow || !m_productASI) && as.isLot()) {
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Lot"));
label.setLabelFor(fieldLotString);
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldLotString, null);
fieldLotString.setText(m_masi.getLot());
// M_Lot_ID
// int AD_Column_ID = 9771; // M_AttributeSetInstance.M_Lot_ID
// fieldLot = new VLookup ("M_Lot_ID", false,false, true,
// MLookupFactory.get(Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
String sql = "SELECT M_Lot_ID, Name " + "FROM M_Lot l " + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p " + "WHERE p.M_AttributeSet_ID=" + m_masi.getM_AttributeSet_ID() + " AND p.M_Product_ID=l.M_Product_ID)";
fieldLot = new CComboBox(DB.getKeyNamePairs(sql, true));
label = new CLabel(Msg.translate(Env.getCtx(), "M_Lot_ID"));
label.setLabelFor(fieldLot);
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldLot, null);
if (m_masi.getM_Lot_ID() != 0) {
for (int i = 1; i < fieldLot.getItemCount(); i++) {
KeyNamePair pp = (KeyNamePair) fieldLot.getItemAt(i);
if (pp.getKey() == m_masi.getM_Lot_ID()) {
fieldLot.setSelectedIndex(i);
fieldLotString.setEditable(false);
break;
}
}
}
fieldLot.addActionListener(this);
// New Lot Button
if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0 && m_readWrite) {
if (MRole.getDefault().isTableAccess(MLot.Table_ID, false) && MRole.getDefault().isTableAccess(MLotCtl.Table_ID, false) && !m_masi.isExcludeLot(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
centerPanel.add(bLot, null);
bLot.addActionListener(this);
}
}
// Popup
// popup
fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this));
mZoom = new CMenuItem(Msg.getMsg(Env.getCtx(), "Zoom"), Env.getImageIcon("Zoom16.gif"));
mZoom.addActionListener(this);
popupMenu.add(mZoom);
}
// SerNo
if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "SerNo"));
label.setLabelFor(fieldSerNo);
fieldSerNo.setText(m_masi.getSerNo());
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldSerNo, null);
// New SerNo Button
if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0 && m_readWrite) {
if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false) && !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
centerPanel.add(bSerNo, null);
bSerNo.addActionListener(this);
}
}
}
// GuaranteeDate
if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "GuaranteeDate"));
label.setLabelFor(fieldGuaranteeDate);
if (m_M_AttributeSetInstance_ID == 0)
fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
else
fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldGuaranteeDate, null);
}
if (m_row == 0) {
ADialog.error(m_WindowNo, this, "PAttributeNoInfo");
//return false;
}
// New/Edit Window
if ((!m_productWindow || !m_productASI) && m_AD_Column_ID != 0 && m_readWrite) {
cbNewEdit.setSelected(m_M_AttributeSetInstance_ID == 0);
cmd_newEdit();
}
// Attribute Set Instance Description
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Description"));
label.setLabelFor(fieldDescription);
fieldDescription.setText(m_masi.getDescription());
fieldDescription.setEditable(false);
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldDescription, null);
// Window usually to wide (??)
Dimension dd = centerPanel.getPreferredSize();
dd.width = Math.min(500, dd.width);
centerPanel.setPreferredSize(dd);
return true;
}
Aggregations