Coverage details for ui.table.model.PhoneNumberTableModel

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.Observable;
23  
24 import javax.swing.table.AbstractTableModel;
25  
26 import ui.Messages;
27 import base.user.NAddress;
28 import base.user.PhoneNumber;
29 import base.user.User;
30  
31 @SuppressWarnings("serial") //$NON-NLS-1$
32 public class PhoneNumberTableModel extends AbstractTableModel {
330 
340    String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.areacode"), Messages.getString("common.exchange"), Messages.getString("common.number"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
350            Messages.getString("common.description") }; //$NON-NLS-1$
360 
37     public static final int PHONENUMBER_ID_COLUMN = 0;
38  
39     public static final int PHONENUMBER_AREA_CODE_COLUMN = 1;
40  
41     public static final int PHONENUMBER_EXCHANGE_COLUMN = 2;
42  
43     public static final int PHONENUMBER_NUMBER_COLUMN = 3;
44  
45     public static final int PHONENUMBER_DESCRIPTION_COLUMN = 4;
46  
47     private User user;
480 
490    public PhoneNumberTableModel(User user) {
500        this.user = user;
510    }
520 
530    public int getColumnCount() {
540        return columnNames.length;
550    }
56  
570    public int getRowCount() {
580        return user.getPhoneNumber().length;
590    }
60  
610    public String getColumnName(int col) {
620        return columnNames[col];
630    }
64  
650    public Object getValueAt(int row, int column) {
660        if (row < 0 || column < 0)
670            return null;
680        PhoneNumber[] phoneNumber = user.getPhoneNumber();
690        Object result = null;
700        switch (column) {
710        case PHONENUMBER_ID_COLUMN:
720            result = phoneNumber[row].getId();
730            break;
740        case PHONENUMBER_AREA_CODE_COLUMN:
750            result = phoneNumber[row].getAreaCode();
760            break;
770        case PHONENUMBER_EXCHANGE_COLUMN:
780            result = phoneNumber[row].getExchange();
790            break;
800        case PHONENUMBER_NUMBER_COLUMN:
810            result = phoneNumber[row].getNumber();
820            break;
830        case PHONENUMBER_DESCRIPTION_COLUMN:
840            result = phoneNumber[row].getDescription();
850            break;
860        }
870        return result;
880    }
89  
90     @SuppressWarnings("unchecked") //$NON-NLS-1$
910    public Class getColumnClass(int column) {
920        if (column < 0)
930            return null;
940        Class result = null;
950        switch (column) {
960        case PHONENUMBER_ID_COLUMN:
970            result = Integer.class;
980            break;
990        case PHONENUMBER_AREA_CODE_COLUMN:
1000            result = String.class;
1010            break;
1020        case PHONENUMBER_EXCHANGE_COLUMN:
1030            result = String.class;
1040            break;
1050        case PHONENUMBER_NUMBER_COLUMN:
1060            result = String.class;
1070            break;
1080        case PHONENUMBER_DESCRIPTION_COLUMN:
1090            result = String.class;
1100            break;
1110        }
1120        return result;
1130    }
114  
115     /*
116      * Don't need to implement this method unless your table's editable.
117      */
1180    public boolean isCellEditable(int row, int column) {
1190        if (row < 0 || column < 0)
1200            return false;
1210        // Note that the data/cell address is constant,
1220        // no matter where the cell appears onscreen.
1230        boolean result = false;
1240        switch (column) {
1250        case PHONENUMBER_ID_COLUMN:
1260            result = false;
1270            break;
1280        case PHONENUMBER_AREA_CODE_COLUMN:
1290            result = true;
1300            break;
1310        case PHONENUMBER_EXCHANGE_COLUMN:
1320            result = true;
1330            break;
1340        case PHONENUMBER_NUMBER_COLUMN:
1350            result = true;
1360            break;
1370        case PHONENUMBER_DESCRIPTION_COLUMN:
1380            result = true;
1390            break;
1400        }
1410        return result;
1420    }
143  
144     /*
145      * Don't need to implement this method unless your table's data can change.
146      */
1470    public void setValueAt(Object value, int row, int column) {
1480        if (row < 0 || column < 0)
1490            return;
1500        PhoneNumber phoneNumber = user.getPhoneNumberById(row);
1510        switch (column) {
1520        case PHONENUMBER_ID_COLUMN:
1530            break;
1540        case PHONENUMBER_AREA_CODE_COLUMN:
1550            phoneNumber.setAreaCode(value.toString());
1560            break;
1570        case PHONENUMBER_EXCHANGE_COLUMN:
1580            phoneNumber.setExchange(value.toString());
1590            break;
1600        case PHONENUMBER_NUMBER_COLUMN:
1610            phoneNumber.setNumber(value.toString());
1620            break;
1630        case PHONENUMBER_DESCRIPTION_COLUMN:
1640            phoneNumber.setDescription(value.toString());
1650            break;
1660        }
1670        fireTableCellUpdated(row, column);
1680    }
1690 
170     /*
171      * (non-Javadoc)
172      *
173      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
174      */
1750    public void update(Observable observable, Object changedObject) {
1760        if (changedObject instanceof NAddress)
1770            this.fireTableDataChanged();
1780    }
1790}

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.