Coverage details for ui.table.model.EAddressTableModel

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.EAddress;
28 import base.user.NAddress;
29 import base.user.User;
30  
31 /**
32  * @author skunk
33  *
34  */
35 @SuppressWarnings("serial") //$NON-NLS-1$
36 public class EAddressTableModel extends AbstractTableModel {
370 
380    String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.address"), Messages.getString("common.description") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
390 
40     public static final int EADDRESS_ID_COLUMN = 0;
41  
42     private static final int EADDRESS_ADDRESS_COLUMN = 1;
43  
44     private static final int EADDRESS_DESCRIPTION_COLUMN = 2;
45  
46     private User user;
470 
480    public EAddressTableModel(User user) {
490        this.user = user;
500    }
510 
520    public int getColumnCount() {
530        return columnNames.length;
540    }
55  
560    public int getRowCount() {
570        return user.getEAddress().length;
580    }
59  
600    public String getColumnName(int col) {
610        return columnNames[col];
620    }
63  
640    public Object getValueAt(int row, int column) {
650        if (row < 0 || column < 0)
660            return null;
670        EAddress[] address = user.getEAddress();
680        Object result = null;
690        switch (column) {
700        case EADDRESS_ID_COLUMN:
710            result = address[row].getId();
720            break;
730        case EADDRESS_ADDRESS_COLUMN:
740            result = address[row].toString();
750            break;
760        case EADDRESS_DESCRIPTION_COLUMN:
770            result = address[row].getDescription();
780            break;
790        }
800        return result;
810    }
82  
83     @SuppressWarnings("unchecked") //$NON-NLS-1$
840    public Class getColumnClass(int column) {
850        if (column < 0)
860            return null;
870        Class result = null;
880        switch (column) {
890        case EADDRESS_ID_COLUMN:
900            result = Integer.class;
910            break;
920        case EADDRESS_ADDRESS_COLUMN:
930            result = String.class;
940            break;
950        case EADDRESS_DESCRIPTION_COLUMN:
960            result = String.class;
970            break;
980        }
990        return result;
1000    }
101  
102     /*
103      * Don't need to implement this method unless your table's editable.
104      */
1050    public boolean isCellEditable(int row, int column) {
1060        if (row < 0 || column < 0)
1070            return false;
1080        // Note that the data/cell address is constant,
1090        // no matter where the cell appears onscreen.
1100        boolean result = false;
1110        switch (column) {
1120        case EADDRESS_ID_COLUMN:
1130            result = false;
1140            break;
1150        case EADDRESS_ADDRESS_COLUMN:
1160            result = false;
1170            break;
1180        case EADDRESS_DESCRIPTION_COLUMN:
1190            result = true;
1200            break;
1210        }
1220        return result;
1230    }
124  
125     /*
126      * Don't need to implement this method unless your table's data can change.
127      */
1280    public void setValueAt(Object value, int row, int column) {
1290        if (row < 0 || column < 0)
1300            return;
1310        EAddress[] address = user.getEAddress();
1320        switch (column) {
1330        case EADDRESS_DESCRIPTION_COLUMN:
1340            address[row].equals(value);
1350            break;
1360        }
1370        fireTableCellUpdated(row, column);
1380    }
1390 
140     /*
141      * (non-Javadoc)
142      *
143      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
144      */
1450    public void update(Observable observable, Object changedObject) {
1460        if (changedObject instanceof NAddress)
1470            this.fireTableDataChanged();
1480    }
1490}

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.