Coverage details for ui.table.model.ServerWorkstationTableModel

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 ServerWorkstationTableModel 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"), Messages.getString("common.role") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
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  
58     public static final int WORKSTATION_ROLE_COLUMN = 8;
59  
600    public ServerWorkstationTableModel() {
610        super();
620        NetworkManager.getInstance().addObserver(this);
630    }
640 
650    public int getColumnCount() {
660        return columnNames.length;
670    }
68  
690    public int getRowCount() {
700        return NetworkManager.getInstance().getNetwork().getServer().length;
710    }
72  
730    public String getColumnName(int column) {
740        return columnNames[column];
750    }
76  
770    public Object getValueAt(int row, int column) {
780        if (row < 0 || column < 0)
790            return null;
800        Workstation[] server = NetworkManager.getInstance().getNetwork()
810                .getServer();
820        Object result = null;
830        switch (column) {
840        case WORKSTATION_ID_COLUMN:
850            result = server[row].getId();
860            break;
870        case WORKSTATION_NAME_COLUMN:
880            result = server[row].getName();
890            break;
900        case WORKSTATION_LOCATION_COLUMN:
910            result = server[row].getLocation();
920            break;
930        case WORKSTATION_DESCRIPTION_COLUMN:
940            result = server[row].getDescription();
950            break;
960        case WORKSTATION_TYPE_COLUMN:
970            result = server[row].getType();
980            break;
990        case WORKSTATION_ADDRESS_COLUMN:
1000            result = server[row].getAddress().getHostAddress();
1010            break;
1020        case WORKSTATION_PORT_COLUMN:
1030            result = server[row].getPort();
1040            break;
1050        case WORKSTATION_IN_USE_COLUMN:
1060            result = server[row].isInUse();
1070            break;
1080        case WORKSTATION_ROLE_COLUMN:
109             // result = client[row].getRole();
110             break;
1110        }
1120        return result;
1130    }
114  
115     @SuppressWarnings("unchecked") //$NON-NLS-1$
1160    public Class getColumnClass(int column) {
1170        Class result = null;
1180        switch (column) {
1190        case WORKSTATION_ID_COLUMN:
1200            result = Integer.class;
1210            break;
1220        case WORKSTATION_NAME_COLUMN:
1230            result = String.class;
1240            break;
1250        case WORKSTATION_LOCATION_COLUMN:
1260            result = String.class;
1270            break;
1280        case WORKSTATION_DESCRIPTION_COLUMN:
1290            result = String.class;
1300            break;
1310        case WORKSTATION_TYPE_COLUMN:
1320            result = String.class;
1330            break;
1340        case WORKSTATION_ADDRESS_COLUMN:
1350            result = InetAddress.class;
1360            break;
1370        case WORKSTATION_PORT_COLUMN:
1380            result = Integer.class;
1390            break;
1400        case WORKSTATION_IN_USE_COLUMN:
1410            result = Boolean.class;
1420            break;
1430        case WORKSTATION_ROLE_COLUMN:
1440            result = String.class;
1450            break;
1460        }
1470        return result;
1480    }
149  
150     /*
151      * Don't need to implement this method unless your table's editable.
152      */
1530    public boolean isCellEditable(int row, int column) {
1540        if (row < 0 || column < 0)
1550            return false;
1560        // Note that the data/cell address is constant,
1570        // no matter where the cell appears onscreen.
1580        boolean result = false;
1590        switch (column) {
1600        case WORKSTATION_ID_COLUMN:
1610            result = false;
1620            break;
1630        case WORKSTATION_NAME_COLUMN:
1640            result = true;
1650            break;
1660        case WORKSTATION_LOCATION_COLUMN:
1670            result = true;
1680            break;
1690        case WORKSTATION_DESCRIPTION_COLUMN:
1700            result = true;
1710            break;
1720        case WORKSTATION_TYPE_COLUMN:
1730            result = true;
1740            break;
1750        case WORKSTATION_ADDRESS_COLUMN:
1760            result = false;
1770            break;
1780        case WORKSTATION_PORT_COLUMN:
1790            result = true;
1800            break;
1810        case WORKSTATION_IN_USE_COLUMN:
1820            result = false;
1830            break;
1840        case WORKSTATION_ROLE_COLUMN:
1850            result = true;
1860            break;
1870        }
1880        return result;
1890    }
190  
191     /*
192      * Don't need to implement this method unless your table's data can change.
193      */
1940    public void setValueAt(Object value, int row, int column) {
1950        if (row < 0 || column < 0)
1960            return;
1970        Workstation[] server = NetworkManager.getInstance().getNetwork()
1980                .getServer();
1990        switch (column) {
2000        case WORKSTATION_ID_COLUMN:
2010            break;
2020        case WORKSTATION_NAME_COLUMN:
2030            server[row].setName(value.toString());
2040            break;
2050        case WORKSTATION_LOCATION_COLUMN:
2060            server[row].setLocation(value.toString());
2070            break;
2080        case WORKSTATION_DESCRIPTION_COLUMN:
2090            server[row].setDescription(value.toString());
2100            break;
2110        case WORKSTATION_TYPE_COLUMN:
2120            server[row].setType(value.toString());
2130            break;
2140        case WORKSTATION_ADDRESS_COLUMN:
2150            break;
2160        case WORKSTATION_PORT_COLUMN:
2170            server[row].setPort(Integer.parseInt(value.toString()));
2180            break;
2190        case WORKSTATION_IN_USE_COLUMN:
2200            break;
2210        case WORKSTATION_ROLE_COLUMN:
222             break;
2230        }
2240        fireTableCellUpdated(row, column);
2250    }
2260 
227     /*
228      * (non-Javadoc)
229      *
230      * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
231      */
2320    public void update(Observable observable, Object changedObject) {
2330        if (changedObject instanceof Workstation)
2340            this.fireTableDataChanged();
2350    }
2360 
237 }

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.