Coverage details for ui.table.model.BackupTableModel

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.backup.Backup;
30  
31 @SuppressWarnings("serial") //$NON-NLS-1$
32 public class BackupTableModel extends AbstractTableModel implements Observer {
330 
340    String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.date"), Messages.getString("common.description"), Messages.getString("common.size")+" "+Messages.getString("common.unit.kylobyte") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
350 
36     public static final int BACKUP_ID_COLUMN = 0;
37  
38     public static final int BACKUP_NAME_COLUMN = 1;
39  
40     public static final int BACKUP_DATE_COLUMN = 2;
41  
42     public static final int BACKUP_DESCRIPTION_COLUMN = 3;
43  
44     public static final int BACKUP_SIZE_COLUMN = 4;
45  
460    public BackupTableModel() {
470        super();
480        InternetCafeManager.getInstance().addObserver(this);
490    }
500 
510    public int getColumnCount() {
520        return columnNames.length;
530    }
54  
550    public int getRowCount() {
560        return InternetCafeManager.getInstance().getBackup().length;
570    }
58  
590    public String getColumnName(int col) {
600        return columnNames[col];
610    }
62  
630    public Object getValueAt(int row, int column) {
640        if (row < 0 || column < 0)
650            return null;
660        Backup[] backup = InternetCafeManager.getInstance().getBackup();
670        Object result = null;
680        switch (column) {
690        case BACKUP_ID_COLUMN:
700            result = backup[row].getId();
710            break;
720        case BACKUP_NAME_COLUMN:
730            result = backup[row].getName();
740            break;
750        case BACKUP_DATE_COLUMN:
760            result = backup[row].getDate().toString();
770            break;
780        case BACKUP_DESCRIPTION_COLUMN:
790            result = backup[row].getDescription();
800            break;
810        case BACKUP_SIZE_COLUMN:
820            result = backup[row].getSize() > 0 ? backup[row].getSize()
830                    : Messages.getString("backuptablemodel.message1"); //$NON-NLS-1$
840            break;
850        }
860        return result;
870    }
88  
89     @SuppressWarnings("unchecked") //$NON-NLS-1$
900    public Class getColumnClass(int column) {
910        if (column < 0)
920            return null;
930        Class result = null;
940        switch (column) {
950        case BACKUP_ID_COLUMN:
960            result = Integer.class;
970            break;
980        case BACKUP_NAME_COLUMN:
990            result = String.class;
1000            break;
1010        case BACKUP_DATE_COLUMN:
1020            result = String.class;
1030            break;
1040        case BACKUP_DESCRIPTION_COLUMN:
1050            result = String.class;
1060            break;
1070        case BACKUP_SIZE_COLUMN:
1080            result = Long.class;
1090            break;
1100        }
1110        return result;
1120    }
113  
114     /*
115      * Don't need to implement this method unless your table's editable.
116      */
1170    public boolean isCellEditable(int row, int column) {
1180        if (row < 0 || column < 0)
1190            return false;
1200        // Note that the data/cell address is constant,
1210        // no matter where the cell appears onscreen.
1220        boolean result = false;
1230        switch (column) {
1240        case BACKUP_ID_COLUMN:
1250            result = false;
1260            break;
1270        case BACKUP_NAME_COLUMN:
1280            result = false;
1290            break;
1300        case BACKUP_DATE_COLUMN:
1310            result = false;
1320            break;
1330        case BACKUP_DESCRIPTION_COLUMN:
1340            result = true;
1350            break;
1360        case BACKUP_SIZE_COLUMN:
1370            result = false;
1380            break;
1390        }
1400        return result;
1410    }
142  
143     /*
144      * Don't need to implement this method unless your table's data can change.
145      */
1460    public void setValueAt(Object value, int row, int column) {
1470        if (row < 0 || column < 0)
1480            return;
1490        fireTableCellUpdated(row, column);
1500    }
1510 
152     /*
153      * (non-Javadoc)
154      *
155      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
156      */
1570    public void update(Observable observable, Object changedObject) {
1580        if (changedObject instanceof Backup)
1590            this.fireTableDataChanged();
1600    }
1610 
162 }

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.