Coverage details for ui.table.model.SessionTableModel

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.Date;
23 import java.util.Observable;
24 import java.util.Observer;
25  
26 import javax.swing.table.AbstractTableModel;
27  
28 import ui.Messages;
29 import base.InternetCafeManager;
30 import base.session.Session;
31  
32 @SuppressWarnings("serial") //$NON-NLS-1$
33 public class SessionTableModel extends AbstractTableModel implements Observer {
34  
35     /*
36      * private User user; private Workstation workstation; private String
37      * description; private Date startTime; private Date endTime;
380     */
390    String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.nickname"), Messages.getString("common.workstation"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
400            Messages.getString("common.description"), Messages.getString("common.starttime"), Messages.getString("common.endtime"), Messages.getString("common.service"), Messages.getString("common.finished") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
410 
42     public static final int SESSION_ID_COLUMN = 0;
43  
44     public static final int SESSION_USER_NICKNAME_COLUMN = 1;
45  
46     public static final int SESSION_WORKSTATION_NAME_COLUMN = 2;
47  
48     public static final int SESSION_DESCRIPTION_COLUMN = 3;
49  
50     public static final int SESSION_START_TIME_COLUMN = 4;
51  
52     public static final int SESSION_END_TIME_COLUMN = 5;
53  
54     public static final int SESSION_SERVICE_COLUMN = 6;
55  
56     public static final int SESSION_FINISHED_COLUMN = 7;
570 
580    private volatile Session[] data = null;
590 
600    public SessionTableModel() {
610        super();
620        InternetCafeManager.getInstance().addObserver(this);
630    }
640 
650    public int getColumnCount() {
660        return columnNames.length;
670    }
68  
690    public int getRowCount() {
700        return data != null ? data.length : InternetCafeManager.getInstance()
710                .getSession().length;
720    }
73  
740    public String getColumnName(int col) {
750        return columnNames[col];
760    }
77  
780    public Object getValueAt(int row, int column) {
790        if (row < 0 || column < 0)
800            return null;
810        Session[] session = data != null ? data : InternetCafeManager
820                .getInstance().getSession();
830        Object result = null;
840        switch (column) {
850        case SESSION_ID_COLUMN:
860            result = session[row].getId();
870            break;
880        case SESSION_USER_NICKNAME_COLUMN:
890            result = session[row].getUser().getNickname();
900            break;
910        case SESSION_WORKSTATION_NAME_COLUMN:
920            result = session[row].getWorkstation().getName();
930            break;
940        case SESSION_DESCRIPTION_COLUMN:
950            result = session[row].getDescription();
960            break;
970        case SESSION_START_TIME_COLUMN:
980            result = session[row].getStartTime();
990            break;
1000        case SESSION_END_TIME_COLUMN:
1010            result = session[row].getEndTime();
1020            break;
1030        case SESSION_SERVICE_COLUMN:
1040            result = session[row].getService().getName();
1050            break;
1060        case SESSION_FINISHED_COLUMN:
1070            result = session[row].isFinished();
1080            break;
1090        }
1100        return result;
1110    }
112  
113     @SuppressWarnings("unchecked") //$NON-NLS-1$
1140    public Class getColumnClass(int column) {
1150        if (column < 0)
1160            return null;
1170        Class result = null;
1180        switch (column) {
1190        case SESSION_ID_COLUMN:
1200            result = Integer.class;
1210            break;
1220        case SESSION_USER_NICKNAME_COLUMN:
1230            result = String.class;
1240            break;
1250        case SESSION_WORKSTATION_NAME_COLUMN:
1260            result = String.class;
1270            break;
1280        case SESSION_DESCRIPTION_COLUMN:
1290            result = String.class;
1300            break;
1310        case SESSION_START_TIME_COLUMN:
1320            result = Date.class;
1330            break;
1340        case SESSION_END_TIME_COLUMN:
1350            result = Date.class;
1360            break;
1370        case SESSION_SERVICE_COLUMN:
1380            result = String.class;
1390            break;
1400        case SESSION_FINISHED_COLUMN:
1410            result = Boolean.class;
1420            break;
1430        }
1440        return result;
1450    }
146  
147     /*
148      * Don't need to implement this method unless your table's editable.
149      */
1500    public boolean isCellEditable(int row, int column) {
1510        if (row < 0 || column < 0)
1520            return false;
1530        // Note that the data/cell address is constant,
1540        // no matter where the cell appears onscreen.
1550        boolean result = false;
1560        switch (column) {
1570        case SESSION_ID_COLUMN:
1580            result = false;
1590            break;
1600        case SESSION_USER_NICKNAME_COLUMN:
1610            result = false;
1620            break;
1630        case SESSION_WORKSTATION_NAME_COLUMN:
1640            result = false;
1650            break;
1660        case SESSION_DESCRIPTION_COLUMN:
1670            result = true;
1680            break;
1690        case SESSION_START_TIME_COLUMN:
1700            result = false;
1710            break;
1720        case SESSION_END_TIME_COLUMN:
1730            result = false;
1740            break;
1750        case SESSION_SERVICE_COLUMN:
1760            result = false;
1770            break;
1780        case SESSION_FINISHED_COLUMN:
1790            result = false;
1800            break;
1810        }
1820        return result;
1830    }
184  
185     /*
186      * Don't need to implement this method unless your table's data can change.
187      */
1880    public void setValueAt(Object value, int row, int column) {
1890        if (row < 0 || column < 0)
1900            return;
1910        Session[] session = InternetCafeManager.getInstance().getSession();
1920        switch (column) {
1930        case SESSION_ID_COLUMN:
1940            break;
1950        case SESSION_USER_NICKNAME_COLUMN:
1960            break;
1970        case SESSION_WORKSTATION_NAME_COLUMN:
1980            break;
1990        case SESSION_DESCRIPTION_COLUMN:
2000            session[row].setDescription((String) value);
2010            break;
2020        case SESSION_START_TIME_COLUMN:
2030            break;
2040        case SESSION_END_TIME_COLUMN:
2050            break;
2060        case SESSION_SERVICE_COLUMN:
2070            break;
2080        case SESSION_FINISHED_COLUMN:
209             break;
2100        }
2110        fireTableCellUpdated(row, column);
2120    }
2130 
214     /*
215      * (non-Javadoc)
216      *
217      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
218      */
2190    public void update(Observable observable, Object changedObject) {
2200        if (changedObject instanceof Session)
2210            this.fireTableDataChanged();
2220    }
2230 
224     /**
225      * @param sessions
226      */
2270    public void setData(Session[] sessions) {
2280        data = sessions;
2290    }
2300}

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.