Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package ui.table.model; | |
21 | ||
22 | import java.util.Date; | |
23 | import java.util.Observable; | |
24 | import java.util.Observer; | |
25 | ||
26 | import javax.swing.table.AbstractTableModel; | |
27 | ||
28 | import ui.Messages; | |
29 | import base.Control; | |
30 | import base.InternetCafeManager; | |
31 | import base.user.User; | |
32 | import base.user.UserCredential; | |
33 | import base.user.UserGender; | |
34 | ||
35 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
36 | public class UserTableModel extends AbstractTableModel implements Observer { | |
37 | 0 | |
38 | 0 | String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.surname"), Messages.getString("common.gender"), Messages.getString("common.birthday"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
39 | 0 | Messages.getString("common.nickname"), Messages.getString("common.credential"), Messages.getString("common.validdocument"), Messages.getString("common.creationdate") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
40 | 0 | |
41 | public static final int USER_ID_COLUMN = 0; | |
42 | ||
43 | public static final int USER_NAME_COLUMN = 1; | |
44 | ||
45 | public static final int USER_SURNAME_COLUMN = 2; | |
46 | ||
47 | public static final int USER_GENDER_COLUMN = 3; | |
48 | ||
49 | public static final int USER_BIRTHDAY_COLUMN = 4; | |
50 | ||
51 | public static final int USER_NICKNAME_COLUMN = 5; | |
52 | ||
53 | public static final int USER_CREDENTIAL_COLUMN = 6; | |
54 | ||
55 | public static final int USER_VALID_DOCUMENT_COLUMN = 7; | |
56 | ||
57 | public static final int USER_CREATION_DATE_COLUMN = 8; | |
58 | ||
59 | 0 | public UserTableModel() { |
60 | 0 | super(); |
61 | 0 | InternetCafeManager.getInstance().addObserver(this); |
62 | 0 | } |
63 | 0 | |
64 | 0 | public int getColumnCount() { |
65 | 0 | return columnNames.length; |
66 | 0 | } |
67 | ||
68 | 0 | public int getRowCount() { |
69 | 0 | return InternetCafeManager.getInstance().getUser().length; |
70 | 0 | } |
71 | ||
72 | 0 | public String getColumnName(int col) { |
73 | 0 | return columnNames[col]; |
74 | 0 | } |
75 | ||
76 | 0 | public Object getValueAt(int row, int column) { |
77 | 0 | if (row < 0 || column < 0) |
78 | 0 | return null; |
79 | 0 | User[] user = InternetCafeManager.getInstance().getUser(); |
80 | 0 | Object result = null; |
81 | 0 | switch (column) { |
82 | 0 | case USER_ID_COLUMN:// Id |
83 | 0 | result = user[row].getId(); |
84 | 0 | break; |
85 | 0 | case USER_NAME_COLUMN:// Name |
86 | 0 | result = user[row].getName(); |
87 | 0 | break; |
88 | 0 | case USER_SURNAME_COLUMN:// Surname |
89 | 0 | result = user[row].getSurname(); |
90 | 0 | break; |
91 | 0 | case USER_GENDER_COLUMN:// Gender |
92 | 0 | result = user[row].getGender(); |
93 | 0 | break; |
94 | 0 | case USER_BIRTHDAY_COLUMN:// Birthday |
95 | 0 | result = user[row].getBirthday(); |
96 | 0 | break; |
97 | 0 | case USER_NICKNAME_COLUMN:// Nickname |
98 | 0 | result = user[row].getNickname(); |
99 | 0 | break; |
100 | 0 | case USER_CREDENTIAL_COLUMN:// Credential |
101 | 0 | result = user[row].getCredential(); |
102 | 0 | break; |
103 | 0 | case USER_VALID_DOCUMENT_COLUMN:// Has Document associated with a valid |
104 | 0 | // image |
105 | 0 | result = Control.isValidUserDocument(user[row].getDocument()) |
106 | 0 | && Control.isValidDocumentImage(user[row].getDocument() |
107 | 0 | .getImagePath()); |
108 | 0 | break; |
109 | 0 | case USER_CREATION_DATE_COLUMN:// Creation Date |
110 | 0 | result = user[row].getCreationDate(); |
111 | 0 | break; |
112 | 0 | } |
113 | 0 | return result; |
114 | 0 | } |
115 | ||
116 | @SuppressWarnings("unchecked") //$NON-NLS-1$ | |
117 | 0 | public Class getColumnClass(int column) { |
118 | 0 | if (column < 0) |
119 | 0 | return null; |
120 | 0 | Class result = null; |
121 | 0 | switch (column) { |
122 | 0 | case USER_ID_COLUMN:// Id |
123 | 0 | result = Integer.class; |
124 | 0 | break; |
125 | 0 | case USER_NAME_COLUMN:// Name |
126 | 0 | result = String.class; |
127 | 0 | break; |
128 | 0 | case USER_SURNAME_COLUMN:// Surname |
129 | 0 | result = String.class; |
130 | 0 | break; |
131 | 0 | case USER_GENDER_COLUMN:// Gender |
132 | 0 | result = UserGender.class; |
133 | 0 | break; |
134 | 0 | case USER_BIRTHDAY_COLUMN:// Birthday |
135 | 0 | result = Date.class; |
136 | 0 | break; |
137 | 0 | case USER_NICKNAME_COLUMN:// Nickname |
138 | 0 | result = String.class; |
139 | 0 | break; |
140 | 0 | case USER_CREDENTIAL_COLUMN:// Credential |
141 | 0 | result = UserCredential.class; |
142 | 0 | break; |
143 | 0 | case USER_VALID_DOCUMENT_COLUMN:// Has Document |
144 | 0 | result = Boolean.class; |
145 | 0 | break; |
146 | 0 | case USER_CREATION_DATE_COLUMN:// Creation Date |
147 | 0 | result = Date.class; |
148 | 0 | break; |
149 | 0 | } |
150 | 0 | return result; |
151 | 0 | } |
152 | ||
153 | /* | |
154 | * Don't need to implement this method unless your table's editable. | |
155 | */ | |
156 | 0 | public boolean isCellEditable(int row, int column) { |
157 | 0 | if (row < 0 || column < 0) |
158 | 0 | return false; |
159 | 0 | // Note that the data/cell address is constant, |
160 | 0 | // no matter where the cell appears onscreen. |
161 | 0 | boolean result = false; |
162 | 0 | switch (column) { |
163 | 0 | case USER_ID_COLUMN:// Id |
164 | 0 | result = false; |
165 | 0 | break; |
166 | 0 | case USER_NAME_COLUMN:// Name |
167 | 0 | result = false; |
168 | 0 | break; |
169 | 0 | case USER_SURNAME_COLUMN:// Surname |
170 | 0 | result = false; |
171 | 0 | break; |
172 | 0 | case USER_GENDER_COLUMN:// Gender |
173 | 0 | result = true; |
174 | 0 | break; |
175 | 0 | case USER_BIRTHDAY_COLUMN:// Birthday |
176 | 0 | result = false; |
177 | 0 | break; |
178 | 0 | case USER_NICKNAME_COLUMN:// Nickname |
179 | 0 | result = false; |
180 | 0 | break; |
181 | 0 | case USER_CREDENTIAL_COLUMN:// Credential |
182 | 0 | result = true; |
183 | 0 | break; |
184 | 0 | case USER_VALID_DOCUMENT_COLUMN:// Has Document |
185 | 0 | result = false; |
186 | 0 | break; |
187 | 0 | case USER_CREATION_DATE_COLUMN:// Creation Date |
188 | 0 | result = false; |
189 | 0 | break; |
190 | 0 | } |
191 | 0 | return result; |
192 | 0 | } |
193 | ||
194 | /* | |
195 | * Don't need to implement this method unless your table's data can change. | |
196 | */ | |
197 | 0 | public void setValueAt(Object value, int row, int column) { |
198 | 0 | if (row < 0 || column < 0) |
199 | 0 | return; |
200 | 0 | |
201 | 0 | User[] user = InternetCafeManager.getInstance().getUser(); |
202 | 0 | switch (column) { |
203 | 0 | case USER_ID_COLUMN:// Id |
204 | 0 | break; |
205 | 0 | case USER_NAME_COLUMN:// Name |
206 | 0 | user[row].setName((String) value); |
207 | 0 | break; |
208 | 0 | case USER_SURNAME_COLUMN:// Surname |
209 | 0 | user[row].setSurname((String) value); |
210 | 0 | break; |
211 | 0 | case USER_GENDER_COLUMN:// Gender |
212 | 0 | user[row].setGender((String) value); |
213 | 0 | break; |
214 | 0 | case USER_BIRTHDAY_COLUMN:// Birthday |
215 | 0 | break; |
216 | 0 | case USER_NICKNAME_COLUMN:// Nickname |
217 | 0 | break; |
218 | 0 | case USER_CREDENTIAL_COLUMN:// Credential |
219 | 0 | user[row].setCredential((String) value); |
220 | 0 | break; |
221 | 0 | case USER_VALID_DOCUMENT_COLUMN:// Has Document |
222 | 0 | break; |
223 | 0 | case USER_CREATION_DATE_COLUMN:// Creation Date |
224 | break; | |
225 | } | |
226 | 0 | |
227 | 0 | fireTableCellUpdated(row, column); |
228 | 0 | } |
229 | 0 | |
230 | /* | |
231 | * (non-Javadoc) | |
232 | * | |
233 | * @see java.util.Observer#update(java.util.Observable, java.lang.Object) | |
234 | */ | |
235 | 0 | public void update(Observable observable, Object changedObject) { |
236 | 0 | if (changedObject instanceof User) |
237 | 0 | this.fireTableDataChanged(); |
238 | 0 | } |
239 | 0 | |
240 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |