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  package ui.table.model;
21  
22  import javax.swing.table.AbstractTableModel;
23  
24  import ui.Messages;
25  import base.InternetCafeManager;
26  import base.user.User;
27  
28  @SuppressWarnings("serial") //$NON-NLS-1$
29  public class ReducedUserTableModel extends AbstractTableModel {
30  
31  	String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.surname"), Messages.getString("common.nickname"), }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
32  
33  	public static final int USER_ID_COLUMN = 0;
34  
35  	public static final int USER_NAME_COLUMN = 1;
36  
37  	public static final int USER_SURNAME_COLUMN = 2;
38  
39  	public static final int USER_NICKNAME_COLUMN = 3;
40  
41  	public ReducedUserTableModel() {
42  		super();
43  	}
44  
45  	public int getColumnCount() {
46  		return columnNames.length;
47  	}
48  
49  	public int getRowCount() {
50  		return InternetCafeManager.getInstance().getUser().length;
51  	}
52  
53  	public String getColumnName(int col) {
54  		return columnNames[col];
55  	}
56  
57  	public Object getValueAt(int row, int column) {
58  		if (row < 0 || column < 0)
59  			return null;
60  		User[] user = InternetCafeManager.getInstance().getUser();
61  		Object result = null;
62  		switch (column) {
63  		case USER_ID_COLUMN:// Id
64  			result = user[row].getId();
65  			break;
66  		case USER_NAME_COLUMN:// Name
67  			result = user[row].getName();
68  			break;
69  		case USER_SURNAME_COLUMN:// Surname
70  			result = user[row].getSurname();
71  			break;
72  		case USER_NICKNAME_COLUMN:// Nickname
73  			result = user[row].getNickname();
74  			break;
75  		}
76  		return result;
77  	}
78  
79  	@SuppressWarnings("unchecked") //$NON-NLS-1$
80  	public Class getColumnClass(int column) {
81  		if (column < 0)
82  			return null;
83  		Class result = null;
84  		switch (column) {
85  		case USER_ID_COLUMN:// Id
86  			result = Integer.class;
87  			break;
88  		case USER_NAME_COLUMN:// Name
89  			result = String.class;
90  			break;
91  		case USER_SURNAME_COLUMN:// Surname
92  			result = String.class;
93  			break;
94  		case USER_NICKNAME_COLUMN:// Nickname
95  			result = String.class;
96  			break;
97  		}
98  		return result;
99  	}
100 
101 	/*
102 	 * Don't need to implement this method unless your table's editable.
103 	 */
104 	public boolean isCellEditable(int row, int column) {
105 		if (row < 0 || column < 0)
106 			return false;
107 		// Note that the data/cell address is constant,
108 		// no matter where the cell appears onscreen.
109 		boolean result = false;
110 		switch (column) {
111 		case USER_ID_COLUMN:// Id
112 			result = false;
113 			break;
114 		case USER_NAME_COLUMN:// Name
115 			result = false;
116 			break;
117 		case USER_SURNAME_COLUMN:// Surname
118 			result = false;
119 			break;
120 		case USER_NICKNAME_COLUMN:// Nickname
121 			result = false;
122 			break;
123 		}
124 		return result;
125 	}
126 }