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 javax.swing.table.AbstractTableModel;
23
24 import ui.Messages;
25 import base.network.NetworkManager;
26 import base.network.Workstation;
27
28 @SuppressWarnings("serial")
29 public class ReducedClientWorkstationTableModel extends AbstractTableModel {
30
31
32
33
34 private String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.location"), Messages.getString("common.type"), Messages.getString("common.inuse") };
35
36 public static final int WORKSTATION_ID_COLUMN = 0;
37
38 public static final int WORKSTATION_NAME_COLUMN = 1;
39
40 public static final int WORKSTATION_LOCATION_COLUMN = 2;
41
42 public static final int WORKSTATION_TYPE_COLUMN = 3;
43
44 public static final int WORKSTATION_IN_USE_COLUMN = 4;
45
46 public ReducedClientWorkstationTableModel() {
47 super();
48 }
49
50 public int getColumnCount() {
51 return columnNames.length;
52 }
53
54 public int getRowCount() {
55 return NetworkManager.getInstance().getNetwork().getClient().length;
56 }
57
58 public String getColumnName(int column) {
59 return columnNames[column];
60 }
61
62 public Object getValueAt(int row, int column) {
63 if (row < 0 || column < 0)
64 return null;
65 Workstation[] client = NetworkManager.getInstance().getNetwork()
66 .getClient();
67 Object result = null;
68 switch (column) {
69 case WORKSTATION_ID_COLUMN:
70 result = client[row].getId();
71 break;
72 case WORKSTATION_NAME_COLUMN:
73 result = client[row].getName();
74 break;
75 case WORKSTATION_LOCATION_COLUMN:
76 result = client[row].getLocation();
77 break;
78 case WORKSTATION_TYPE_COLUMN:
79 result = client[row].getType();
80 break;
81 case WORKSTATION_IN_USE_COLUMN:
82 result = client[row].isInUse();
83 break;
84 }
85 return result;
86 }
87
88 @SuppressWarnings("unchecked")
89 public Class getColumnClass(int column) {
90 Class result = null;
91 switch (column) {
92 case WORKSTATION_ID_COLUMN:
93 result = Integer.class;
94 break;
95 case WORKSTATION_NAME_COLUMN:
96 result = String.class;
97 break;
98 case WORKSTATION_LOCATION_COLUMN:
99 result = String.class;
100 break;
101 case WORKSTATION_TYPE_COLUMN:
102 result = String.class;
103 break;
104 case WORKSTATION_IN_USE_COLUMN:
105 result = Boolean.class;
106 break;
107 }
108 return result;
109 }
110
111
112
113
114 public boolean isCellEditable(int row, int column) {
115 if (row < 0 || column < 0)
116 return false;
117
118
119 boolean result = false;
120 switch (column) {
121 case WORKSTATION_ID_COLUMN:
122 result = false;
123 break;
124 case WORKSTATION_NAME_COLUMN:
125 result = false;
126 break;
127 case WORKSTATION_LOCATION_COLUMN:
128 result = false;
129 break;
130 case WORKSTATION_TYPE_COLUMN:
131 result = false;
132 break;
133 case WORKSTATION_IN_USE_COLUMN:
134 result = false;
135 break;
136 }
137 return result;
138 }
139 }