Coverage details for ui.table.model.NAddressTableModel

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
50 
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 import java.util.Observer;
24  
25 import javax.swing.table.AbstractTableModel;
26  
27 import ui.Messages;
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 NAddressTableModel extends AbstractTableModel implements Observer {
370 
380    String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.city"), Messages.getString("common.nation"), Messages.getString("common.street"), Messages.getString("common.region"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
390            Messages.getString("common.postalcode"), Messages.getString("common.description") }; //$NON-NLS-1$ //$NON-NLS-2$
400 
41     public static final int NADDRESS_ID_COLUMN = 0;
42  
43     private static final int NADDRESS_CITY_COLUMN = 1;
44  
45     private static final int NADDRESS_NATION_COLUMN = 2;
46  
47     private static final int NADDRESS_STREET_COLUMN = 3;
48  
49     private static final int NADDRESS_REGION_COLUMN = 4;
50  
51     private static final int NADDRESS_POSTAL_CODE_COLUMN = 5;
52  
53     private static final int NADDRESS_DESCRIPTION_COLUMN = 6;
54  
55     private User user;
56  
570    public NAddressTableModel() {
580        super();
590    }
600 
610    public NAddressTableModel(User user) {
620        super();
630        this.user = user;
640        // FUK! WHY I CAN'T WRITE THAT ?
650        // this.user.addObserver(this);
660    }
670 
680    public int getColumnCount() {
690        return columnNames.length;
700    }
71  
720    public int getRowCount() {
730        return user.getNAddress().length;
740    }
75  
760    public String getColumnName(int col) {
770        return columnNames[col];
780    }
79  
800    public Object getValueAt(int row, int column) {
810        if (row < 0 || column < 0)
820            return null;
830        NAddress[] address = user.getNAddress();
840        Object result = null;
850        switch (column) {
860        case NADDRESS_ID_COLUMN:
870            result = address[row].getId();
880            break;
890        case NADDRESS_CITY_COLUMN:
900            result = address[row].getCity();
910            break;
920        case NADDRESS_NATION_COLUMN:
930            result = address[row].getNation();
940            break;
950        case NADDRESS_STREET_COLUMN:
960            result = address[row].getStreet();
970            break;
980        case NADDRESS_REGION_COLUMN:
990            result = address[row].getRegion();
1000            break;
1010        case NADDRESS_POSTAL_CODE_COLUMN:
1020            result = address[row].getPostalCode();
1030            break;
1040        case NADDRESS_DESCRIPTION_COLUMN:
1050            result = address[row].getDescription();
1060            break;
1070        }
1080        return result;
1090    }
110  
111     @SuppressWarnings("unchecked") //$NON-NLS-1$
1120    public Class getColumnClass(int column) {
1130        if (column < 0)
1140            return null;
1150        Class result = null;
1160        switch (column) {
1170        case NADDRESS_ID_COLUMN:
1180            result = Integer.class;
1190            break;
1200        case NADDRESS_CITY_COLUMN:
1210            result = String.class;
1220            break;
1230        case NADDRESS_NATION_COLUMN:
1240            result = String.class;
1250            break;
1260        case NADDRESS_STREET_COLUMN:
1270            result = String.class;
1280            break;
1290        case NADDRESS_REGION_COLUMN:
1300            result = String.class;
1310            break;
1320        case NADDRESS_POSTAL_CODE_COLUMN:
1330            result = String.class;
1340            break;
1350        case NADDRESS_DESCRIPTION_COLUMN:
1360            result = String.class;
1370            break;
1380        }
1390        return result;
1400    }
141  
142     /*
143      * Don't need to implement this method unless your table's editable.
144      */
1450    public boolean isCellEditable(int row, int column) {
1460        if (row < 0 || column < 0)
1470            return false;
1480        // Note that the data/cell address is constant,
1490        // no matter where the cell appears onscreen.
1500        boolean result = false;
1510        switch (column) {
1520        case NADDRESS_ID_COLUMN:
1530            result = false;
1540            break;
1550        case NADDRESS_CITY_COLUMN:
1560            result = true;
1570            break;
1580        case NADDRESS_NATION_COLUMN:
1590            result = true;
1600            break;
1610        case NADDRESS_STREET_COLUMN:
1620            result = true;
1630            break;
1640        case NADDRESS_REGION_COLUMN:
1650            result = true;
1660            break;
1670        case NADDRESS_POSTAL_CODE_COLUMN:
1680            result = true;
1690            break;
1700        case NADDRESS_DESCRIPTION_COLUMN:
1710            result = true;
1720            break;
1730        }
1740        return result;
1750    }
176  
177     /*
178      * Don't need to implement this method unless your table's data can change.
179      */
1800    public void setValueAt(Object value, int row, int column) {
1810        if (row < 0 || column < 0)
1820            return;
1830        switch (column) {
1840        case NADDRESS_ID_COLUMN:
1850            break;
1860        case NADDRESS_CITY_COLUMN:
1870            user.getNAddress()[row].setCity(value.toString());
1880            break;
1890        case NADDRESS_NATION_COLUMN:
1900            user.getNAddress()[row].setNation(value.toString());
1910            break;
1920        case NADDRESS_STREET_COLUMN:
1930            user.getNAddress()[row].setStreet(value.toString());
1940            break;
1950        case NADDRESS_REGION_COLUMN:
1960            user.getNAddress()[row].setRegion(value.toString());
1970            break;
1980        case NADDRESS_POSTAL_CODE_COLUMN:
1990            user.getNAddress()[row].setPostalCode(value.toString());
2000            break;
2010        case NADDRESS_DESCRIPTION_COLUMN:
2020            user.getNAddress()[row].setDescription(value.toString());
2030            break;
2040        }
2050        fireTableCellUpdated(row, column);
2060    }
2070 
208     /*
209      * (non-Javadoc)
210      *
211      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
212      */
2130    public void update(Observable observable, Object changedObject) {
2140        if (changedObject instanceof NAddress)
2150            this.fireTableDataChanged();
2160    }
2170}

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.