1 14 package org.compiere.apps.search; 15 16 import javax.swing.*; 17 import javax.swing.event.*; 18 import javax.swing.table.*; 19 import java.awt.*; 20 import java.awt.event.*; 21 import java.util.*; 22 import java.math.*; 23 import java.sql.*; 24 25 import org.compiere.apps.*; 26 import org.compiere.swing.*; 27 import org.compiere.plaf.*; 28 import org.compiere.minigrid.*; 29 import org.compiere.util.*; 30 31 32 38 public class PAttributeInstance extends CDialog 39 implements ListSelectionListener 40 { 41 47 public PAttributeInstance(JDialog parent, 48 KeyNamePair Warehouse, KeyNamePair Product) 49 { 50 super (parent, Msg.getMsg(Env.getCtx(), "PAttributeInstance") 51 + " - " + Warehouse + " - " + Product, true); 52 Log.trace(Log.l3_Util, "PAttributeInstance", 53 "M_Warehouse_ID=" + Warehouse.getKey() + ", M_Product_ID=" + Product.getKey()); 54 m_warehouse = Warehouse; 55 m_product = Product; 56 try 57 { 58 jbInit(); 59 dynInit(); 60 } 61 catch (Exception e) 62 { 63 Log.error("PAttributeInstance", e); 64 } 65 AEnv.showCenterWindow(parent, this); 66 } 68 private CPanel mainPanel = new CPanel(); 69 private BorderLayout mainLayout = new BorderLayout(); 70 private CPanel nothPanel = new CPanel(); 71 private JScrollPane centerScrollPane = new JScrollPane(); 72 private ConfirmPanel confirmPanel = new ConfirmPanel (true); 73 private MiniTable m_table = new MiniTable(); 75 private DefaultTableModel m_model; 76 private KeyNamePair m_warehouse; 78 private KeyNamePair m_product; 79 private int m_M_AttributeSetInstance_ID = -1; 81 82 86 private void jbInit() throws Exception 87 { 88 mainPanel.setLayout(mainLayout); 89 this.getContentPane().add(mainPanel, BorderLayout.CENTER); 90 mainPanel.add(nothPanel, BorderLayout.NORTH); 92 mainPanel.add(centerScrollPane, BorderLayout.CENTER); 94 centerScrollPane.getViewport().add(m_table, null); 95 mainPanel.add(confirmPanel, BorderLayout.SOUTH); 97 confirmPanel.addActionListener(this); 98 } 100 private static ColumnInfo[] s_layout = new ColumnInfo[] 101 { 102 new ColumnInfo(" ", "s.M_AttributeSetInstance_ID", IDColumn.class), 103 new ColumnInfo(Msg.translate(Env.getCtx(), "Description"), "asi.Description", String .class), 104 new ColumnInfo(Msg.translate(Env.getCtx(), "Lot"), "asi.Lot", String .class), 105 new ColumnInfo(Msg.translate(Env.getCtx(), "SerNo"), "asi.SerNo", String .class), 106 new ColumnInfo(Msg.translate(Env.getCtx(), "GuaranteeDate"), "asi.GuaranteeDate", Timestamp.class), 107 new ColumnInfo(Msg.translate(Env.getCtx(), "M_Locator_ID"), "l.Value", KeyNamePair.class, "s.M_Locator_ID"), 108 new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "s.QtyOnHand", Double .class), 109 new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "s.QtyReserved", Double .class), 110 new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOrdered"), "s.QtyOrdered", Double .class) 111 }; 112 private static String s_sqlFrom = "M_Storage s" 113 + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)" 114 + " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID)"; 115 private static String s_sqlWhere = "M_Warehouse_ID=? AND M_Product_ID=?" 116 + " AND (s.QtyOnHand<>0 OR s.QtyReserved<>0 OR s.QtyOrdered<>0)"; 117 118 121 private void dynInit() 122 { 123 String sql = m_table.prepareTable (s_layout, s_sqlFrom, 124 s_sqlWhere, false, "s") 125 + " ORDER BY asi.GuaranteeDate, s.QtyOnHand"; Log.trace(Log.l6_Database, "PAttributeInstance.dynInit", sql); 127 PreparedStatement pstmt = null; 128 try 129 { 130 pstmt = DB.prepareCall(sql); 131 pstmt.setInt(1, m_warehouse.getKey()); 132 pstmt.setInt(2, m_product.getKey()); 133 ResultSet rs = pstmt.executeQuery(); 134 m_table.loadTable(rs); 135 rs.close(); 136 pstmt.close(); 137 pstmt = null; 138 } 139 catch (Exception e) 140 { 141 Log.error("dynInit", e); 142 } 143 try 144 { 145 if (pstmt != null) 146 pstmt.close(); 147 pstmt = null; 148 } 149 catch (Exception e) 150 { 151 pstmt = null; 152 } 153 m_table.setRowSelectionAllowed(true); 155 m_table.setMultiSelection(false); 156 m_table.addMouseListener(this); 157 m_table.getSelectionModel().addListSelectionListener(this); 158 enableButtons(); 159 } 161 165 public void actionPerformed(ActionEvent e) 166 { 167 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 168 dispose(); 169 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 170 { 171 dispose(); 172 m_M_AttributeSetInstance_ID = -1; 173 } 174 } 176 181 public void valueChanged(ListSelectionEvent e) 182 { 183 if (e.getValueIsAdjusting()) 184 return; 185 enableButtons(); 186 } 188 191 private void enableButtons() 192 { 193 m_M_AttributeSetInstance_ID = -1; 194 int row = m_table.getSelectedRow(); 195 boolean enabled = row != -1; 196 if (enabled) 197 { 198 Integer ID = m_table.getSelectedRowKey(); 199 if (ID != null) 200 m_M_AttributeSetInstance_ID = ID.intValue(); 201 } 202 confirmPanel.getOKButton().setEnabled(enabled); 203 Log.trace(Log.l6_Database, "PAttributeInstance.enableButtons", "M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID); 204 } 206 210 public void mouseClicked(MouseEvent e) 211 { 212 if (e.getClickCount() > 1 && m_table.getSelectedRow() != -1) 214 { 215 enableButtons(); 216 dispose(); 217 } 218 } 220 221 225 public int getM_AttributeSetInstance_ID() 226 { 227 return m_M_AttributeSetInstance_ID; 228 } 230 } | Popular Tags |