KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MAccount


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.model;
15
16 import java.sql.*;
17 import java.util.*;
18 import java.math.*;
19 import java.io.Serializable JavaDoc;
20
21 import org.compiere.util.NamePair;
22 import org.compiere.util.KeyNamePair;
23 import org.compiere.util.Env;
24 import org.compiere.util.DB;
25
26 /**
27  * Account Model Lookup - Maintains ValidCombination Info for Display & Edit - not cached
28  *
29  * @author Jorg Janke
30  * @version $Id: MAccount.java,v 1.7 2003/08/15 17:22:58 jjanke Exp $
31  */

32 public final class MAccount extends Lookup implements Serializable JavaDoc
33 {
34     /**
35      * Constructor
36      * @parameter ctx context
37      * @parameter WindowNo window no
38      */

39     public MAccount (Properties ctx, int WindowNo)
40     {
41         m_ctx = ctx;
42         m_WindowNo = WindowNo;
43     } // MAccount
44

45     private int m_WindowNo;
46     private Properties m_ctx;
47
48     public int C_ValidCombination_ID;
49     private String JavaDoc Combination;
50     private String JavaDoc Description;
51
52     /**
53      * Get Display for Value
54      * @param value value
55      * @return String
56      */

57     public String JavaDoc getDisplay (Object JavaDoc value)
58     {
59         if (!containsKey (value))
60             return "<" + value.toString() + ">";
61         return toString();
62     } // getDisplay
63

64     /**
65      * Get Object of Key Value
66      * @param value value
67      * @return Object or null
68      */

69     public NamePair get (Object JavaDoc value)
70     {
71         if (value == null)
72             return null;
73         if (!containsKey (value))
74             return null;
75         return new KeyNamePair (C_ValidCombination_ID, toString());
76     } // get
77

78     /**
79      * The Lookup contains the key
80      * @param key key
81      * @return true if exists
82      */

83     public boolean containsKey (Object JavaDoc key)
84     {
85         int intValue = 0;
86         if (key instanceof Integer JavaDoc)
87             intValue = ((Integer JavaDoc)key).intValue();
88         else if (key != null)
89             intValue = Integer.parseInt(key.toString());
90         //
91
return load (intValue);
92     } // containsKey
93

94     /**
95      * Get Description
96      * @return Description
97      */

98     public String JavaDoc getDescription()
99     {
100         return Description;
101     } // getDescription
102

103     /**
104      * Return String representation
105      * @return Combination
106      */

107     public String JavaDoc toString()
108     {
109         if (C_ValidCombination_ID == 0)
110             return "";
111         return Combination;
112     } // toString
113

114     /**
115      * Load C_ValidCombination with ID
116      * @param ID C_ValidCombination_ID
117      * @return true if found
118      */

119     public boolean load (int ID)
120     {
121         if (ID == 0) // new
122
{
123             C_ValidCombination_ID = 0;
124             Combination = "";
125             Description = "";
126             return true;
127         }
128         if (ID == C_ValidCombination_ID) // already loaded
129
return true;
130
131         String JavaDoc SQL = "SELECT C_ValidCombination_ID, Combination, Description "
132             + "FROM C_ValidCombination WHERE C_ValidCombination_ID=?";
133         try
134         {
135             // Prepare Statement
136
PreparedStatement pstmt = DB.prepareStatement(SQL);
137             pstmt.setInt(1, ID);
138             ResultSet rs = pstmt.executeQuery();
139             if (!rs.next())
140             {
141                 rs.close();
142                 pstmt.close();
143                 return false;
144             }
145             //
146
C_ValidCombination_ID = rs.getInt(1);
147             Combination = rs.getString(2);
148             Description = rs.getString(3);
149             //
150
rs.close();
151             pstmt.close();
152
153         }
154         catch (SQLException e)
155         {
156             return false;
157         }
158         return true;
159     } // load
160

161     /**
162      * Get underlying fully qualified Table.Column Name
163      * @return ""
164      */

165     public String JavaDoc getColumnName()
166     {
167         return "";
168     } // getColumnName
169

170     /**
171      * Return data as sorted Array.
172      * Used in Web Interface
173      * @param mandatory mandatory
174      * @param onlyValidated only valid
175      * @param onlyActive only active
176      * @param temporary force load for temporary display
177      * @return ArrayList with KeyNamePair
178      */

179     public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary)
180     {
181         ArrayList list = new ArrayList();
182         if (!mandatory)
183             list.add(new KeyNamePair (-1, ""));
184         //
185
StringBuffer JavaDoc sql = new StringBuffer JavaDoc ("SELECT C_ValidCombination_ID, Combination, Description "
186             + "FROM C_ValidCombination WHERE AD_Client_ID=?");
187         if (onlyActive)
188             sql.append(" AND IsActive='Y'");
189         sql.append(" ORDER BY 2");
190         try
191         {
192             PreparedStatement pstmt = DB.prepareStatement(sql.toString());
193             pstmt.setInt(1, Env.getContextAsInt(m_ctx, "#AD_Client_ID"));
194             ResultSet rs = pstmt.executeQuery();
195             while (rs.next())
196                 list.add (new KeyNamePair(rs.getInt(1), rs.getString(2) + " - " + rs.getString(3)));
197             rs.close();
198             pstmt.close();
199         }
200         catch (SQLException e)
201         {
202             log.error("getData", e);
203         }
204
205         // Sort & return
206
return list;
207     } // getData
208

209 } // MAccount
210
Popular Tags