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.VNumber;
import org.compiere.grid.ed.VString; import org.compiere.grid.ed.VString;
import org.compiere.model.MAttribute; import org.compiere.model.MAttribute;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.swing.CDialog; import org.compiere.swing.CDialog;
import org.compiere.swing.CLabel; 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. * Constructor.
@ -72,6 +76,9 @@ public class InfoPAttribute extends CDialog
public InfoPAttribute (JDialog parent) public InfoPAttribute (JDialog parent)
{ {
super (parent, Msg.getMsg(Env.getCtx(), "InfoPAttribute"), true); super (parent, Msg.getMsg(Env.getCtx(), "InfoPAttribute"), true);
if (parent instanceof InfoProduct) {
p_M_AttributeSet_ID = ((InfoProduct)parent).getM_AttributeSet_ID();
}
try try
{ {
jbInit(); jbInit();
@ -131,6 +138,16 @@ public class InfoPAttribute extends CDialog
private void dynInit() private void dynInit()
{ {
int row = addAttributes(); 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"); String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
guaranteeDateSelection = new VComboBox (new Object[] guaranteeDateSelection = new VComboBox (new Object[]
@ -138,14 +155,20 @@ public class InfoPAttribute extends CDialog
// guaranteeDateSelection.setPreferredSize(); // guaranteeDateSelection.setPreferredSize();
initLotSelection(); initLotSelection();
// Fixed Instance Selection Fields // Fixed Instance Selection Fields
centerPanel.add(serNoLabel, new ALayoutConstraint(row++, 0)); if (isSerial) {
centerPanel.add(serNoField, null); centerPanel.add(serNoLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(lotLabel, new ALayoutConstraint(row++, 0)); centerPanel.add(serNoField, null);
centerPanel.add(lotField, null); }
centerPanel.add(lotLabel2, new ALayoutConstraint(row++, 0)); if (isLot) {
centerPanel.add(lotSelection, null); centerPanel.add(lotLabel, new ALayoutConstraint(row++, 0));
centerPanel.add(guaranteeDateSelection, new ALayoutConstraint(row++, 0)); centerPanel.add(lotField, null);
centerPanel.add(guaranteeDateField, 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(); Dimension d = centerPanel.getPreferredSize();
d.width = 400; d.width = 400;
@ -161,17 +184,23 @@ public class InfoPAttribute extends CDialog
int row = 0; int row = 0;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = 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( String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute " "SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute " + "FROM M_Attribute "
+ "WHERE IsActive='Y' " + "WHERE IsActive='Y' "
+ "ORDER BY IsInstanceAttribute, Name", + whereAttributeSet
+ " ORDER BY IsInstanceAttribute, Name",
"M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); "M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
boolean instanceLine = false;
try try
{ {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next()) while (rs.next())
{ {
int attribute_ID = rs.getInt(1); int attribute_ID = rs.getInt(1);
@ -231,6 +260,27 @@ public class InfoPAttribute extends CDialog
DB.close(rs, pstmt); DB.close(rs, pstmt);
rs = null; pstmt = null; 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; return row;
} // addProductAttributes } // addProductAttributes
@ -282,8 +332,13 @@ public class InfoPAttribute extends CDialog
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>(); ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, "")); 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( 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); "M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = 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 * Standard Constructor

View File

@ -34,6 +34,7 @@ import org.adempiere.webui.editor.WNumberEditor;
import org.adempiere.webui.editor.WStringEditor; import org.adempiere.webui.editor.WStringEditor;
import org.compiere.apps.search.InfoPAttribute; import org.compiere.apps.search.InfoPAttribute;
import org.compiere.model.MAttribute; import org.compiere.model.MAttribute;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -60,8 +61,11 @@ 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. * Constructor.
* Called from InfoProduct,cmd_InfoPAttribute * Called from InfoProduct,cmd_InfoPAttribute
@ -70,6 +74,9 @@ public class InfoPAttributePanel extends Window implements EventListener
public InfoPAttributePanel(Window parent) public InfoPAttributePanel(Window parent)
{ {
super(); super();
if (parent instanceof InfoProductPanel) {
p_M_AttributeSet_ID = ((InfoProductPanel)parent).getM_AttributeSet_ID();
}
setTitle(Msg.getMsg(Env.getCtx(), "InfoPAttribute")); setTitle(Msg.getMsg(Env.getCtx(), "InfoPAttribute"));
this.setBorder("normal"); this.setBorder("normal");
this.setMaximizable(true); this.setMaximizable(true);
@ -141,6 +148,16 @@ public class InfoPAttributePanel extends Window implements EventListener
private void dynInit() private void dynInit()
{ {
addAttributes(); 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"); String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
guaranteeDateSelection = new Listbox(); guaranteeDateSelection = new Listbox();
@ -154,39 +171,47 @@ public class InfoPAttributePanel extends Window implements EventListener
initLotSelection(); initLotSelection();
// Fixed Instance Selection Fields // Fixed Instance Selection Fields
Row row = new Row(); Row row;
rows.appendChild(row); Div div;
Div div = new Div(); if (isSerial) {
div.setAlign("right"); row = new Row();
div.appendChild(serNoLabel); rows.appendChild(row);
row.appendChild(div); div = new Div();
row.appendChild(serNoField.getComponent()); div.setAlign("right");
serNoField.getComponent().setWidth("150px"); div.appendChild(serNoLabel);
row.appendChild(div);
row.appendChild(serNoField.getComponent());
serNoField.getComponent().setWidth("150px");
}
row = new Row(); if (isLot) {
rows.appendChild(row); row = new Row();
div = new Div(); rows.appendChild(row);
div.setAlign("right"); div = new Div();
div.appendChild(lotLabel); div.setAlign("right");
row.appendChild(div); div.appendChild(lotLabel);
row.appendChild(lotField.getComponent()); row.appendChild(div);
lotField.getComponent().setWidth("150px"); row.appendChild(lotField.getComponent());
lotField.getComponent().setWidth("150px");
row = new Row(); row = new Row();
rows.appendChild(row); rows.appendChild(row);
div = new Div(); div = new Div();
div.setAlign("right"); div.setAlign("right");
div.appendChild(lotLabel2); div.appendChild(lotLabel2);
row.appendChild(div); row.appendChild(div);
row.appendChild(lotSelection); row.appendChild(lotSelection);
}
row = new Row();
rows.appendChild(row); if (isGuarantee) {
div = new Div(); row = new Row();
div.setAlign("right"); rows.appendChild(row);
div.appendChild(guaranteeDateSelection); div = new Div();
row.appendChild(div); div.setAlign("right");
row.appendChild(guaranteeDateField); div.appendChild(guaranteeDateSelection);
row.appendChild(div);
row.appendChild(guaranteeDateField);
}
} // dynInit } // dynInit
/** /**
@ -197,17 +222,23 @@ public class InfoPAttributePanel extends Window implements EventListener
{ {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = 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( String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute " "SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute " + "FROM M_Attribute "
+ "WHERE IsActive='Y' " + "WHERE IsActive='Y' "
+ "ORDER BY IsInstanceAttribute, Name", + whereAttributeSet
+ " ORDER BY IsInstanceAttribute, Name",
"M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); "M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
boolean instanceLine = false;
try try
{ {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next()) while (rs.next())
{ {
int attribute_ID = rs.getInt(1); int attribute_ID = rs.getInt(1);
@ -307,6 +338,38 @@ public class InfoPAttributePanel extends Window implements EventListener
DB.close(rs, pstmt); DB.close(rs, pstmt);
rs = null; pstmt = null; 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; return 0;
} // addProductAttributes } // addProductAttributes
@ -358,8 +421,13 @@ public class InfoPAttributePanel extends Window implements EventListener
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>(); ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, "")); 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( 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); "M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = 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 Label lblValue = new Label();
private Textbox fieldValue = new Textbox(); private Textbox fieldValue = new Textbox();
private Label lblName = new Label(); private Label lblName = new Label();
@ -116,6 +116,8 @@ public class InfoProductPanel extends InfoPanel implements EventListener
private Label lblProductCategory = new Label(); private Label lblProductCategory = new Label();
private Listbox pickProductCategory = new Listbox(); private Listbox pickProductCategory = new Listbox();
// //
private Label lblAS = new Label();
private Listbox pickAS = new Listbox();
// Elaine 2008/11/25 // Elaine 2008/11/25
private Borderlayout borderlayout = new Borderlayout(); private Borderlayout borderlayout = new Borderlayout();
@ -219,6 +221,8 @@ public class InfoProductPanel extends InfoPanel implements EventListener
lblProductCategory = new Label(); lblProductCategory = new Label();
lblProductCategory.setValue(Msg.translate(Env.getCtx(), "M_Product_Category_ID")); 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 = new Label();
lblWarehouse.setValue(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Warehouse"))); lblWarehouse.setValue(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Warehouse")));
lblVendor = new Label(); lblVendor = new Label();
@ -251,6 +255,12 @@ public class InfoProductPanel extends InfoPanel implements EventListener
pickProductCategory.setWidth("150px"); pickProductCategory.setWidth("150px");
pickProductCategory.addEventListener(Events.ON_SELECT, this); 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 = new Listbox();
pickWarehouse.setRows(0); pickWarehouse.setRows(0);
@ -281,8 +291,6 @@ public class InfoProductPanel extends InfoPanel implements EventListener
row.appendChild(fieldUPC); row.appendChild(fieldUPC);
row.appendChild(lblWarehouse.rightAlign()); row.appendChild(lblWarehouse.rightAlign());
row.appendChild(pickWarehouse); row.appendChild(pickWarehouse);
row.appendChild(lblPriceList.rightAlign());
row.appendChild(pickPriceList);
row.appendChild(m_InfoPAttributeButton); row.appendChild(m_InfoPAttributeButton);
row = new Row(); row = new Row();
@ -294,11 +302,18 @@ public class InfoProductPanel extends InfoPanel implements EventListener
row.appendChild(fieldSKU); row.appendChild(fieldSKU);
row.appendChild(lblVendor.rightAlign()); row.appendChild(lblVendor.rightAlign());
row.appendChild(fieldVendor); 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); m_PAttributeButton = confirmPanel.createButton(ConfirmPanel.A_PATTRIBUTE);
confirmPanel.addComponentsLeft(m_PAttributeButton); confirmPanel.addComponentsLeft(m_PAttributeButton);
m_PAttributeButton.addActionListener(this); m_PAttributeButton.addActionListener(this);
@ -609,6 +624,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener
pickWarehouse.addEventListener(Events.ON_SELECT,this); pickWarehouse.addEventListener(Events.ON_SELECT,this);
pickPriceList.addEventListener(Events.ON_SELECT,this); pickPriceList.addEventListener(Events.ON_SELECT,this);
pickProductCategory.addEventListener(Events.ON_SELECT, this); // Elaine 2008/11/21 pickProductCategory.addEventListener(Events.ON_SELECT, this); // Elaine 2008/11/21
pickAS.addEventListener(Events.ON_SELECT, this);
} // initInfo } // initInfo
/** /**
@ -670,7 +686,15 @@ public class InfoProductPanel extends InfoPanel implements EventListener
for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) { for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) {
pickProductCategory.addItem(kn); 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) 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 // Product Attribute Search
if (m_pAttributeWhere != null) 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); 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 // Rest of Parameter in Query for Attribute Search
if (m_pAttributeWhere != null) if (m_pAttributeWhere != null)
return; return;
@ -1389,4 +1423,16 @@ public class InfoProductPanel extends InfoPanel implements EventListener
return M_Product_Category_ID; 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 } // InfoProduct