Coverage details for ui.table.model.ServiceTableModel

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 import java.util.Observer;
24  
25 import javax.swing.table.AbstractTableModel;
26  
27 import ui.Messages;
28 import base.InternetCafeManager;
29 import base.service.Service;
30 import base.service.ServiceRateType;
31  
32 @SuppressWarnings("serial") //$NON-NLS-1$
33 public class ServiceTableModel extends AbstractTableModel implements Observer {
340 
350    String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.description"), Messages.getString("common.ratetype"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
360            Messages.getString("common.baserate"), Messages.getString("common.mindurationinminute"), Messages.getString("common.maxdurationinminute") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
370 
38     public static final int SERVICE_ID_COLUMN = 0;
39  
40     public static final int SERVICE_NAME_COLUMN = 1;
41  
42     public static final int SERVICE_DESCRIPTION_COLUMN = 2;
43  
44     public static final int SERVICE_RATE_TYPE_COLUMN = 3;
45  
46     public static final int SERVICE_BASE_RATE_COLUMN = 4;
47  
48     public static final int SERVICE_MIN_DURATION_IN_MINUTE_COLUMN = 5;
49  
50     public static final int SERVICE_MAX_DURATION_IN_MINUTE_COLUMN = 6;
51  
520    public ServiceTableModel() {
530        super();
540        InternetCafeManager.getInstance().addObserver(this);
550    }
560 
570    public int getColumnCount() {
580        return columnNames.length;
590    }
60  
610    public int getRowCount() {
620        return InternetCafeManager.getInstance().getService().length;
630    }
64  
650    public String getColumnName(int col) {
660        return columnNames[col];
670    }
68  
690    public Object getValueAt(int row, int column) {
700        if (row < 0 || column < 0)
710            return null;
720        Service[] service = InternetCafeManager.getInstance().getService();
730        Object result = null;
740        switch (column) {
750        case SERVICE_ID_COLUMN:
760            result = service[row].getId();
770            break;
780        case SERVICE_NAME_COLUMN:
790            result = service[row].getName();
800            break;
810        case SERVICE_DESCRIPTION_COLUMN:
820            result = service[row].getDescription();
830            break;
840        case SERVICE_RATE_TYPE_COLUMN:
850            result = service[row].getRateType();
860            break;
870        case SERVICE_BASE_RATE_COLUMN:
880            result = service[row].getBaseRate();
890            break;
900        case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN:
910            result = service[row].getMinDurationInMinute();
920            break;
930        case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN:
940            result = service[row].getMaxDurationInMinute();
950            break;
960        }
970        return result;
980    }
99  
100     @SuppressWarnings("unchecked") //$NON-NLS-1$
1010    public Class getColumnClass(int column) {
1020        if (column < 0)
1030            return null;
1040        Class result = null;
1050        switch (column) {
1060        case SERVICE_ID_COLUMN:
1070            result = Integer.class;
1080            break;
1090        case SERVICE_NAME_COLUMN:
1100            result = String.class;
1110            break;
1120        case SERVICE_DESCRIPTION_COLUMN:
1130            result = String.class;
1140            break;
1150        case SERVICE_RATE_TYPE_COLUMN:
1160            result = ServiceRateType.class;
1170            break;
1180        case SERVICE_BASE_RATE_COLUMN:// Should be Double but with string will
119             // be displayed the double's dot
1200            // notation
1210            result = String.class;
1220            break;
1230        case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN:
1240            result = Integer.class;
1250            break;
1260        case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN:
1270            result = Integer.class;
1280            break;
1290        }
1300        return result;
1310    }
132  
133     /*
134      * Don't need to implement this method unless your table's editable.
135      */
1360    public boolean isCellEditable(int row, int column) {
1370        if (row < 0 || column < 0)
1380            return false;
1390        // Note that the data/cell address is constant,
1400        // no matter where the cell appears onscreen.
1410        boolean result = false;
1420        switch (column) {
1430        case SERVICE_ID_COLUMN:
1440            result = false;
1450            break;
1460        case SERVICE_NAME_COLUMN:
1470            result = true;
1480            break;
1490        case SERVICE_DESCRIPTION_COLUMN:
1500            result = true;
1510            break;
1520        case SERVICE_RATE_TYPE_COLUMN:
1530            result = true;
1540            break;
1550        case SERVICE_BASE_RATE_COLUMN:
1560            result = false;
1570            break;
1580        case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN:
1590            result = true;
1600            break;
1610        case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN:
1620            result = true;
1630            break;
1640        }
1650        return result;
1660    }
167  
168     /*
169      * Don't need to implement this method unless your table's data can change.
170      */
1710    public void setValueAt(Object value, int row, int column) {
1720        if (row < 0 || column < 0)
1730            return;
1740        @SuppressWarnings("unused") //$NON-NLS-1$
1750        Service[] service = InternetCafeManager.getInstance().getService();
1760        switch (column) {
1770        case SERVICE_ID_COLUMN:
1780            break;
1790        case SERVICE_NAME_COLUMN:
1800            service[row].setName((String) value);
1810            break;
1820        case SERVICE_DESCRIPTION_COLUMN:
1830            service[row].setDescription((String) value);
1840            break;
1850        case SERVICE_RATE_TYPE_COLUMN:
1860            service[row].setRateType((String) value);
1870            break;
1880        case SERVICE_BASE_RATE_COLUMN:
1890            service[row].setBaseRate(Double.parseDouble(value.toString()));
1900            break;
1910        case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN:
1920            service[row].setMinDurationInMinute(Integer.parseInt(value
1930                    .toString()));
1940            break;
1950        case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN:
1960            service[row].setMaxDurationInMinute(Integer.parseInt(value
1970                    .toString()));
1980            break;
1990        }
2000        fireTableCellUpdated(row, column);
2010    }
2020 
203     /*
204      * (non-Javadoc)
205      *
206      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
207      */
2080    public void update(Observable observable, Object changedObject) {
2090        if (changedObject instanceof Service)
2100            this.fireTableDataChanged();
2110    }
2120}

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.