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;
21  
22  import javax.swing.DefaultCellEditor;
23  import javax.swing.JComboBox;
24  import javax.swing.JTable;
25  import javax.swing.ListSelectionModel;
26  import javax.swing.table.TableColumn;
27  
28  import ui.table.model.UserTableModel;
29  import base.user.UserCredential;
30  import base.user.UserGender;
31  
32  @SuppressWarnings("serial") //$NON-NLS-1$
33  public class UserTable extends JTable {
34  	/***
35  	 * @param userTableSorter
36  	 */
37  	public UserTable(TableSorter userTableSorter) {
38  		super(userTableSorter);
39  		initialize();
40  	}
41  
42  	protected void initialize() {
43  		this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
44  		TableColumn idColumn = this.getColumnModel().getColumn(
45  				UserTableModel.USER_ID_COLUMN);
46  		idColumn.setPreferredWidth(30);
47  		idColumn.setMaxWidth(60);
48  
49  		TableColumn genderColumn = this.getColumnModel().getColumn(
50  				UserTableModel.USER_GENDER_COLUMN);
51  		DefaultCellEditor genderCellEditor = new DefaultCellEditor(
52  				getUserGenderComboBox());
53  		genderCellEditor.setClickCountToStart(2);
54  		genderColumn.setCellEditor(genderCellEditor);
55  		genderColumn.setPreferredWidth(30);
56  
57  		TableColumn credentialColumn = this.getColumnModel().getColumn(
58  				UserTableModel.USER_CREDENTIAL_COLUMN);
59  		DefaultCellEditor credentialCellEditor = new DefaultCellEditor(
60  				getUserCredentialComboBox());
61  		credentialCellEditor.setClickCountToStart(2);
62  		credentialColumn.setCellEditor(credentialCellEditor);
63  		credentialColumn.setPreferredWidth(40);
64  	}
65  
66  	private JComboBox getUserGenderComboBox() {
67  		JComboBox comboBox = new JComboBox();
68  		for (int i = 0; i < UserGender.USER_GENDER.length; i++)
69  			comboBox.addItem(UserGender.USER_GENDER[i]);
70  		return comboBox;
71  	}
72  
73  	private JComboBox getUserCredentialComboBox() {
74  		JComboBox comboBox = new JComboBox();
75  		for (int i = 0; i < UserCredential.USER_CREDENTIAL.length; i++)
76  			comboBox.addItem(UserCredential.USER_CREDENTIAL[i]);
77  		return comboBox;
78  	}
79  
80  }