KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > search > PAttributeInstance


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

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 /**
33  * Display Product Attribute Instance Info
34  *
35  * @author Jorg Janke
36  * @version $Id: PAttributeInstance.java,v 1.4 2003/10/27 15:22:03 jjanke Exp $
37  */

38 public class PAttributeInstance extends CDialog
39     implements ListSelectionListener
40 {
41     /**
42      * Constructor
43      * @param parent InfoProduct
44      * @param M_Warehouse_ID warehouse
45      * @param M_Product_ID product
46      */

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 JavaDoc e)
62         {
63             Log.error("PAttributeInstance", e);
64         }
65         AEnv.showCenterWindow(parent, this);
66     } // PAttributeInstance
67

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     //
74
private MiniTable m_table = new MiniTable();
75     private DefaultTableModel m_model;
76     // Parameter
77
private KeyNamePair m_warehouse;
78     private KeyNamePair m_product;
79     //
80
private int m_M_AttributeSetInstance_ID = -1;
81     
82     /**
83      * Static Init
84      * @throws Exception
85      */

86     private void jbInit() throws Exception JavaDoc
87     {
88         mainPanel.setLayout(mainLayout);
89         this.getContentPane().add(mainPanel, BorderLayout.CENTER);
90         // North
91
mainPanel.add(nothPanel, BorderLayout.NORTH);
92         // Center
93
mainPanel.add(centerScrollPane, BorderLayout.CENTER);
94         centerScrollPane.getViewport().add(m_table, null);
95         // South
96
mainPanel.add(confirmPanel, BorderLayout.SOUTH);
97         confirmPanel.addActionListener(this);
98     } // jbInit
99

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 JavaDoc.class),
104         new ColumnInfo(Msg.translate(Env.getCtx(), "Lot"), "asi.Lot", String JavaDoc.class),
105         new ColumnInfo(Msg.translate(Env.getCtx(), "SerNo"), "asi.SerNo", String JavaDoc.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 JavaDoc.class),
109         new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "s.QtyReserved", Double JavaDoc.class),
110         new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOrdered"), "s.QtyOrdered", Double JavaDoc.class)
111     };
112     private static String JavaDoc 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 JavaDoc s_sqlWhere = "M_Warehouse_ID=? AND M_Product_ID=?"
116         + " AND (s.QtyOnHand<>0 OR s.QtyReserved<>0 OR s.QtyOrdered<>0)";
117
118     /**
119      * Dynamic Init
120      */

121     private void dynInit()
122     {
123         String JavaDoc sql = m_table.prepareTable (s_layout, s_sqlFrom,
124             s_sqlWhere, false, "s")
125             + " ORDER BY asi.GuaranteeDate, s.QtyOnHand"; // oldest, smallest first
126
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 JavaDoc 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 JavaDoc e)
150         {
151             pstmt = null;
152         }
153         //
154
m_table.setRowSelectionAllowed(true);
155         m_table.setMultiSelection(false);
156         m_table.addMouseListener(this);
157         m_table.getSelectionModel().addListSelectionListener(this);
158         enableButtons();
159     } // dynInit
160

161     /**
162      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
163      * @param e event
164      */

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     } // actionPerformed
175

176     /**
177      * Table selection changed
178      * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
179      * @param e event
180      */

181     public void valueChanged(ListSelectionEvent e)
182     {
183         if (e.getValueIsAdjusting())
184             return;
185         enableButtons();
186     } // valueChanged
187

188     /**
189      * Enable/Set Buttons and set ID
190      */

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 JavaDoc 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     } // enableButtons
205

206     /**
207      * Mouse Clicked
208      * @param e event
209      */

210     public void mouseClicked(MouseEvent e)
211     {
212         // Double click with selected row => exit
213
if (e.getClickCount() > 1 && m_table.getSelectedRow() != -1)
214         {
215             enableButtons();
216             dispose();
217         }
218     } // mouseClicked
219

220
221     /**
222      * Get Attribute Set Instance
223      * @return M_AttributeSetInstance_ID or -1
224      */

225     public int getM_AttributeSetInstance_ID()
226     {
227         return m_M_AttributeSetInstance_ID;
228     } // getM_AttributeSetInstance_ID
229

230 } // PAttributeInstance
231
Popular Tags