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.backup.Backup; | |
30 | ||
31 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
32 | public class BackupTableModel extends AbstractTableModel implements Observer { | |
33 | 0 | |
34 | 0 | String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.date"), Messages.getString("common.description"), Messages.getString("common.size")+" "+Messages.getString("common.unit.kylobyte") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
35 | 0 | |
36 | public static final int BACKUP_ID_COLUMN = 0; | |
37 | ||
38 | public static final int BACKUP_NAME_COLUMN = 1; | |
39 | ||
40 | public static final int BACKUP_DATE_COLUMN = 2; | |
41 | ||
42 | public static final int BACKUP_DESCRIPTION_COLUMN = 3; | |
43 | ||
44 | public static final int BACKUP_SIZE_COLUMN = 4; | |
45 | ||
46 | 0 | public BackupTableModel() { |
47 | 0 | super(); |
48 | 0 | InternetCafeManager.getInstance().addObserver(this); |
49 | 0 | } |
50 | 0 | |
51 | 0 | public int getColumnCount() { |
52 | 0 | return columnNames.length; |
53 | 0 | } |
54 | ||
55 | 0 | public int getRowCount() { |
56 | 0 | return InternetCafeManager.getInstance().getBackup().length; |
57 | 0 | } |
58 | ||
59 | 0 | public String getColumnName(int col) { |
60 | 0 | return columnNames[col]; |
61 | 0 | } |
62 | ||
63 | 0 | public Object getValueAt(int row, int column) { |
64 | 0 | if (row < 0 || column < 0) |
65 | 0 | return null; |
66 | 0 | Backup[] backup = InternetCafeManager.getInstance().getBackup(); |
67 | 0 | Object result = null; |
68 | 0 | switch (column) { |
69 | 0 | case BACKUP_ID_COLUMN: |
70 | 0 | result = backup[row].getId(); |
71 | 0 | break; |
72 | 0 | case BACKUP_NAME_COLUMN: |
73 | 0 | result = backup[row].getName(); |
74 | 0 | break; |
75 | 0 | case BACKUP_DATE_COLUMN: |
76 | 0 | result = backup[row].getDate().toString(); |
77 | 0 | break; |
78 | 0 | case BACKUP_DESCRIPTION_COLUMN: |
79 | 0 | result = backup[row].getDescription(); |
80 | 0 | break; |
81 | 0 | case BACKUP_SIZE_COLUMN: |
82 | 0 | result = backup[row].getSize() > 0 ? backup[row].getSize() |
83 | 0 | : Messages.getString("backuptablemodel.message1"); //$NON-NLS-1$ |
84 | 0 | break; |
85 | 0 | } |
86 | 0 | return result; |
87 | 0 | } |
88 | ||
89 | @SuppressWarnings("unchecked") //$NON-NLS-1$ | |
90 | 0 | public Class getColumnClass(int column) { |
91 | 0 | if (column < 0) |
92 | 0 | return null; |
93 | 0 | Class result = null; |
94 | 0 | switch (column) { |
95 | 0 | case BACKUP_ID_COLUMN: |
96 | 0 | result = Integer.class; |
97 | 0 | break; |
98 | 0 | case BACKUP_NAME_COLUMN: |
99 | 0 | result = String.class; |
100 | 0 | break; |
101 | 0 | case BACKUP_DATE_COLUMN: |
102 | 0 | result = String.class; |
103 | 0 | break; |
104 | 0 | case BACKUP_DESCRIPTION_COLUMN: |
105 | 0 | result = String.class; |
106 | 0 | break; |
107 | 0 | case BACKUP_SIZE_COLUMN: |
108 | 0 | result = Long.class; |
109 | 0 | break; |
110 | 0 | } |
111 | 0 | return result; |
112 | 0 | } |
113 | ||
114 | /* | |
115 | * Don't need to implement this method unless your table's editable. | |
116 | */ | |
117 | 0 | public boolean isCellEditable(int row, int column) { |
118 | 0 | if (row < 0 || column < 0) |
119 | 0 | return false; |
120 | 0 | // Note that the data/cell address is constant, |
121 | 0 | // no matter where the cell appears onscreen. |
122 | 0 | boolean result = false; |
123 | 0 | switch (column) { |
124 | 0 | case BACKUP_ID_COLUMN: |
125 | 0 | result = false; |
126 | 0 | break; |
127 | 0 | case BACKUP_NAME_COLUMN: |
128 | 0 | result = false; |
129 | 0 | break; |
130 | 0 | case BACKUP_DATE_COLUMN: |
131 | 0 | result = false; |
132 | 0 | break; |
133 | 0 | case BACKUP_DESCRIPTION_COLUMN: |
134 | 0 | result = true; |
135 | 0 | break; |
136 | 0 | case BACKUP_SIZE_COLUMN: |
137 | 0 | result = false; |
138 | 0 | break; |
139 | 0 | } |
140 | 0 | return result; |
141 | 0 | } |
142 | ||
143 | /* | |
144 | * Don't need to implement this method unless your table's data can change. | |
145 | */ | |
146 | 0 | public void setValueAt(Object value, int row, int column) { |
147 | 0 | if (row < 0 || column < 0) |
148 | 0 | return; |
149 | 0 | fireTableCellUpdated(row, column); |
150 | 0 | } |
151 | 0 | |
152 | /* | |
153 | * (non-Javadoc) | |
154 | * | |
155 | * @see java.util.Observer#update(java.util.Observable, java.lang.Object) | |
156 | */ | |
157 | 0 | public void update(Observable observable, Object changedObject) { |
158 | 0 | if (changedObject instanceof Backup) |
159 | 0 | this.fireTableDataChanged(); |
160 | 0 | } |
161 | 0 | |
162 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |