KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > form > VTrxMaterial


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.form;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Cursor JavaDoc;
18 import java.awt.GridBagConstraints JavaDoc;
19 import java.awt.GridBagLayout JavaDoc;
20 import java.awt.Insets JavaDoc;
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.VetoableChangeListener JavaDoc;
25 import java.sql.PreparedStatement JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.sql.Timestamp JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import javax.swing.JLabel JavaDoc;
32
33 import org.compiere.apps.AEnv;
34 import org.compiere.apps.AWindow;
35 import org.compiere.apps.ConfirmPanel;
36 import org.compiere.apps.StatusBar;
37 import org.compiere.grid.GridController;
38 import org.compiere.grid.ed.VDate;
39 import org.compiere.grid.ed.VLocator;
40 import org.compiere.grid.ed.VLookup;
41 import org.compiere.model.MLocatorLookup;
42 import org.compiere.model.MLookup;
43 import org.compiere.model.MLookupFactory;
44 import org.compiere.model.MQuery;
45 import org.compiere.model.MTab;
46 import org.compiere.model.MWindow;
47 import org.compiere.model.MWindowVO;
48 import org.compiere.plaf.CompiereColor;
49 import org.compiere.swing.CPanel;
50 import org.compiere.util.DB;
51 import org.compiere.util.DisplayType;
52 import org.compiere.util.Env;
53 import org.compiere.util.Log;
54 import org.compiere.util.Msg;
55
56 /**
57  * Material Transaction History
58  *
59  * @author Jorg Janke
60  * @version $Id: VTrxMaterial.java,v 1.19 2003/10/03 04:06:36 jjanke Exp $
61  */

62 public class VTrxMaterial extends CPanel
63     implements FormPanel, ActionListener JavaDoc, VetoableChangeListener JavaDoc
64 {
65     /**
66      * Construvctor
67      */

68     public VTrxMaterial()
69     {
70     } // VTrxMaterial
71

72     /** Window No */
73     private int m_WindowNo = 0;
74     /** FormFrame */
75     private FormFrame m_frame;
76
77     /** GridController */
78     private GridController m_gridController = null;
79     /** MWindow */
80     private MWindow m_mWindow = null;
81     /** MTab pointer */
82     private MTab m_mTab = null;
83
84     private MQuery m_staticQuery = null;
85     //
86
private CPanel mainPanel = new CPanel();
87     private BorderLayout JavaDoc mainLayout = new BorderLayout JavaDoc();
88     private CPanel parameterPanel = new CPanel();
89     private JLabel JavaDoc orgLabel = new JLabel JavaDoc();
90     private VLookup orgField;
91     private JLabel JavaDoc locatorLabel = new JLabel JavaDoc();
92     private VLocator locatorField;
93     private JLabel JavaDoc productLabel = new JLabel JavaDoc();
94     private VLookup productField;
95     private JLabel JavaDoc dateFLabel = new JLabel JavaDoc();
96     private VDate dateFField;
97     private JLabel JavaDoc dateTLabel = new JLabel JavaDoc();
98     private VDate dateTField;
99     private JLabel JavaDoc mtypeLabel = new JLabel JavaDoc();
100     private VLookup mtypeField;
101     private GridBagLayout JavaDoc parameterLayout = new GridBagLayout JavaDoc();
102     private CPanel southPanel = new CPanel();
103     private BorderLayout JavaDoc southLayout = new BorderLayout JavaDoc();
104     private ConfirmPanel confirmPanel = new ConfirmPanel(true, true, false, false, false, true, true);
105     private StatusBar statusBar = new StatusBar();
106
107
108     /**
109      * Initialize Panel
110      * @param WindowNo window
111      * @param frame frame
112      */

113     public void init (int WindowNo, FormFrame frame)
114     {
115         Log.trace(Log.l1_User, "VTrxMaterial.init");
116         m_WindowNo = WindowNo;
117         m_frame = frame;
118         try
119         {
120             dynParameter();
121             jbInit();
122             dynInit();
123             frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
124             frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
125         }
126         catch(Exception JavaDoc ex)
127         {
128             Log.error("VTrxMaterial.init", ex);
129         }
130     } // init
131

132
133     /**
134      * Static Init
135      * @throws Exception
136      */

137     void jbInit() throws Exception JavaDoc
138     {
139         CompiereColor.setBackground(this);
140         mainPanel.setLayout(mainLayout);
141         mainLayout.setVgap(10);
142         parameterPanel.setLayout(parameterLayout);
143         //
144
orgLabel.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
145         locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID"));
146         productLabel.setText(Msg.translate(Env.getCtx(), "M_Product_ID"));
147         dateFLabel.setText(Msg.translate(Env.getCtx(), "DateFrom"));
148         dateTLabel.setText(Msg.translate(Env.getCtx(), "DateTo"));
149         mtypeLabel.setText(Msg.translate(Env.getCtx(), "MovementType"));
150         //
151
mainPanel.add(parameterPanel, BorderLayout.NORTH);
152         parameterPanel.add(orgLabel, new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.0, 0.0
153             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
154         parameterPanel.add(orgField, new GridBagConstraints JavaDoc(1, 0, 1, 1, 0.0, 0.0
155             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 0, 0, 5), 0, 0));
156         parameterPanel.add(mtypeLabel, new GridBagConstraints JavaDoc(2, 0, 1, 1, 0.0, 0.0
157             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
158         parameterPanel.add(mtypeField, new GridBagConstraints JavaDoc(3, 0, 1, 1, 0.0, 0.0
159             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 0, 0, 5), 0, 0));
160         parameterPanel.add(dateFLabel, new GridBagConstraints JavaDoc(4, 0, 1, 1, 0.0, 0.0
161             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
162         parameterPanel.add(dateFField, new GridBagConstraints JavaDoc(5, 0, 1, 1, 0.0, 0.0
163             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 0, 0, 5), 0, 0));
164
165         parameterPanel.add(locatorLabel, new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.0, 0.0
166             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
167         parameterPanel.add(locatorField, new GridBagConstraints JavaDoc(1, 1, 1, 1, 0.0, 0.0
168             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 0, 0, 5), 0, 0));
169         parameterPanel.add(productLabel, new GridBagConstraints JavaDoc(2, 1, 1, 1, 0.0, 0.0
170             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
171         parameterPanel.add(productField, new GridBagConstraints JavaDoc(3, 1, 1, 1, 0.0, 0.0
172             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 0, 0, 5), 0, 0));
173         parameterPanel.add(dateTLabel, new GridBagConstraints JavaDoc(4, 1, 1, 1, 0.0, 0.0
174             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
175         parameterPanel.add(dateTField, new GridBagConstraints JavaDoc(5, 1, 1, 1, 0.0, 0.0
176             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 0, 0, 5), 0, 0));
177         //
178
southPanel.setLayout(southLayout);
179         southPanel.add(confirmPanel, BorderLayout.NORTH);
180         southPanel.add(statusBar, BorderLayout.SOUTH);
181         mainPanel.add(southPanel, BorderLayout.SOUTH);
182     } // jbInit
183

184     /**
185      * Initialize Parameter fields
186      * @throws Exception if Lookups cannot be initialized
187      */

188     private void dynParameter() throws Exception JavaDoc
189     {
190         Properties JavaDoc ctx = Env.getCtx();
191         // Organization
192
MLookup orgLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3660, DisplayType.TableDir);
193         orgField = new VLookup("AD_Org_ID", false, false, true, orgLookup, DisplayType.TableDir, m_WindowNo);
194     // orgField.addVetoableChangeListener(this);
195
// Locator
196
MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo);
197         locatorField = new VLocator ("M_Locator_ID", false, false, true, locatorLookup, m_WindowNo);
198     // locatorField.addVetoableChangeListener(this);
199
// Product
200
MLookup productLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3668, DisplayType.Search);
201         productField = new VLookup("M_Product_ID", false, false, true, productLookup, DisplayType.Search, m_WindowNo);
202         productField.addVetoableChangeListener(this);
203         // Movement Type
204
MLookup mtypeLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3666, DisplayType.List);
205         mtypeField = new VLookup("MovementType", false, false, true, mtypeLookup, DisplayType.List, m_WindowNo);
206         // Dates
207
dateFField = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateFrom"));
208         dateTField = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateTo"));
209         //
210
confirmPanel.addActionListener(this);
211         statusBar.setStatusLine("");
212     } // dynParameter
213

214     /**
215      * Dynamic Layout (Grid)
216      */

217     private void dynInit()
218     {
219         m_staticQuery = new MQuery();
220         m_staticQuery.addRestriction("AD_Client_ID", MQuery.EQUAL, Env.getContextAsInt(Env.getCtx(), "#AD_Client_ID"));
221         MWindowVO wVO = AEnv.getMWindowVO (m_WindowNo, 223, 0);
222         if (wVO == null)
223             return;
224         m_mWindow = new MWindow (wVO);
225         m_mTab = m_mWindow.getTab(0);
226         //
227
m_gridController = new GridController();
228         m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
229         mainPanel.add(m_gridController, BorderLayout.CENTER);
230         //
231
m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
232         m_mTab.query(false);
233         statusBar.setStatusLine(" ", false);
234         statusBar.setStatusDB(" ");
235     } // dynInit
236

237
238     /**
239      * Dispose
240      */

241     public void dispose()
242     {
243         if (m_gridController != null)
244             m_gridController.dispose();
245         m_gridController = null;
246         m_mTab = null;
247         if (m_mWindow != null)
248             m_mWindow.dispose();
249         m_mWindow = null;
250
251         orgField = null;
252         locatorField = null;
253         productField = null;
254         mtypeField = null;
255         dateFField = null;
256         dateTField = null;
257         //
258
m_frame.dispose();
259     } // dispose
260

261     /*************************************************************************/
262
263     /**
264      * Action Listener
265      * @param e event
266      */

267     public void actionPerformed (ActionEvent JavaDoc e)
268     {
269         if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
270             dispose();
271         else if (e.getActionCommand().equals(ConfirmPanel.A_REFRESH)
272                 || e.getActionCommand().equals(ConfirmPanel.A_OK))
273             refresh();
274         else if (e.getActionCommand().equals(ConfirmPanel.A_ZOOM))
275             zoom();
276     } // actionPerformed
277

278     /*************************************************************************/
279
280     /**
281      * Property Listener
282      * @param e event
283      */

284     public void vetoableChange (PropertyChangeEvent JavaDoc e)
285     {
286         if (e.getPropertyName().equals("M_Product_ID"))
287             productField.setValue(e.getNewValue());
288     } // vetoableChange
289

290
291     /*************************************************************************/
292
293     /**
294      * Refresh - Create Query and refresh grid
295      */

296     private void refresh()
297     {
298         /**
299          * Create Where Clause
300          */

301         MQuery query = m_staticQuery.deepCopy();
302         // Organization
303
Object JavaDoc value = orgField.getValue();
304         if (value != null && value.toString().length() > 0)
305             query.addRestriction("AD_Org_ID", MQuery.EQUAL, value);
306         // Locator
307
value = locatorField.getValue();
308         if (value != null && value.toString().length() > 0)
309             query.addRestriction("M_Locator_ID", MQuery.EQUAL, value);
310         // Product
311
value = productField.getValue();
312         if (value != null && value.toString().length() > 0)
313             query.addRestriction("M_Product_ID", MQuery.EQUAL, value);
314         // MovementType
315
value = mtypeField.getValue();
316         if (value != null && value.toString().length() > 0)
317             query.addRestriction("MovementType", MQuery.EQUAL, value);
318         // DateFrom
319
Timestamp JavaDoc ts = (Timestamp JavaDoc)dateFField.getValue();
320         if (ts != null)
321             query.addRestriction("TRUNC(MovementDate)", MQuery.GREATER_EQUAL, ts);
322         // DateTO
323
ts = (Timestamp JavaDoc)dateTField.getValue();
324         if (ts != null)
325             query.addRestriction("TRUNC(MovementDate)", MQuery.LESS_EQUAL, ts);
326         Log.trace(Log.l1_User, "VTrxMaterial.refresh query=" + query.toString());
327
328         /**
329          * Refresh/Requery
330          */

331         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
332         statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false);
333         //
334
m_mTab.setQuery(query);
335         m_mTab.query(false);
336         //
337
setCursor(Cursor.getDefaultCursor());
338         int no = m_mTab.getRowCount();
339         statusBar.setStatusLine(" ", false);
340         statusBar.setStatusDB(Integer.toString(no));
341     } // refresh
342

343     /**
344      * Zoom
345      */

346     private void zoom()
347     {
348         Log.trace(Log.l1_User, "VTrxMaterial.zoom");
349         //
350
int AD_Window_ID = 0;
351         String JavaDoc ColumnName = null;
352         String JavaDoc SQL = null;
353         boolean isSOTrx = false;
354         //
355
int lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InOutLine_ID");
356         if (lineID != 0)
357         {
358             Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_InOutLine_ID=" + lineID);
359             if (Env.getContext(Env.getCtx(), m_WindowNo, "MovementType").startsWith("C"))
360             {
361                 AD_Window_ID = 169; // Customer
362
isSOTrx = true;
363             }
364             else
365             {
366                 AD_Window_ID = 184; // Vendor
367
isSOTrx = false;
368             }
369             ColumnName = "M_InOut_ID";
370             SQL = "SELECT M_InOut_ID FROM M_InOutLine WHERE M_InOutLine_ID=?";
371         }
372         else
373         {
374             lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InventoryLine_ID");
375             if (lineID != 0)
376             {
377                 Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_InventoryLine_ID=" + lineID);
378                 AD_Window_ID = 168;
379                 ColumnName = "M_Inventory_ID";
380                 SQL = "SELECT M_Inventory_ID FROM M_InventoryLine WHERE M_InventoryLine_ID=?";
381             }
382             else
383             {
384                 lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_MovementLine_ID");
385                 if (lineID != 0)
386                 {
387                     Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_MovementLine_ID=" + lineID);
388                     AD_Window_ID = 170;
389                     ColumnName = "M_Movement_ID";
390                     SQL = "SELECT M_Movement_ID FROM M_MovementLine WHERE M_MovementLine_ID=?";
391                 }
392                 else
393                 {
394                     lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductionLine_ID");
395                     if (lineID != 0)
396                     {
397                         Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_ProductionLine_ID=" + lineID);
398                         AD_Window_ID = 191;
399                         ColumnName = "M_Production_ID";
400                         SQL = "SELECT M_Production_ID FROM M_ProductionLine WHERE M_ProductionLine_ID=?";
401                     }
402                     else
403                         Log.trace(Log.l6_Database, "VTrxMaterial.zoom - not found WindowNo=" + m_WindowNo);
404                 }
405             }
406         }
407         if (AD_Window_ID == 0)
408             return;
409
410         // Get Parent ID
411
int parentID = 0;
412         try
413         {
414             PreparedStatement JavaDoc pstmt = DB.prepareStatement(SQL);
415             pstmt.setInt(1, lineID);
416             ResultSet JavaDoc rs = pstmt.executeQuery();
417             if (rs.next())
418                 parentID = rs.getInt(1);
419             rs.close();
420             pstmt.close();
421         }
422         catch (SQLException JavaDoc e)
423         {
424             Log.error ("VTrxMaterial.zoom - " + SQL, e);
425         }
426         MQuery query = MQuery.getEqualQuery(ColumnName, parentID);
427         Log.trace(Log.l2_Sub, "Zoom: AD_Window_ID=" + AD_Window_ID + " - " + query);
428         if (parentID == 0)
429             Log.error("VTrxMaterial.zoom - No ParentValue - " + SQL + " - " + lineID);
430
431         // Zoom
432
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
433         AWindow frame = new AWindow();
434         if (!frame.initWindow(AD_Window_ID, query, isSOTrx))
435         {
436             setCursor(Cursor.getDefaultCursor());
437             return;
438         }
439         AEnv.showCenterScreen(frame);
440         frame = null;
441         setCursor(Cursor.getDefaultCursor());
442     } // zoom
443

444 } // VTrxMaterial
445
Popular Tags