Line | Hits | Source |
---|---|---|
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.service.Service; | |
30 | import base.service.ServiceRateType; | |
31 | ||
32 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
33 | public class ServiceTableModel extends AbstractTableModel implements Observer { | |
34 | 0 | |
35 | 0 | String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.description"), Messages.getString("common.ratetype"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
36 | 0 | Messages.getString("common.baserate"), Messages.getString("common.mindurationinminute"), Messages.getString("common.maxdurationinminute") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
37 | 0 | |
38 | public static final int SERVICE_ID_COLUMN = 0; | |
39 | ||
40 | public static final int SERVICE_NAME_COLUMN = 1; | |
41 | ||
42 | public static final int SERVICE_DESCRIPTION_COLUMN = 2; | |
43 | ||
44 | public static final int SERVICE_RATE_TYPE_COLUMN = 3; | |
45 | ||
46 | public static final int SERVICE_BASE_RATE_COLUMN = 4; | |
47 | ||
48 | public static final int SERVICE_MIN_DURATION_IN_MINUTE_COLUMN = 5; | |
49 | ||
50 | public static final int SERVICE_MAX_DURATION_IN_MINUTE_COLUMN = 6; | |
51 | ||
52 | 0 | public ServiceTableModel() { |
53 | 0 | super(); |
54 | 0 | InternetCafeManager.getInstance().addObserver(this); |
55 | 0 | } |
56 | 0 | |
57 | 0 | public int getColumnCount() { |
58 | 0 | return columnNames.length; |
59 | 0 | } |
60 | ||
61 | 0 | public int getRowCount() { |
62 | 0 | return InternetCafeManager.getInstance().getService().length; |
63 | 0 | } |
64 | ||
65 | 0 | public String getColumnName(int col) { |
66 | 0 | return columnNames[col]; |
67 | 0 | } |
68 | ||
69 | 0 | public Object getValueAt(int row, int column) { |
70 | 0 | if (row < 0 || column < 0) |
71 | 0 | return null; |
72 | 0 | Service[] service = InternetCafeManager.getInstance().getService(); |
73 | 0 | Object result = null; |
74 | 0 | switch (column) { |
75 | 0 | case SERVICE_ID_COLUMN: |
76 | 0 | result = service[row].getId(); |
77 | 0 | break; |
78 | 0 | case SERVICE_NAME_COLUMN: |
79 | 0 | result = service[row].getName(); |
80 | 0 | break; |
81 | 0 | case SERVICE_DESCRIPTION_COLUMN: |
82 | 0 | result = service[row].getDescription(); |
83 | 0 | break; |
84 | 0 | case SERVICE_RATE_TYPE_COLUMN: |
85 | 0 | result = service[row].getRateType(); |
86 | 0 | break; |
87 | 0 | case SERVICE_BASE_RATE_COLUMN: |
88 | 0 | result = service[row].getBaseRate(); |
89 | 0 | break; |
90 | 0 | case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN: |
91 | 0 | result = service[row].getMinDurationInMinute(); |
92 | 0 | break; |
93 | 0 | case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN: |
94 | 0 | result = service[row].getMaxDurationInMinute(); |
95 | 0 | break; |
96 | 0 | } |
97 | 0 | return result; |
98 | 0 | } |
99 | ||
100 | @SuppressWarnings("unchecked") //$NON-NLS-1$ | |
101 | 0 | public Class getColumnClass(int column) { |
102 | 0 | if (column < 0) |
103 | 0 | return null; |
104 | 0 | Class result = null; |
105 | 0 | switch (column) { |
106 | 0 | case SERVICE_ID_COLUMN: |
107 | 0 | result = Integer.class; |
108 | 0 | break; |
109 | 0 | case SERVICE_NAME_COLUMN: |
110 | 0 | result = String.class; |
111 | 0 | break; |
112 | 0 | case SERVICE_DESCRIPTION_COLUMN: |
113 | 0 | result = String.class; |
114 | 0 | break; |
115 | 0 | case SERVICE_RATE_TYPE_COLUMN: |
116 | 0 | result = ServiceRateType.class; |
117 | 0 | break; |
118 | 0 | case SERVICE_BASE_RATE_COLUMN:// Should be Double but with string will |
119 | // be displayed the double's dot | |
120 | 0 | // notation |
121 | 0 | result = String.class; |
122 | 0 | break; |
123 | 0 | case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN: |
124 | 0 | result = Integer.class; |
125 | 0 | break; |
126 | 0 | case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN: |
127 | 0 | result = Integer.class; |
128 | 0 | break; |
129 | 0 | } |
130 | 0 | return result; |
131 | 0 | } |
132 | ||
133 | /* | |
134 | * Don't need to implement this method unless your table's editable. | |
135 | */ | |
136 | 0 | public boolean isCellEditable(int row, int column) { |
137 | 0 | if (row < 0 || column < 0) |
138 | 0 | return false; |
139 | 0 | // Note that the data/cell address is constant, |
140 | 0 | // no matter where the cell appears onscreen. |
141 | 0 | boolean result = false; |
142 | 0 | switch (column) { |
143 | 0 | case SERVICE_ID_COLUMN: |
144 | 0 | result = false; |
145 | 0 | break; |
146 | 0 | case SERVICE_NAME_COLUMN: |
147 | 0 | result = true; |
148 | 0 | break; |
149 | 0 | case SERVICE_DESCRIPTION_COLUMN: |
150 | 0 | result = true; |
151 | 0 | break; |
152 | 0 | case SERVICE_RATE_TYPE_COLUMN: |
153 | 0 | result = true; |
154 | 0 | break; |
155 | 0 | case SERVICE_BASE_RATE_COLUMN: |
156 | 0 | result = false; |
157 | 0 | break; |
158 | 0 | case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN: |
159 | 0 | result = true; |
160 | 0 | break; |
161 | 0 | case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN: |
162 | 0 | result = true; |
163 | 0 | break; |
164 | 0 | } |
165 | 0 | return result; |
166 | 0 | } |
167 | ||
168 | /* | |
169 | * Don't need to implement this method unless your table's data can change. | |
170 | */ | |
171 | 0 | public void setValueAt(Object value, int row, int column) { |
172 | 0 | if (row < 0 || column < 0) |
173 | 0 | return; |
174 | 0 | @SuppressWarnings("unused") //$NON-NLS-1$ |
175 | 0 | Service[] service = InternetCafeManager.getInstance().getService(); |
176 | 0 | switch (column) { |
177 | 0 | case SERVICE_ID_COLUMN: |
178 | 0 | break; |
179 | 0 | case SERVICE_NAME_COLUMN: |
180 | 0 | service[row].setName((String) value); |
181 | 0 | break; |
182 | 0 | case SERVICE_DESCRIPTION_COLUMN: |
183 | 0 | service[row].setDescription((String) value); |
184 | 0 | break; |
185 | 0 | case SERVICE_RATE_TYPE_COLUMN: |
186 | 0 | service[row].setRateType((String) value); |
187 | 0 | break; |
188 | 0 | case SERVICE_BASE_RATE_COLUMN: |
189 | 0 | service[row].setBaseRate(Double.parseDouble(value.toString())); |
190 | 0 | break; |
191 | 0 | case SERVICE_MIN_DURATION_IN_MINUTE_COLUMN: |
192 | 0 | service[row].setMinDurationInMinute(Integer.parseInt(value |
193 | 0 | .toString())); |
194 | 0 | break; |
195 | 0 | case SERVICE_MAX_DURATION_IN_MINUTE_COLUMN: |
196 | 0 | service[row].setMaxDurationInMinute(Integer.parseInt(value |
197 | 0 | .toString())); |
198 | 0 | break; |
199 | 0 | } |
200 | 0 | fireTableCellUpdated(row, column); |
201 | 0 | } |
202 | 0 | |
203 | /* | |
204 | * (non-Javadoc) | |
205 | * | |
206 | * @see java.util.Observer#update(java.util.Observable, java.lang.Object) | |
207 | */ | |
208 | 0 | public void update(Observable observable, Object changedObject) { |
209 | 0 | if (changedObject instanceof Service) |
210 | 0 | this.fireTableDataChanged(); |
211 | 0 | } |
212 | 0 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |