KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.*;
17 import java.awt.event.*;
18
19 import javax.swing.*;
20 import javax.swing.event.*;
21 import javax.swing.table.*;
22
23 import java.sql.*;
24 import java.text.*;
25 import java.util.*;
26 import java.math.*;
27
28 import org.compiere.apps.*;
29 import org.compiere.grid.ed.*;
30 import org.compiere.minigrid.*;
31 import org.compiere.util.*;
32 import org.compiere.model.*;
33 import org.compiere.plaf.*;
34 import org.compiere.swing.*;
35
36
37 /**
38  * Info InOut
39  *
40  * @author Jorg Janke
41  * @version $Id: InfoInOut.java,v 1.14 2003/10/17 06:15:56 jjanke Exp $
42  */

43 public class InfoInOut extends Info
44 {
45     /**
46      * Detail Protected Contructor
47      * @param frame parent frame
48      * @param modal modal
49      * @param WindowNo window no
50      * @param value query value
51      * @param multiSelection multiple selections
52      * @param whereClause where clause
53      */

54     protected InfoInOut(Frame frame, boolean modal, int WindowNo, String JavaDoc value,
55         boolean multiSelection, String JavaDoc whereClause)
56     {
57         super (frame, modal, WindowNo, "i", "M_InOut_ID", multiSelection, whereClause);
58         Log.trace(Log.l1_User, "InfoInOut");
59         setTitle(Msg.getMsg(Env.getCtx(), "InfoInOut"));
60         //
61
try
62         {
63             statInit();
64             p_loadedOK = initInfo ();
65         }
66         catch (Exception JavaDoc e)
67         {
68             return;
69         }
70         //
71
int no = p_table.getRowCount();
72         setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
73         setStatusDB(Integer.toString(no));
74         if (value != null && value.length() > 0)
75         {
76             fDocumentNo.setValue(value);
77             executeQuery();
78         }
79         //
80
pack();
81         // Focus
82
fDocumentNo.requestFocus();
83     } // InfoInOut
84

85     /** String Array of Column Info */
86     private Info_Column[] m_generalLayout;
87     /** list of query columns */
88     private ArrayList m_queryColumns = new ArrayList();
89     /** Table Name */
90     private String JavaDoc m_tableName;
91     /** Key Column Name */
92     private String JavaDoc m_keyColumn;
93
94     // Static Info
95
private CLabel lDocumentNo = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo"));
96     private CTextField fDocumentNo = new CTextField(10);
97     private CLabel lDescription = new CLabel(Msg.translate(Env.getCtx(), "Description"));
98     private CTextField fDescription = new CTextField(10);
99     private CLabel lPOReference = new CLabel(Msg.translate(Env.getCtx(), "POReference"));
100     private CTextField fPOReference = new CTextField(10);
101     //
102
// private CLabel lOrg_ID = new CLabel(Msg.translate(Env.getCtx(), "AD_Org_ID"));
103
// private VLookup fOrg_ID;
104
private CLabel lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
105     private VLookup fBPartner_ID;
106     //
107
private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "MovementDate"));
108     private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom"));
109     private CLabel lDateTo = new CLabel("-");
110     private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo"));
111     private VCheckBox fIsSOTrx = new VCheckBox ("IsSOTrx", false, false, true, Msg.translate(Env.getCtx(), "IsSOTrx"), "", false);
112
113     /** Array of Column Info */
114     private static final Info_Column[] s_invoiceLayout = {
115         new Info_Column(" ", "i.M_InOut_ID", IDColumn.class),
116         new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), "(SELECT Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=i.C_BPartner_ID)", String JavaDoc.class),
117         new Info_Column(Msg.translate(Env.getCtx(), "MovementDate"), "i.MovementDate", Timestamp.class),
118         new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"), "i.DocumentNo", String JavaDoc.class),
119         new Info_Column(Msg.translate(Env.getCtx(), "Description"), "i.Description", String JavaDoc.class),
120         new Info_Column(Msg.translate(Env.getCtx(), "POReference"), "i.POReference", String JavaDoc.class),
121         new Info_Column(Msg.translate(Env.getCtx(), "IsSOTrx"), "i.IsSOTrx", Boolean JavaDoc.class)
122     };
123
124     /**
125      * Static Setup - add fields to parameterPanel
126      * @throws Exception if Lookups cannot be initialized
127      */

128     private void statInit() throws Exception JavaDoc
129     {
130         lDocumentNo.setLabelFor(fDocumentNo);
131         fDocumentNo.setBackground(CompierePLAF.getInfoBackground());
132         fDocumentNo.addActionListener(this);
133         lDescription.setLabelFor(fDescription);
134         fDescription.setBackground(CompierePLAF.getInfoBackground());
135         fDescription.addActionListener(this);
136         lPOReference.setLabelFor(lPOReference);
137         fPOReference.setBackground(CompierePLAF.getInfoBackground());
138         fPOReference.addActionListener(this);
139         fIsSOTrx.setSelected(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx")));
140         fIsSOTrx.addActionListener(this);
141         //
142
// fOrg_ID = new VLookup("AD_Org_ID", false, false, true,
143
// MLookupFactory.create(Env.getCtx(), 3486, m_WindowNo, DisplayType.TableDir, false),
144
// DisplayType.TableDir, m_WindowNo);
145
// lOrg_ID.setLabelFor(fOrg_ID);
146
// fOrg_ID.setBackground(CompierePLAF.getInfoBackground());
147
fBPartner_ID = new VLookup("C_BPartner_ID", false, false, true,
148             MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search),
149             DisplayType.Search, p_WindowNo);
150         lBPartner_ID.setLabelFor(fBPartner_ID);
151         fBPartner_ID.setBackground(CompierePLAF.getInfoBackground());
152         //
153
lDateFrom.setLabelFor(fDateFrom);
154         fDateFrom.setBackground(CompierePLAF.getInfoBackground());
155         fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom"));
156         lDateTo.setLabelFor(fDateTo);
157         fDateTo.setBackground(CompierePLAF.getInfoBackground());
158         fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo"));
159         //
160
parameterPanel.setLayout(new ALayout());
161         // First Row
162
parameterPanel.add(lDocumentNo, new ALayoutConstraint(0,0));
163         parameterPanel.add(fDocumentNo, null);
164         parameterPanel.add(lBPartner_ID, null);
165         parameterPanel.add(fBPartner_ID, null);
166         parameterPanel.add(fIsSOTrx, new ALayoutConstraint(0,5));
167         // 2nd Row
168
parameterPanel.add(lDescription, new ALayoutConstraint(1,0));
169         parameterPanel.add(fDescription, null);
170         parameterPanel.add(lDateFrom, null);
171         parameterPanel.add(fDateFrom, null);
172         parameterPanel.add(lDateTo, null);
173         parameterPanel.add(fDateTo, null);
174         // 3rd Row
175
parameterPanel.add(lPOReference, new ALayoutConstraint(2,0));
176         parameterPanel.add(fPOReference, null);
177     // parameterPanel.add(lOrg_ID, null);
178
// parameterPanel.add(fOrg_ID, null);
179
} // statInit
180

181     /**
182      * General Init
183      * @return true, if success
184      */

185     private boolean initInfo ()
186     {
187         // Set Defaults
188
String JavaDoc bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID");
189         if (bp != null && bp.length() != 0)
190             fBPartner_ID.setValue(new Integer JavaDoc(bp));
191
192         // prepare table
193
StringBuffer JavaDoc where = new StringBuffer JavaDoc("i.IsActive='Y'");
194         if (p_whereClause.length() > 0)
195             where.append(" AND ").append(Util.replace(p_whereClause, "M_InOut.", "i."));
196         prepareTable(s_invoiceLayout,
197             " M_InOut i",
198             where.toString(),
199             "2,3,4");
200
201         return true;
202     } // initInfo
203

204     /*************************************************************************/
205
206     /**
207      * Construct SQL Where Clause and define parameters.
208      * (setParameters needs to set parameters)
209      * Includes first AND
210      * @return where clause
211      */

212     String JavaDoc getSQLWhere()
213     {
214         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
215         if (fDocumentNo.getText().length() > 0)
216             sql.append(" AND UPPER(i.DocumentNo) LIKE ?");
217         if (fDescription.getText().length() > 0)
218             sql.append(" AND UPPER(i.Description) LIKE ?");
219         if (fPOReference.getText().length() > 0)
220             sql.append(" AND UPPER(i.POReference) LIKE ?");
221         //
222
if (fBPartner_ID.getValue() != null)
223             sql.append(" AND i.C_BPartner_ID=?");
224         //
225
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
226         {
227             Timestamp from = (Timestamp)fDateFrom.getValue();
228             Timestamp to = (Timestamp)fDateTo.getValue();
229             if (from == null && to != null)
230                 sql.append(" AND TRUNC(i.MovementDate) <= ?");
231             else if (from != null && to == null)
232                 sql.append(" AND TRUNC(i.MovementDate) >= ?");
233             else if (from != null && to != null)
234                 sql.append(" AND TRUNC(i.MovementDate) BETWEEN ? AND ?");
235         }
236         sql.append(" AND i.IsSOTrx=?");
237
238     // Log.trace(Log.l6_Database, "InfoInOut.setWhereClause", sql.toString());
239
return sql.toString();
240     } // getSQLWhere
241

242     /**
243      * Set Parameters for Query.
244      * (as defined in getSQLWhere)
245      * @param pstmt statement
246      * @throws SQLException
247      */

248     void setParameters(PreparedStatement pstmt) throws SQLException
249     {
250         int index = 1;
251         if (fDocumentNo.getText().length() > 0)
252             pstmt.setString(index++, getSQLText(fDocumentNo));
253         if (fDescription.getText().length() > 0)
254             pstmt.setString(index++, getSQLText(fDescription));
255         if (fPOReference.getText().length() > 0)
256             pstmt.setString(index++, getSQLText(fPOReference));
257         //
258
if (fBPartner_ID.getValue() != null)
259         {
260             Integer JavaDoc bp = (Integer JavaDoc)fBPartner_ID.getValue();
261             pstmt.setInt(index++, bp.intValue());
262             Log.trace(Log.l5_DData, "BPartner=" + bp);
263         }
264         //
265
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
266         {
267             Timestamp from = (Timestamp)fDateFrom.getValue();
268             Timestamp to = (Timestamp)fDateTo.getValue();
269             Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to);
270             if (from == null && to != null)
271                 pstmt.setTimestamp(index++, to);
272             else if (from != null && to == null)
273                 pstmt.setTimestamp(index++, from);
274             else if (from != null && to != null)
275             {
276                 pstmt.setTimestamp(index++, from);
277                 pstmt.setTimestamp(index++, to);
278             }
279         }
280         pstmt.setString(index++, fIsSOTrx.isSelected() ? "Y" : "N");
281     } // setParameters
282

283     /**
284      * Get SQL WHERE parameter
285      * @param f field
286      * @return sql part
287      */

288     private String JavaDoc getSQLText (CTextField f)
289     {
290         String JavaDoc s = f.getText().toUpperCase();
291         if (!s.endsWith("%"))
292             s += "%";
293         Log.trace(Log.l5_DData, "String=" + s);
294         return s;
295     } // getSQLText
296

297 } // InfoInOut
298
Popular Tags