View Javadoc

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  
21  package base.jdbs.ui;
22  
23  import java.util.Date;
24  import java.util.Observable;
25  import java.util.Observer;
26  
27  import javax.swing.table.AbstractTableModel;
28  
29  import org.apache.log4j.Logger;
30  
31  import base.jdbs.BackupDescriptor;
32  import base.jdbs.ConfigurationManager;
33  import base.util.FileUtil;
34  
35  @SuppressWarnings("serial")
36  public class BackupDescriptorTableModel extends AbstractTableModel implements Observer {
37  	
38  	private static final transient Logger logger = Logger.getLogger(BackupDescriptorTableModel.class.getName());
39  
40  	private String[] columnNames = {"Id","Name","Space (Kb)","Creation","Expiration","CRC32","MD5","Security"};
41  
42  	public static final int BACKUP_ID_COLUMN = 0;
43  
44  	public static final int BACKUP_NAME_COLUMN = 1;
45  
46  	public static final int BACKUP_OCCUPIED_SPACE_COLUMN = 2;
47  
48  	public static final int BACKUP_CREATION_DATE_COLUMN = 3;
49  
50  	public static final int BACKUP_EXPIRATION_DATE_COLUMN = 4;
51  
52  	public static final int BACKUP_CRC32_COLUMN = 5;
53  
54  	public static final int BACKUP_MD5_COLUMN = 6;
55  
56  	public static final int BACKUP_SECURITY_LEVEL_COLUMN = 7;
57  
58  	public BackupDescriptorTableModel() {
59  		super();
60  		ConfigurationManager.getInstance().getRepository().addObserver(this);
61  	}
62  
63  	public int getColumnCount() {
64  		return columnNames.length;
65  	}
66  
67  	public int getRowCount() {
68  		return ConfigurationManager.getInstance().getRepository().getBackupDescriptor().length;
69  	}
70  
71  	public String getColumnName(int column) {
72  		return columnNames[column];
73  	}
74  
75  	public Object getValueAt(int row, int column) {
76  		if (row < 0 || column < 0)
77  			return null;
78  		Object result = null;
79  		BackupDescriptor backupDescriptor = ConfigurationManager.getInstance().getRepository().getBackupDescriptor()[row];
80  		switch (column) {
81  		case BACKUP_ID_COLUMN:
82  			result = backupDescriptor.getBackup().getGuId();
83  			break;
84  		case BACKUP_NAME_COLUMN:
85  			result = backupDescriptor.getBackup().getName();
86  			break;
87  		case BACKUP_OCCUPIED_SPACE_COLUMN:
88  			result = FileUtil.fileSizeInKB(backupDescriptor.getBackupFile());
89  			break;
90  		case BACKUP_CREATION_DATE_COLUMN:
91  			result = backupDescriptor.getBackup().getCreationDate();
92  			break;
93  		case BACKUP_EXPIRATION_DATE_COLUMN:
94  			result = backupDescriptor.getBackup().getExpirationDate();
95  			break;
96  		case BACKUP_CRC32_COLUMN:
97  			result = backupDescriptor.getCrc32ChecksumValue();
98  			break;
99  		case BACKUP_MD5_COLUMN:
100 			result = backupDescriptor.getMd5DigestValue();
101 			break;
102 		case BACKUP_SECURITY_LEVEL_COLUMN:
103 			result = backupDescriptor.getBackup().getSecurityLevel();
104 			break;
105 		}
106 		return result;
107 	}
108 
109 	@SuppressWarnings("unchecked")
110 	public Class getColumnClass(int column) {
111 		Class result = null;
112 		switch (column) {
113 		case BACKUP_ID_COLUMN:
114 			result = String.class;
115 			break;
116 		case BACKUP_NAME_COLUMN:
117 			result = String.class;
118 			break;
119 		case BACKUP_OCCUPIED_SPACE_COLUMN:
120 			result = Long.class;
121 			break;
122 		case BACKUP_CREATION_DATE_COLUMN:
123 			result = Date.class;
124 			break;
125 		case BACKUP_EXPIRATION_DATE_COLUMN:
126 			result = Date.class;
127 			break;
128 		case BACKUP_CRC32_COLUMN:
129 			result = String.class;
130 			break;
131 		case BACKUP_MD5_COLUMN:
132 			result = String.class;
133 			break;
134 		case BACKUP_SECURITY_LEVEL_COLUMN:
135 			result = String.class;
136 			break;
137 		}
138 		return result;
139 	}
140 
141 	public void update(Observable arg0, Object arg1) {
142 		this.fireTableDataChanged();
143 	}
144 }