James Moger
2011-10-22 84c1d5c1527183a4e2830deab5b177d880914f1c
commit | author | age
4b430b 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.client;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import javax.swing.table.AbstractTableModel;
23
24 import com.gitblit.models.UserModel;
25
26 /**
27  * Table model of a list of users.
28  * 
29  * @author James Moger
30  * 
31  */
84c1d5 32 public class UsersTableModel extends AbstractTableModel {
4b430b 33
JM 34     private static final long serialVersionUID = 1L;
35
36     List<UserModel> list;
37
38     enum Columns {
39         Name;
40
41         @Override
42         public String toString() {
43             return name().replace('_', ' ');
44         }
45     }
46
84c1d5 47     public UsersTableModel() {
4b430b 48         this(new ArrayList<UserModel>());
JM 49     }
50
84c1d5 51     public UsersTableModel(List<UserModel> users) {
4b430b 52         this.list = users;
JM 53         Collections.sort(this.list);
54     }
55
56     @Override
57     public int getRowCount() {
58         return list.size();
59     }
60
61     @Override
62     public int getColumnCount() {
63         return Columns.values().length;
64     }
65
66     @Override
67     public String getColumnName(int column) {
68         Columns col = Columns.values()[column];
69         switch (col) {
70         case Name:
71             return Translation.get("gb.name");
72         }
73         return "";
74     }
75
76     /**
77      * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
78      * 
79      * @param columnIndex
80      *            the column being queried
81      * @return the Object.class
82      */
83     public Class<?> getColumnClass(int columnIndex) {
84         return String.class;
85     }
86
87     @Override
88     public Object getValueAt(int rowIndex, int columnIndex) {
89         UserModel model = list.get(rowIndex);
90         Columns col = Columns.values()[columnIndex];
91         switch (col) {
92         case Name:
93             return model.username;
94         }
95         return null;
96     }
97 }