Coverage details for ui.table.model.UserTableModel

LineHitsSource
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 {
370 
380    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$
390            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$
400 
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  
590    public UserTableModel() {
600        super();
610        InternetCafeManager.getInstance().addObserver(this);
620    }
630 
640    public int getColumnCount() {
650        return columnNames.length;
660    }
67  
680    public int getRowCount() {
690        return InternetCafeManager.getInstance().getUser().length;
700    }
71  
720    public String getColumnName(int col) {
730        return columnNames[col];
740    }
75  
760    public Object getValueAt(int row, int column) {
770        if (row < 0 || column < 0)
780            return null;
790        User[] user = InternetCafeManager.getInstance().getUser();
800        Object result = null;
810        switch (column) {
820        case USER_ID_COLUMN:// Id
830            result = user[row].getId();
840            break;
850        case USER_NAME_COLUMN:// Name
860            result = user[row].getName();
870            break;
880        case USER_SURNAME_COLUMN:// Surname
890            result = user[row].getSurname();
900            break;
910        case USER_GENDER_COLUMN:// Gender
920            result = user[row].getGender();
930            break;
940        case USER_BIRTHDAY_COLUMN:// Birthday
950            result = user[row].getBirthday();
960            break;
970        case USER_NICKNAME_COLUMN:// Nickname
980            result = user[row].getNickname();
990            break;
1000        case USER_CREDENTIAL_COLUMN:// Credential
1010            result = user[row].getCredential();
1020            break;
1030        case USER_VALID_DOCUMENT_COLUMN:// Has Document associated with a valid
1040            // image
1050            result = Control.isValidUserDocument(user[row].getDocument())
1060                    && Control.isValidDocumentImage(user[row].getDocument()
1070                            .getImagePath());
1080            break;
1090        case USER_CREATION_DATE_COLUMN:// Creation Date
1100            result = user[row].getCreationDate();
1110            break;
1120        }
1130        return result;
1140    }
115  
116     @SuppressWarnings("unchecked") //$NON-NLS-1$
1170    public Class getColumnClass(int column) {
1180        if (column < 0)
1190            return null;
1200        Class result = null;
1210        switch (column) {
1220        case USER_ID_COLUMN:// Id
1230            result = Integer.class;
1240            break;
1250        case USER_NAME_COLUMN:// Name
1260            result = String.class;
1270            break;
1280        case USER_SURNAME_COLUMN:// Surname
1290            result = String.class;
1300            break;
1310        case USER_GENDER_COLUMN:// Gender
1320            result = UserGender.class;
1330            break;
1340        case USER_BIRTHDAY_COLUMN:// Birthday
1350            result = Date.class;
1360            break;
1370        case USER_NICKNAME_COLUMN:// Nickname
1380            result = String.class;
1390            break;
1400        case USER_CREDENTIAL_COLUMN:// Credential
1410            result = UserCredential.class;
1420            break;
1430        case USER_VALID_DOCUMENT_COLUMN:// Has Document
1440            result = Boolean.class;
1450            break;
1460        case USER_CREATION_DATE_COLUMN:// Creation Date
1470            result = Date.class;
1480            break;
1490        }
1500        return result;
1510    }
152  
153     /*
154      * Don't need to implement this method unless your table's editable.
155      */
1560    public boolean isCellEditable(int row, int column) {
1570        if (row < 0 || column < 0)
1580            return false;
1590        // Note that the data/cell address is constant,
1600        // no matter where the cell appears onscreen.
1610        boolean result = false;
1620        switch (column) {
1630        case USER_ID_COLUMN:// Id
1640            result = false;
1650            break;
1660        case USER_NAME_COLUMN:// Name
1670            result = false;
1680            break;
1690        case USER_SURNAME_COLUMN:// Surname
1700            result = false;
1710            break;
1720        case USER_GENDER_COLUMN:// Gender
1730            result = true;
1740            break;
1750        case USER_BIRTHDAY_COLUMN:// Birthday
1760            result = false;
1770            break;
1780        case USER_NICKNAME_COLUMN:// Nickname
1790            result = false;
1800            break;
1810        case USER_CREDENTIAL_COLUMN:// Credential
1820            result = true;
1830            break;
1840        case USER_VALID_DOCUMENT_COLUMN:// Has Document
1850            result = false;
1860            break;
1870        case USER_CREATION_DATE_COLUMN:// Creation Date
1880            result = false;
1890            break;
1900        }
1910        return result;
1920    }
193  
194     /*
195      * Don't need to implement this method unless your table's data can change.
196      */
1970    public void setValueAt(Object value, int row, int column) {
1980        if (row < 0 || column < 0)
1990            return;
2000 
2010        User[] user = InternetCafeManager.getInstance().getUser();
2020        switch (column) {
2030        case USER_ID_COLUMN:// Id
2040            break;
2050        case USER_NAME_COLUMN:// Name
2060            user[row].setName((String) value);
2070            break;
2080        case USER_SURNAME_COLUMN:// Surname
2090            user[row].setSurname((String) value);
2100            break;
2110        case USER_GENDER_COLUMN:// Gender
2120            user[row].setGender((String) value);
2130            break;
2140        case USER_BIRTHDAY_COLUMN:// Birthday
2150            break;
2160        case USER_NICKNAME_COLUMN:// Nickname
2170            break;
2180        case USER_CREDENTIAL_COLUMN:// Credential
2190            user[row].setCredential((String) value);
2200            break;
2210        case USER_VALID_DOCUMENT_COLUMN:// Has Document
2220            break;
2230        case USER_CREATION_DATE_COLUMN:// Creation Date
224             break;
225         }
2260 
2270        fireTableCellUpdated(row, column);
2280    }
2290 
230     /*
231      * (non-Javadoc)
232      *
233      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
234      */
2350    public void update(Observable observable, Object changedObject) {
2360        if (changedObject instanceof User)
2370            this.fireTableDataChanged();
2380    }
2390 
240 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.