KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.*;
17 import java.awt.*;
18 import java.awt.event.*;
19 import javax.swing.*;
20
21 import org.compiere.apps.*;
22 import org.compiere.model.*;
23 import org.compiere.util.*;
24 import org.compiere.swing.*;
25 import org.compiere.grid.ed.*;
26 import org.compiere.minigrid.*;
27
28
29 /**
30  * View Assignments and optionally create Resource Assigments
31  *
32  * @author Jorg Janke
33  * @version $Id: InfoAssignment.java,v 1.8 2003/10/17 06:15:56 jjanke Exp $
34  */

35 public class InfoAssignment extends Info
36 {
37     /**
38      * Constructor
39      * @param frame frame
40      * @param modal modal
41      * @param WindowNo WindowNo
42      * @param value Query value Name or Value if contains numbers
43      * @param multiSelection multiple selection
44      * @param whereClause where clause
45      */

46     public InfoAssignment (Frame frame, boolean modal, int WindowNo,
47         String JavaDoc value, boolean multiSelection, String JavaDoc whereClause)
48     {
49         super (frame, modal, WindowNo, "ra", "S_ResourceAssigment_ID",
50             multiSelection, whereClause);
51         Log.trace(Log.l1_User, "InfoAssignment", value);
52         setTitle(Msg.getMsg(Env.getCtx(), "InfoAssignment"));
53         //
54
if (!initLookups())
55             return;
56         statInit();
57         initInfo (value, whereClause);
58         //
59
int no = p_table.getRowCount();
60         setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
61         setStatusDB(Integer.toString(no));
62         // AutoQuery
63
// if (value != null && value.length() > 0)
64
// executeQuery();
65
p_loadedOK = true;
66
67         AEnv.positionCenterWindow(frame, this);
68     } // InfoAssignment
69

70     //
71
private CLabel labelResourceType = new CLabel(Msg.translate(Env.getCtx(), "S_ResourceType_ID"));
72     private VLookup fieldResourceType;
73     private CLabel labelResource = new CLabel(Msg.translate(Env.getCtx(), "S_Resource_ID"));
74     private VLookup fieldResource;
75     private CLabel labelFrom = new CLabel(Msg.translate(Env.getCtx(), "DateFrom"));
76     private VDate fieldFrom = new VDate(DisplayType.DateTime);
77     private CLabel labelTo = new CLabel(Msg.translate(Env.getCtx(), "DateTo"));
78     private VDate fieldTo = new VDate(DisplayType.DateTime);
79     private CButton bNew = new CButton();
80
81     /**
82      * Initialize Lookups
83      * @return true if OK
84      */

85     private boolean initLookups()
86     {
87         try
88         {
89             int AD_Column_ID = 6851; // S_Resource.S_ResourceType_ID
90
Lookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
91             fieldResourceType = new VLookup ("S_ResourceType_ID", false, false, true, lookup, DisplayType.TableDir, p_WindowNo);
92             AD_Column_ID = 6826; // S_ResourceAssignment.S_Resource_ID
93
lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
94             fieldResource = new VLookup ("S_Resource_ID", false, false, true, lookup, DisplayType.TableDir, p_WindowNo);
95         }
96         catch (Exception JavaDoc e)
97         {
98             Log.error("InfoAssignment.initLookup");
99             return false;
100         }
101         //
102
bNew.setIcon(Env.getImageIcon("New16.gif"));
103         return true;
104     } // initLookups
105

106     /**
107      * Static Setup - add fields to parameterPanel.
108      * <pre>
109      * ResourceType Resource DateTimeFrom DateTimeTo New
110      * </pre>
111      */

112     private void statInit()
113     {
114         parameterPanel.setLayout(new ALayout());
115         parameterPanel.add(labelResourceType, new ALayoutConstraint(0,0));
116         parameterPanel.add(labelResource, null);
117         parameterPanel.add(labelFrom, null);
118         parameterPanel.add(labelTo, null);
119     // parameterPanel.add(labelPhone, null);
120
// parameterPanel.add(checkFuzzy, null);
121
//
122
parameterPanel.add(fieldResourceType, new ALayoutConstraint(1,0));
123         parameterPanel.add(fieldResource, null);
124         parameterPanel.add(fieldFrom, null);
125         parameterPanel.add(fieldTo, null);
126         parameterPanel.add(bNew, null);
127     // parameterPanel.add(checkCustomer, null);
128
} // statInit
129

130     /**
131 SELECT rt.Name, r.Name, ra.AssignDateFrom, ra.AssignDateTo, ra.Qty, uom.UOMSymbol, ra.IsConfirmed
132 FROM S_ResourceAssignment ra, S_ResourceType rt, S_Resource r, C_UOM uom
133 WHERE ra.IsActive='Y'
134 AND ra.S_Resource_ID=r.S_Resource_ID
135 AND r.S_ResourceType_ID=rt.S_ResourceType_ID
136 AND rt.C_UOM_ID=uom.C_UOM_ID
137      */

138
139     /** From Clause */
140     private static String JavaDoc s_assignmentFROM =
141         "S_ResourceAssignment ra, S_ResourceType rt, S_Resource r, C_UOM uom";
142     private static String JavaDoc s_assignmentWHERE =
143         "ra.IsActive='Y' AND ra.S_Resource_ID=r.S_Resource_ID "
144         + "AND r.S_ResourceType_ID=rt.S_ResourceType_ID AND rt.C_UOM_ID=uom.C_UOM_ID";
145
146     /** Array of Column Info */
147     private static Info_Column[] s_assignmentLayout = {
148         new Info_Column(" ", "ra.S_ResourceAssignment_ID", IDColumn.class),
149         new Info_Column(Msg.translate(Env.getCtx(), "S_ResourceType_ID"), "rt.Name", String JavaDoc.class),
150         new Info_Column(Msg.translate(Env.getCtx(), "S_Resource_ID"), "r.Name", String JavaDoc.class),
151         new Info_Column(Msg.translate(Env.getCtx(), "AssignDateFrom"), "ra.AssignDateFrom", Timestamp.class),
152         new Info_Column(Msg.translate(Env.getCtx(), "Qty"), "ra.Qty", Double JavaDoc.class),
153         new Info_Column(Msg.translate(Env.getCtx(), "C_UOM_ID"), "uom.UOMSymbol", String JavaDoc.class),
154         new Info_Column(Msg.translate(Env.getCtx(), "AssignDateTo"), "ra.AssignDateTo", Timestamp.class),
155         new Info_Column(Msg.translate(Env.getCtx(), "IsConfirmed"), "ra.IsConfirmed", Boolean JavaDoc.class)
156     };
157
158
159     /**
160      * Dynamic Init
161      * @param value value
162      * @param whereClause where clause
163      */

164     private void initInfo(String JavaDoc value, String JavaDoc whereClause)
165     {
166         // C_BPartner bp, AD_User c, C_BPartner_Location l, C_Location a
167

168         // Create Grid
169
StringBuffer JavaDoc where = new StringBuffer JavaDoc(s_assignmentWHERE);
170         if (whereClause != null && whereClause.length() > 0)
171             where.append(" AND ").append(whereClause);
172         //
173
prepareTable(s_assignmentLayout, s_assignmentFROM,
174             where.toString(),
175             "rt.Name,r.Name,ra.AssignDateFrom");
176     } // initInfo
177

178     /*************************************************************************/
179
180     /**
181      * Action Listner
182      *
183      * @param e event
184      */

185     public void actionPerformed (ActionEvent e)
186     {
187         // don't requery if fieldValue and fieldName are empty
188
// return;
189
//
190
super.actionPerformed(e);
191     } // actionPerformed
192

193     /*************************************************************************/
194
195     /**
196      * Get dynamic WHERE part of SQL
197      * To be overwritten by concrete classes
198      * @return WHERE clause
199      */

200     String JavaDoc getSQLWhere()
201     {
202         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
203         //
204
KeyNamePair vp = (KeyNamePair)fieldResourceType.getValue();
205         if (vp != null)
206             sql.append(" AND rt.S_ResourceType_ID=").append(vp.getKey());
207         //
208
vp = (KeyNamePair)fieldResource.getValue();
209         if (vp != null)
210             sql.append(" AND r.S_Resource_ID=").append(vp.getKey());
211         //
212
Timestamp ts = fieldFrom.getTimestamp();
213         if (ts != null)
214             sql.append(" AND ra.AssignDateFrom>").append(DB.TO_DATE(ts,false));
215         //
216
ts = fieldTo.getTimestamp();
217         if (ts != null)
218             sql.append(" AND ra.AssignDateTo<").append(DB.TO_DATE(ts,false));
219         return sql.toString();
220     } // getSQLWhere
221

222     /**
223      * Set Parameters for Query
224      * To be overwritten by concrete classes
225      * @param pstmt pstmt
226      * @throws SQLException
227      */

228     void setParameters (PreparedStatement pstmt) throws SQLException
229     {
230     }
231
232     /**
233      * History dialog
234      * To be overwritten by concrete classes
235      */

236     void showHistory()
237     {
238     }
239
240     /**
241      * Has History (false)
242      * To be overwritten by concrete classes
243      * @return true if it has history (default false)
244      */

245     boolean hasHistory()
246     {
247         return false;
248     }
249
250     /**
251      * Customize dialog
252      * To be overwritten by concrete classes
253      */

254     void customize()
255     {
256     }
257
258     /**
259      * Has Customize (false)
260      * To be overwritten by concrete classes
261      * @return true if it has customize (default false)
262      */

263     boolean hasCustomize()
264     {
265         return false;
266     }
267
268     /**
269      * Zoom action
270      * To be overwritten by concrete classes
271      */

272     void zoom()
273     {
274     }
275
276     /**
277      * Has Zoom (false)
278      * To be overwritten by concrete classes
279      * @return true if it has zoom (default false)
280      */

281     boolean hasZoom()
282     {
283         return false;
284     }
285
286     /**
287      * Save Selection Details
288      * To be overwritten by concrete classes
289      */

290     void saveSelectionDetail()
291     {
292     }
293
294 } // InfoAssignment
295
Popular Tags