Coverage details for ui.table.model.ClientWorkstationTableModel

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.net.InetAddress;
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.network.NetworkManager;
30 import base.network.Workstation;
31  
32 @SuppressWarnings("serial") //$NON-NLS-1$
33 public class ClientWorkstationTableModel extends AbstractTableModel implements
34         Observer {
35     /*
36      * private String name; private String description; private WorkstationType
37      * type; private InetAddress address; private boolean inUse = false;
380     */
390    private String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.location"), Messages.getString("common.description"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
400            Messages.getString("common.type"), Messages.getString("common.address"), Messages.getString("common.port"), Messages.getString("common.inuse") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
410 
42     public static final int WORKSTATION_ID_COLUMN = 0;
43  
44     public static final int WORKSTATION_NAME_COLUMN = 1;
45  
46     public static final int WORKSTATION_LOCATION_COLUMN = 2;
47  
48     public static final int WORKSTATION_DESCRIPTION_COLUMN = 3;
49  
50     public static final int WORKSTATION_TYPE_COLUMN = 4;
51  
52     public static final int WORKSTATION_ADDRESS_COLUMN = 5;
53  
54     public static final int WORKSTATION_PORT_COLUMN = 6;
55  
56     public static final int WORKSTATION_IN_USE_COLUMN = 7;
57  
580    public ClientWorkstationTableModel() {
590        super();
600        NetworkManager.getInstance().addObserver(this);
610    }
620 
630    public int getColumnCount() {
640        return columnNames.length;
650    }
66  
670    public int getRowCount() {
680        return NetworkManager.getInstance().getNetwork().getClient().length;
690    }
70  
710    public String getColumnName(int column) {
720        return columnNames[column];
730    }
74  
750    public Object getValueAt(int row, int column) {
760        if (row < 0 || column < 0)
770            return null;
780        Workstation[] client = NetworkManager.getInstance().getNetwork()
790                .getClient();
800        Object result = null;
810        switch (column) {
820        case WORKSTATION_ID_COLUMN:
830            result = client[row].getId();
840            break;
850        case WORKSTATION_NAME_COLUMN:
860            result = client[row].getName();
870            break;
880        case WORKSTATION_LOCATION_COLUMN:
890            result = client[row].getLocation();
900            break;
910        case WORKSTATION_DESCRIPTION_COLUMN:
920            result = client[row].getDescription();
930            break;
940        case WORKSTATION_TYPE_COLUMN:
950            result = client[row].getType();
960            break;
970        case WORKSTATION_ADDRESS_COLUMN:
980            result = client[row].getAddress().getHostAddress();
990            break;
1000        case WORKSTATION_PORT_COLUMN:
1010            result = client[row].getPort();
1020            break;
1030        case WORKSTATION_IN_USE_COLUMN:
1040            result = client[row].isInUse();
1050            break;
1060        }
1070        return result;
1080    }
109  
110     @SuppressWarnings("unchecked") //$NON-NLS-1$
1110    public Class getColumnClass(int column) {
1120        Class result = null;
1130        switch (column) {
1140        case WORKSTATION_ID_COLUMN:
1150            result = Integer.class;
1160            break;
1170        case WORKSTATION_NAME_COLUMN:
1180            result = String.class;
1190            break;
1200        case WORKSTATION_LOCATION_COLUMN:
1210            result = String.class;
1220            break;
1230        case WORKSTATION_DESCRIPTION_COLUMN:
1240            result = String.class;
1250            break;
1260        case WORKSTATION_TYPE_COLUMN:
1270            result = String.class;
1280            break;
1290        case WORKSTATION_ADDRESS_COLUMN:
1300            result = InetAddress.class;
1310            break;
1320        case WORKSTATION_PORT_COLUMN:
1330            result = Integer.class;
1340            break;
1350        case WORKSTATION_IN_USE_COLUMN:
1360            result = Boolean.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 WORKSTATION_ID_COLUMN:
1530            result = false;
1540            break;
1550        case WORKSTATION_NAME_COLUMN:
1560            result = true;
1570            break;
1580        case WORKSTATION_LOCATION_COLUMN:
1590            result = true;
1600            break;
1610        case WORKSTATION_DESCRIPTION_COLUMN:
1620            result = true;
1630            break;
1640        case WORKSTATION_TYPE_COLUMN:
1650            result = true;
1660            break;
1670        case WORKSTATION_ADDRESS_COLUMN:
1680            result = false;
1690            break;
1700        case WORKSTATION_PORT_COLUMN:
1710            result = true;
1720            break;
1730        case WORKSTATION_IN_USE_COLUMN:
1740            result = false;
1750            break;
1760        }
1770        return result;
1780    }
179  
180     /*
181      * Don't need to implement this method unless your table's data can change.
182      */
1830    public void setValueAt(Object value, int row, int column) {
1840        if (row < 0 || column < 0)
1850            return;
1860        Workstation[] client = NetworkManager.getInstance().getNetwork()
1870                .getClient();
1880        switch (column) {
1890        case WORKSTATION_ID_COLUMN:
1900            break;
1910        case WORKSTATION_NAME_COLUMN:
1920            client[row].setName(value.toString());
1930            break;
1940        case WORKSTATION_LOCATION_COLUMN:
1950            client[row].setLocation(value.toString());
1960            break;
1970        case WORKSTATION_DESCRIPTION_COLUMN:
1980            client[row].setDescription(value.toString());
1990            break;
2000        case WORKSTATION_TYPE_COLUMN:
2010            client[row].setType(value.toString());
2020            break;
2030        case WORKSTATION_ADDRESS_COLUMN:
2040            break;
2050        case WORKSTATION_PORT_COLUMN:
2060            client[row].setPort(Integer.parseInt(value.toString()));
2070            break;
2080        case WORKSTATION_IN_USE_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 Workstation)
2210            this.fireTableDataChanged();
2220    }
2230 
224 }

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.