FR Product Info Window - Add filter by Attribute Set

- implemented for zkwebui
- extend the functionality to filter the attributes by the attribute set selected
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2952085
This commit is contained in:
Carlos Ruiz 2010-02-17 23:05:02 +00:00
parent 8629dfb7b5
commit e0dff39270
4 changed files with 224 additions and 55 deletions

View File

@ -40,6 +40,7 @@ import org.compiere.grid.ed.VLine;
import org.compiere.grid.ed.VNumber;
import org.compiere.grid.ed.VString;
import org.compiere.model.MAttribute;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MRole;
import org.compiere.swing.CDialog;
import org.compiere.swing.CLabel;
@ -62,7 +63,10 @@ public class InfoPAttribute extends CDialog
/**
*
*/
private static final long serialVersionUID = 4307517787262162793L;
private static final long serialVersionUID = -4309055112258081495L;
/* the attribute set selected on the InfoProduct window */
private int p_M_AttributeSet_ID = 0;
/**
* Constructor.
@ -72,6 +76,9 @@ public class InfoPAttribute extends CDialog
public InfoPAttribute (JDialog parent)
{
super (parent, Msg.getMsg(Env.getCtx(), "InfoPAttribute"), true);
if (parent instanceof InfoProduct) {
p_M_AttributeSet_ID = ((InfoProduct)parent).getM_AttributeSet_ID();
}
try
{
jbInit();
@ -131,6 +138,16 @@ public class InfoPAttribute extends CDialog
private void dynInit()
{
int row = addAttributes();
boolean isGuarantee = true;
boolean isSerial = true;
boolean isLot = true;
if (p_M_AttributeSet_ID > 0) {
MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
isGuarantee = as.isGuaranteeDate();
isSerial = as.isSerNo();
isLot = as.isLot();
}
//
String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
guaranteeDateSelection = new VComboBox (new Object[]
@ -138,14 +155,20 @@ public class InfoPAttribute extends CDialog
// guaranteeDateSelection.setPreferredSize();
initLotSelection();
// Fixed Instance Selection Fields
centerPanel.add(serNoLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(serNoField, null);
centerPanel.add(lotLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(lotField, null);
centerPanel.add(lotLabel2, new ALayoutConstraint(row++, 0));
centerPanel.add(lotSelection, null);
centerPanel.add(guaranteeDateSelection, new ALayoutConstraint(row++, 0));
centerPanel.add(guaranteeDateField, null);
if (isSerial) {
centerPanel.add(serNoLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(serNoField, null);
}
if (isLot) {
centerPanel.add(lotLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(lotField, null);
centerPanel.add(lotLabel2, new ALayoutConstraint(row++, 0));
centerPanel.add(lotSelection, null);
}
if (isGuarantee) {
centerPanel.add(guaranteeDateSelection, new ALayoutConstraint(row++, 0));
centerPanel.add(guaranteeDateField, null);
}
//
Dimension d = centerPanel.getPreferredSize();
d.width = 400;
@ -161,17 +184,23 @@ public class InfoPAttribute extends CDialog
int row = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String whereAttributeSet;
if (p_M_AttributeSet_ID > 0)
whereAttributeSet = "AND M_Attribute_ID IN (SELECT M_Attribute_ID FROM M_AttributeUse WHERE M_AttributeSet_ID="+p_M_AttributeSet_ID+")";
else
whereAttributeSet = "";
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute "
+ "WHERE IsActive='Y' "
+ "ORDER BY IsInstanceAttribute, Name",
+ whereAttributeSet
+ " ORDER BY IsInstanceAttribute, Name",
"M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
boolean instanceLine = false;
try
{
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next())
{
int attribute_ID = rs.getInt(1);
@ -231,6 +260,27 @@ public class InfoPAttribute extends CDialog
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// print instance line if not printed
if (!instanceLine) {
boolean isGuarantee = true;
boolean isSerial = true;
boolean isLot = true;
if (p_M_AttributeSet_ID > 0) {
MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
isGuarantee = as.isGuaranteeDate();
isSerial = as.isSerNo();
isLot = as.isLot();
}
if (isGuarantee || isSerial || isLot) {
CPanel group = new CPanel();
group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsInstanceAttribute")));
group.add(Box.createVerticalStrut(VLine.SPACE));
centerPanel.add(group, new ALayoutConstraint(row++, 0));
instanceLine = true;
}
}
return row;
} // addProductAttributes
@ -282,8 +332,13 @@ public class InfoPAttribute extends CDialog
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, ""));
String whereAttributeSet;
if (p_M_AttributeSet_ID > 0)
whereAttributeSet = "AND M_Product_ID IN (SELECT M_Product_ID FROM M_Product WHERE M_AttributeSet_ID="+p_M_AttributeSet_ID+")";
else
whereAttributeSet = "";
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' ORDER BY 2",
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY 2",
"M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
ResultSet rs = null;

View File

@ -82,7 +82,7 @@ public class InfoProduct extends Info implements ActionListener, ChangeListener
/**
*
*/
private static final long serialVersionUID = -2674502713710863413L;
private static final long serialVersionUID = 2076229793041196087L;
/**
* Standard Constructor

View File

@ -34,6 +34,7 @@ import org.adempiere.webui.editor.WNumberEditor;
import org.adempiere.webui.editor.WStringEditor;
import org.compiere.apps.search.InfoPAttribute;
import org.compiere.model.MAttribute;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MRole;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -60,7 +61,10 @@ public class InfoPAttributePanel extends Window implements EventListener
/**
*
*/
private static final long serialVersionUID = -6385043105828153806L;
private static final long serialVersionUID = -4922961793415942591L;
/* the attribute set selected on the InfoProduct window */
private int p_M_AttributeSet_ID = 0;
/**
* Constructor.
@ -70,6 +74,9 @@ public class InfoPAttributePanel extends Window implements EventListener
public InfoPAttributePanel(Window parent)
{
super();
if (parent instanceof InfoProductPanel) {
p_M_AttributeSet_ID = ((InfoProductPanel)parent).getM_AttributeSet_ID();
}
setTitle(Msg.getMsg(Env.getCtx(), "InfoPAttribute"));
this.setBorder("normal");
this.setMaximizable(true);
@ -141,6 +148,16 @@ public class InfoPAttributePanel extends Window implements EventListener
private void dynInit()
{
addAttributes();
boolean isGuarantee = true;
boolean isSerial = true;
boolean isLot = true;
if (p_M_AttributeSet_ID > 0) {
MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
isGuarantee = as.isGuaranteeDate();
isSerial = as.isSerNo();
isLot = as.isLot();
}
//
String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
guaranteeDateSelection = new Listbox();
@ -154,39 +171,47 @@ public class InfoPAttributePanel extends Window implements EventListener
initLotSelection();
// Fixed Instance Selection Fields
Row row = new Row();
rows.appendChild(row);
Div div = new Div();
div.setAlign("right");
div.appendChild(serNoLabel);
row.appendChild(div);
row.appendChild(serNoField.getComponent());
serNoField.getComponent().setWidth("150px");
Row row;
Div div;
if (isSerial) {
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(serNoLabel);
row.appendChild(div);
row.appendChild(serNoField.getComponent());
serNoField.getComponent().setWidth("150px");
}
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(lotLabel);
row.appendChild(div);
row.appendChild(lotField.getComponent());
lotField.getComponent().setWidth("150px");
if (isLot) {
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(lotLabel);
row.appendChild(div);
row.appendChild(lotField.getComponent());
lotField.getComponent().setWidth("150px");
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(lotLabel2);
row.appendChild(div);
row.appendChild(lotSelection);
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(lotLabel2);
row.appendChild(div);
row.appendChild(lotSelection);
}
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(guaranteeDateSelection);
row.appendChild(div);
row.appendChild(guaranteeDateField);
if (isGuarantee) {
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(guaranteeDateSelection);
row.appendChild(div);
row.appendChild(guaranteeDateField);
}
} // dynInit
/**
@ -197,17 +222,23 @@ public class InfoPAttributePanel extends Window implements EventListener
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String whereAttributeSet;
if (p_M_AttributeSet_ID > 0)
whereAttributeSet = "AND M_Attribute_ID IN (SELECT M_Attribute_ID FROM M_AttributeUse WHERE M_AttributeSet_ID="+p_M_AttributeSet_ID+")";
else
whereAttributeSet = "";
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute "
+ "WHERE IsActive='Y' "
+ "ORDER BY IsInstanceAttribute, Name",
+ whereAttributeSet
+ " ORDER BY IsInstanceAttribute, Name",
"M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
boolean instanceLine = false;
try
{
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next())
{
int attribute_ID = rs.getInt(1);
@ -307,6 +338,38 @@ public class InfoPAttributePanel extends Window implements EventListener
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// print instance line if not printed
if (!instanceLine) {
boolean isGuarantee = true;
boolean isSerial = true;
boolean isLot = true;
if (p_M_AttributeSet_ID > 0) {
MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
isGuarantee = as.isGuaranteeDate();
isSerial = as.isSerNo();
isLot = as.isLot();
}
if (isGuarantee || isSerial || isLot) {
Row row = new Row();
rows.appendChild(row);
row.setSpans("2");
Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
row.appendChild(group);
rows.appendChild(row);
row = new Row();
rows.appendChild(row);
row.setSpans("2");
Separator separator = new Separator();
separator.setBar(true);
row.appendChild(separator);
rows.appendChild(row);
instanceLine = true;
}
}
return 0;
} // addProductAttributes
@ -358,8 +421,13 @@ public class InfoPAttributePanel extends Window implements EventListener
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, ""));
String whereAttributeSet;
if (p_M_AttributeSet_ID > 0)
whereAttributeSet = "AND M_Product_ID IN (SELECT M_Product_ID FROM M_Product WHERE M_AttributeSet_ID="+p_M_AttributeSet_ID+")";
else
whereAttributeSet = "";
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' ORDER BY 2",
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY 2",
"M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
ResultSet rs = null;

View File

@ -97,7 +97,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener
/**
*
*/
private static final long serialVersionUID = 73880400775610395L;
private static final long serialVersionUID = 6804975825156657866L;
private Label lblValue = new Label();
private Textbox fieldValue = new Textbox();
private Label lblName = new Label();
@ -116,6 +116,8 @@ public class InfoProductPanel extends InfoPanel implements EventListener
private Label lblProductCategory = new Label();
private Listbox pickProductCategory = new Listbox();
//
private Label lblAS = new Label();
private Listbox pickAS = new Listbox();
// Elaine 2008/11/25
private Borderlayout borderlayout = new Borderlayout();
@ -219,6 +221,8 @@ public class InfoProductPanel extends InfoPanel implements EventListener
lblProductCategory = new Label();
lblProductCategory.setValue(Msg.translate(Env.getCtx(), "M_Product_Category_ID"));
//
lblAS = new Label();
lblAS.setValue(Msg.translate(Env.getCtx(), "M_AttributeSet_ID"));
lblWarehouse = new Label();
lblWarehouse.setValue(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Warehouse")));
lblVendor = new Label();
@ -251,6 +255,12 @@ public class InfoProductPanel extends InfoPanel implements EventListener
pickProductCategory.setWidth("150px");
pickProductCategory.addEventListener(Events.ON_SELECT, this);
//
pickAS = new Listbox();
pickAS.setRows(0);
pickAS.setMultiple(false);
pickAS.setMold("select");
pickAS.setWidth("150px");
pickAS.addEventListener(Events.ON_SELECT, this);
pickWarehouse = new Listbox();
pickWarehouse.setRows(0);
@ -281,8 +291,6 @@ public class InfoProductPanel extends InfoPanel implements EventListener
row.appendChild(fieldUPC);
row.appendChild(lblWarehouse.rightAlign());
row.appendChild(pickWarehouse);
row.appendChild(lblPriceList.rightAlign());
row.appendChild(pickPriceList);
row.appendChild(m_InfoPAttributeButton);
row = new Row();
@ -294,11 +302,18 @@ public class InfoProductPanel extends InfoPanel implements EventListener
row.appendChild(fieldSKU);
row.appendChild(lblVendor.rightAlign());
row.appendChild(fieldVendor);
row.appendChild(lblProductCategory.rightAlign());
row.appendChild(pickProductCategory);
//
// Product Attribute Instance
row = new Row();
rows.appendChild(row);
row.appendChild(lblPriceList.rightAlign());
row.appendChild(pickPriceList);
row.appendChild(lblProductCategory.rightAlign());
row.appendChild(pickProductCategory);
row.appendChild(lblAS.rightAlign());
row.appendChild(pickAS);
// Product Attribute Instance
m_PAttributeButton = confirmPanel.createButton(ConfirmPanel.A_PATTRIBUTE);
confirmPanel.addComponentsLeft(m_PAttributeButton);
m_PAttributeButton.addActionListener(this);
@ -609,6 +624,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener
pickWarehouse.addEventListener(Events.ON_SELECT,this);
pickPriceList.addEventListener(Events.ON_SELECT,this);
pickProductCategory.addEventListener(Events.ON_SELECT, this); // Elaine 2008/11/21
pickAS.addEventListener(Events.ON_SELECT, this);
} // initInfo
/**
@ -670,7 +686,15 @@ public class InfoProductPanel extends InfoPanel implements EventListener
for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) {
pickProductCategory.addItem(kn);
}
//
// Attribute Sets
SQL = MRole.getDefault().addAccessSQL (
"SELECT M_AttributeSet_ID, Name FROM M_AttributeSet WHERE IsActive='Y'",
"M_AttributeSet", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO)
+ " ORDER BY Name";
for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) {
pickAS.addItem(kn);
}
}
catch (SQLException e)
{
@ -797,6 +821,11 @@ public class InfoProductPanel extends InfoPanel implements EventListener
}
//
// Optional Attribute Set
if (getM_AttributeSet_ID() > 0) {
where.append(" AND p.M_AttributeSet_ID=?");
}
// Product Attribute Search
if (m_pAttributeWhere != null)
{
@ -875,6 +904,11 @@ public class InfoProductPanel extends InfoPanel implements EventListener
log.fine("M_Product_Category_ID=" + M_Product_Category_ID);
}
//
int M_AttributeSet_ID = getM_AttributeSet_ID();
if (M_AttributeSet_ID > 0) {
pstmt.setInt(index++, M_AttributeSet_ID);
log.fine("M_AttributeSet_ID=" + M_AttributeSet_ID);
}
// Rest of Parameter in Query for Attribute Search
if (m_pAttributeWhere != null)
return;
@ -1389,4 +1423,16 @@ public class InfoProductPanel extends InfoPanel implements EventListener
return M_Product_Category_ID;
}
//
public int getM_AttributeSet_ID()
{
int M_AttributeSet_ID = 0;
ListItem itemAS = (ListItem)pickAS.getSelectedItem();
if (itemAS!=null)
M_AttributeSet_ID = Integer.parseInt(itemAS.getValue().toString());
return M_AttributeSet_ID;
}
} // InfoProduct