KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > XLookup


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.grid;
15
16 import java.util.*;
17
18 import org.compiere.model.*;
19 import org.compiere.util.*;
20
21 /**
22  * Manual Lookup (Model)- loaded by the put method
23  *
24  * @author Jorg Janke
25  * @version $Id: XLookup.java,v 1.5 2003/06/12 22:09:21 jjanke Exp $
26  */

27 public class XLookup extends Lookup
28 {
29     /**
30      * Manual Lookup
31      * @param keyColumn key Column
32      */

33     public XLookup(String JavaDoc keyColumn)
34     {
35         super();
36         m_keyColumn = keyColumn;
37     } // XLookup
38

39
40     /** Key Column - as identifier */
41     private String JavaDoc m_keyColumn;
42
43     /**
44      * Get Display String of key value
45      * @param key key
46      * @return display
47      */

48     public String JavaDoc getDisplay (Object JavaDoc key)
49     {
50         // linear seatch in m_data
51
for (int i = 0; i < p_data.size(); i++)
52         {
53             Object JavaDoc oo = p_data.get(i);
54             if (oo != null && oo instanceof NamePair)
55             {
56                 NamePair pp = (NamePair)oo;
57                 if (pp.getID().equals(key))
58                     return pp.getName();
59             }
60         }
61         return "<" + key + ">";
62     } // getDisplay
63

64     /**
65      * The Lookup contains the key
66      * @param key key
67      * @return true if contains key
68      */

69     public boolean containsKey (Object JavaDoc key)
70     {
71         // linear seatch in p_data
72
for (int i = 0; i < p_data.size(); i++)
73         {
74             Object JavaDoc oo = p_data.get(i);
75             if (oo != null && oo instanceof NamePair)
76             {
77                 NamePair pp = (NamePair)oo;
78                 if (pp.getID().equals(key))
79                     return true;
80             }
81         }
82         return false;
83     } // containsKey
84

85     /**
86      * Get Object of Key Value
87      * @param key key
88      * @return Object or null
89      */

90     public NamePair get (Object JavaDoc key)
91     {
92         // linear seatch in m_data
93
for (int i = 0; i < p_data.size(); i++)
94         {
95             Object JavaDoc oo = p_data.get(i);
96             if (oo != null && oo instanceof NamePair)
97             {
98                 NamePair pp = (NamePair)oo;
99                 if (pp.getID().equals(key))
100                     return pp;
101             }
102         }
103         return null;
104     } // get
105

106
107     /**
108      * Return data as sorted Array
109      * @param mandatory mandatory
110      * @param onlyValidated only validated
111      * @param onlyActive only active
112      * @param temporary force load for temporary display
113      * @return list of data
114      */

115     public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary)
116     {
117         ArrayList list = new ArrayList (p_data);
118         // Sort Data
119
if (m_keyColumn.endsWith("_ID"))
120         {
121             KeyNamePair p = new KeyNamePair (-1, "");
122             if (!mandatory)
123                 list.add (p);
124             Collections.sort (list, p);
125         }
126         else
127         {
128             ValueNamePair p = new ValueNamePair (null, "");
129             if (!mandatory)
130                 list.add (p);
131             Collections.sort (list, p);
132         }
133         return list;
134     } // getArray
135

136     /**
137      * Refresh Values (nop)
138      * @return number of cache
139      */

140     public int refresh()
141     {
142         return p_data.size();
143     } // refresh
144

145     /**
146      * Get underlying fully qualified Table.Column Name
147      * @return column name
148      */

149     public String JavaDoc getColumnName()
150     {
151         return m_keyColumn;
152     } // getColumnName
153

154 } // XLookup
155
Popular Tags