KickJava   Java API By Example, From Geeks To Geeks.

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


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-2003 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.sql.*;
17 import java.math.*;
18 import java.awt.*;
19
20 import org.compiere.apps.*;
21 import org.compiere.minigrid.*;
22 import org.compiere.plaf.*;
23 import org.compiere.swing.*;
24 import org.compiere.model.*;
25 import org.compiere.util.*;
26
27 /**
28  * Asset Information
29  *
30  * @author Jorg Janke
31  * @version $Id: InfoAsset.java,v 1.3 2003/10/17 06:15:56 jjanke Exp $
32  */

33 public class InfoAsset extends Info
34 {
35     /**
36      * Standard Constructor
37
38      * @param frame frame
39      * @param modal modal
40      * @param WindowNo window no
41      * @param A_Asset_ID asset
42      * @param value Query Value or Name if enclosed in @
43      * @param multiSelection multiple selections
44      * @param whereClause where clause
45      */

46     public InfoAsset (Frame frame, boolean modal, int WindowNo,
47         int A_Asset_ID, String JavaDoc value,
48         boolean multiSelection, String JavaDoc whereClause)
49     {
50         super (frame, modal, WindowNo, "a", "A_Asset_ID", multiSelection, whereClause);
51         Log.trace(Log.l1_User, "InfoAsset", value + ", ID=" + A_Asset_ID + ", WHERE=" + whereClause);
52         setTitle(Msg.getMsg(Env.getCtx(), "InfoAsset"));
53         //
54
statInit();
55         initInfo (value, A_Asset_ID, whereClause);
56         //
57
int no = p_table.getRowCount();
58         setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
59         setStatusDB(Integer.toString(no));
60         // AutoQuery
61
if (value != null && value.length() > 0)
62             executeQuery();
63         p_loadedOK = true;
64         // Focus
65
// fieldValue.requestFocus();
66

67         AEnv.positionCenterWindow(frame, this);
68     } // InfoProduct
69

70     /** From Clause */
71     private static String JavaDoc s_assetFROM = "A_ASSET a"
72         + " INNER JOIN M_Product p ON (a.M_Product_ID=p.M_Product_ID)"
73         + " LEFT OUTER JOIN C_BPartner bp ON (a.C_BPartner_ID=bp.C_BPartner_ID)"
74         + " LEFT OUTER JOIN AD_User u ON (a.AD_User_ID=u.AD_User_ID)";
75
76     /** Array of Column Info */
77     private static final Info_Column[] s_assetLayout = {
78         new Info_Column(" ", "a.A_Asset_ID", IDColumn.class),
79         new Info_Column(Msg.translate(Env.getCtx(), "Value"), "a.Value", String JavaDoc.class),
80         new Info_Column(Msg.translate(Env.getCtx(), "Name"), "a.Name", String JavaDoc.class),
81         new Info_Column(Msg.translate(Env.getCtx(), "M_Product_ID"), "p.Name", String JavaDoc.class),
82         new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), "bp.Name", String JavaDoc.class),
83         new Info_Column(Msg.translate(Env.getCtx(), "AD_User_ID"), "u.Name", String JavaDoc.class),
84         new Info_Column(Msg.translate(Env.getCtx(), "AssetServiceDate"), "a.AssetServiceDate", Timestamp.class),
85         new Info_Column(Msg.translate(Env.getCtx(), "GuaranteeDate"), "a.GuaranteeDate", Timestamp.class),
86         new Info_Column(Msg.translate(Env.getCtx(), "VersionNo"), "a.VersionNo", String JavaDoc.class)
87     };
88     
89     //
90
private CLabel labelValue = new CLabel();
91     private CTextField fieldValue = new CTextField(10);
92     private CLabel labelName = new CLabel();
93     private CTextField fieldName = new CTextField(10);
94     
95     /**
96      * Static Setup - add fields to parameterPanel
97      */

98     private void statInit()
99     {
100         labelValue.setText(Msg.getMsg(Env.getCtx(), "Value"));
101         fieldValue.setBackground(CompierePLAF.getInfoBackground());
102         fieldValue.addActionListener(this);
103
104         labelName.setText(Msg.getMsg(Env.getCtx(), "Name"));
105         fieldName.setBackground(CompierePLAF.getInfoBackground());
106         fieldName.addActionListener(this);
107
108         //
109
parameterPanel.setLayout(new ALayout());
110         //
111
parameterPanel.add(labelValue, new ALayoutConstraint(0,0));
112         parameterPanel.add(fieldValue, null);
113         //
114
parameterPanel.add(labelName, new ALayoutConstraint(1,0));
115         parameterPanel.add(fieldName, null);
116     } // statInit
117

118     /**
119      * Dynamic Init
120      * @param value value
121      * @param whereClause where clause
122      */

123     private void initInfo (String JavaDoc value, int A_Asset_ID, String JavaDoc whereClause)
124     {
125         // Create Grid
126
StringBuffer JavaDoc where = new StringBuffer JavaDoc();
127         where.append("a.IsActive='Y'");
128         if (whereClause != null && whereClause.length() > 0)
129             where.append(" AND ").append(whereClause);
130         //
131
prepareTable(s_assetLayout, s_assetFROM,
132             where.toString(),
133             "a.Value");
134
135         // Set Value
136
if (value == null)
137             value = "%";
138         if (!value.endsWith("%"))
139             value += "%";
140     } // initInfo
141

142     /*************************************************************************/
143
144     /**
145      * Construct SQL Where Clause and define parameters.
146      * (setParameters needs to set parameters)
147      * Includes first AND
148      * @return WHERE clause
149      */

150     String JavaDoc getSQLWhere()
151     {
152         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
153         // => Value
154
String JavaDoc value = fieldValue.getText().toUpperCase();
155         if (!(value.equals("") || value.equals("%")))
156             sql.append(" AND UPPER(bp.Value) LIKE ?");
157         // => Name
158
String JavaDoc name = fieldName.getText().toUpperCase();
159         if (!(name.equals("") || name.equals("%")))
160             sql.append (" AND UPPER(bp.Name) LIKE ?");
161         //
162
return sql.toString();
163     } // getSQLWhere
164

165     /**
166      * Set Parameters for Query
167      * (as defined in getSQLWhere)
168      *
169      * @param pstmt pstmt
170      * @throws SQLException
171      * @see org.compiere.apps.search.Info#setParameters(java.sql.PreparedStatement)
172      */

173     void setParameters(PreparedStatement pstmt) throws SQLException
174     {
175         int index = 1;
176         // => Value
177
String JavaDoc value = fieldValue.getText().toUpperCase();
178         if (!(value.equals("") || value.equals("%")))
179         {
180             if (!value.endsWith("%"))
181                 value += "%";
182             pstmt.setString(index++, value);
183             Log.trace(Log.l5_DData, "InfoAsset.setParameters", "Value: " + value);
184         }
185         // => Name
186
String JavaDoc name = fieldName.getText().toUpperCase();
187         if (!(name.equals("") || name.equals("%")))
188         {
189             if (!name.endsWith("%"))
190                 name += "%";
191             pstmt.setString(index++, name);
192             Log.trace(Log.l5_DData, "InfoAsset.setParameters", "Name: " + name);
193         }
194     } // setParameters
195

196     /**
197      * Save Selection Details
198      * Get Location/Partner Info
199      */

200     public void saveSelectionDetail()
201     {
202         int row = p_table.getSelectedRow();
203         if (row == -1)
204             return;
205
206         // publish for Callout to read
207
Integer JavaDoc ID = getSelectedRowKey();
208         Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "A_Asset_ID", ID == null ? "0" : ID.toString());
209     } // saveSelectionDetail
210

211
212     /*************************************************************************/
213
214     /**
215      * Show History
216      */

217     void showHistory()
218     {
219         Log.trace(Log.l1_User, "InfoAsset.showHistory");
220     } // showHistory
221

222     /**
223      * Has History
224      * @return true
225      */

226     boolean hasHistory()
227     {
228         return false;
229     } // hasHistory
230

231     /**
232      * Zoom
233      */

234     void zoom()
235     {
236         Log.trace(Log.l1_User, "InfoAsset.zoom");
237         Integer JavaDoc A_Asset_ID = getSelectedRowKey();
238         if (A_Asset_ID == null)
239             return;
240         MQuery query = new MQuery("A_Asset");
241         query.addRestriction("A_Asset_ID", MQuery.EQUAL, A_Asset_ID);
242         zoom (123, query);
243     } // zoom
244

245     /**
246      * Has Zoom
247      * @return true
248      */

249     boolean hasZoom()
250     {
251         return true;
252     } // hasZoom
253

254     /**
255      * Customize
256      */

257     void customize()
258     {
259         Log.trace(Log.l1_User, "InfoAsset.customize");
260     } // customize
261

262     /**
263      * Has Customize
264      * @return false
265      */

266     boolean hasCustomize()
267     {
268         return false; // for now
269
} // hasCustomize
270

271 } // InfoAsset
272
Popular Tags