KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
17 import java.sql.Timestamp JavaDoc;
18 import java.io.Serializable JavaDoc;
19
20 /**
21  * Data Status Event
22  * <p>
23  * Indicates the current Status of the database
24  *
25  * @author Jorg Janke
26  * @version $Id: DataStatusEvent.java,v 1.4 2003/08/18 15:48:03 jjanke Exp $
27  */

28 public final class DataStatusEvent extends EventObject implements Serializable JavaDoc
29 {
30     /**
31      * Constructor
32      * @param source source
33      * @param totalRows total rows
34      * @param changed changed
35      * @param autoSave auto save
36      * @param inserting inserting
37      */

38     public DataStatusEvent (Object JavaDoc source, int totalRows, boolean changed, boolean autoSave, boolean inserting)
39     {
40         super(source);
41         m_totalRows = totalRows;
42         m_changed = changed;
43         m_autoSave = autoSave;
44         m_inserting = inserting;
45     } // DataStatusEvent
46

47     private int m_totalRows;
48     private boolean m_changed;
49     private boolean m_autoSave;
50     private boolean m_inserting;
51     //
52
private String JavaDoc m_AD_Message = null;
53     private String JavaDoc m_info = null;
54     private boolean m_isError = false;
55     private boolean m_confirmed = false;
56     //
57
private boolean m_allLoaded = true;
58     private int m_loadedRows = -1;
59     private int m_currentRow = -1;
60     //
61
private int m_changedColumn = 0;
62     //
63
public Timestamp JavaDoc Created = null;
64     public Object JavaDoc CreatedBy = null;
65     public Timestamp JavaDoc Updated = null;
66     public Object JavaDoc UpdatedBy = null;
67     //
68
public String JavaDoc Info = null;
69
70     /**
71      * Set Loaded Info
72      * @param loadedRows loaded rows
73      */

74     public void setLoading (int loadedRows)
75     {
76         m_allLoaded = false;
77         m_loadedRows = loadedRows;
78     } // setLoaded
79

80     /**
81      * Is loading
82      * @return true if loading
83      */

84     public boolean isLoading()
85     {
86         return !m_allLoaded;
87     } // isLoading
88

89     /**
90      * Get loaded rows
91      * @return loaded rows
92      */

93     public int getLoadedRows()
94     {
95         return m_loadedRows;
96     } // getLoadedRows
97

98     /**
99      * Set current Row (zero based)
100      * @param currentRow current row
101      */

102     public void setCurrentRow (int currentRow)
103     {
104         m_currentRow = currentRow;
105     } // setCurrentRow
106

107     /**
108      * Get current row (zero based)
109      * @return current roe
110      */

111     public int getCurrentRow()
112     {
113         return m_currentRow;
114     } // getCurrentRow
115

116     /**
117      * Get total rows
118      * @return total rows
119      */

120     public int getTotalRows()
121     {
122         return m_totalRows;
123     } // getTotalRows
124

125     /**
126      * Set Message Info
127      * @param info info
128      * @param isError error
129      */

130     public void setInfo (String JavaDoc info, boolean isError)
131     {
132         m_info = info;
133         m_isError = isError;
134     } // setInfo
135

136     /**
137      * Set Message Info
138      * @param AD_Message message
139      * @param info info
140      * @param isError error
141      */

142     public void setInfo (String JavaDoc AD_Message, String JavaDoc info, boolean isError)
143     {
144         m_AD_Message = AD_Message;
145         m_info = info;
146         m_isError = isError;
147     } // setInfo
148

149     /**
150      * Set Inserting
151      * @param inserting inserting
152      */

153     public void setInserting (boolean inserting)
154     {
155         m_inserting = inserting;
156     } // setInserting
157

158     /**
159      * Are we inserting
160      * @return true if inserting
161      */

162     public boolean isInserting()
163     {
164         return m_inserting;
165     } // isInserting
166

167     /**
168      * Get Message Info
169      * @return Message
170      */

171     public String JavaDoc getAD_Message()
172     {
173         return m_AD_Message;
174     } // getAD_Message
175

176     /**
177      * Get Message Info
178      * @return Info
179      */

180     public String JavaDoc getInfo()
181     {
182         return m_info;
183     } // getInfo
184

185     /**
186      * Is this an error
187      * @return true if error
188      */

189     public boolean isError()
190     {
191         return m_isError;
192     } // isError
193

194     /**
195      * String representation of Status.
196      * @return Examples: +*1?/20
197      * 1/256->2000
198      */

199     public String JavaDoc toString()
200     {
201         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("DataStatusEvent - ");
202         if (m_AD_Message != null)
203             sb.append(m_AD_Message);
204         if (m_info != null)
205             sb.append(" ").append(m_info);
206         sb.append(" : ").append(getMessage());
207         return sb.toString();
208     } // toString
209

210     /**
211      * String representation of Status.
212      * <pre>
213      * *1/20 Change - automatic commit
214      * ?1/20 Change - manual confirm
215      * 1/56->200 Loading
216      * 1/20 Normal
217      * +*1/20 Inserting, changed - automatic commit
218      * The row number is converted from zero based representation
219      * </pre>
220      * @return Status info
221      */

222     public String JavaDoc getMessage()
223     {
224         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc();
225         if (m_inserting)
226             retValue.append("+");
227         retValue.append(m_changed ? (m_autoSave ? "*" : "?") : " ");
228         // current row
229
if (m_totalRows == 0)
230             retValue.append(m_currentRow);
231         else
232             retValue.append(m_currentRow+1);
233         // of
234
retValue.append("/");
235         if (m_allLoaded)
236             retValue.append(m_totalRows);
237         else
238             retValue.append(m_loadedRows).append("->").append(m_totalRows);
239         //
240
return retValue.toString();
241     } // getMessage
242

243     /**
244      * Is Data Changed
245      * @return true if changed
246      */

247     public boolean isChanged()
248     {
249         return m_changed;
250     } // isChanged
251

252     /**
253      * Is First Row - (zero based)
254      * @return true if first row
255      */

256     public boolean isFirstRow()
257     {
258         if (m_totalRows == 0)
259             return true;
260         return m_currentRow == 0;
261     } // isFirstRow
262

263     /**
264      * Is Last Row - (zero based)
265      * @return true if last row
266      */

267     public boolean isLastRow()
268     {
269         if (m_totalRows == 0)
270             return true;
271         return m_currentRow == m_totalRows-1;
272     } // isLastRow
273

274     /**
275      * Set Changed Column
276      * @param col column
277      */

278     public void setChangedColumn (int col)
279     {
280         m_changedColumn = col;
281     } // setChangedColumn
282

283     /**
284      * Get Changed Column
285      * @return changed column
286      */

287     public int getChangedColumn()
288     {
289         return m_changedColumn;
290     } // getChangedColumn
291

292     /**
293      * Set Confirmed toggle
294      * @param confirmed confirmed
295      */

296     public void setConfirmed (boolean confirmed)
297     {
298         m_confirmed = confirmed;
299     } // setConfirmed
300

301     /**
302      * Is Confirmed (e.g. user has seen it)
303      * @return true if confirmed
304      */

305     public boolean isConfirmed()
306     {
307         return m_confirmed;
308     } // isConfirmed
309

310 } // DataStatusEvent
311
Popular Tags