James Moger
2012-10-22 eba89539a29deba954035056437279088c3e047b
commit | author | age
f08aab 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.TeamModel;
25
26 /**
27  * Table model of a list of teams.
28  * 
29  * @author James Moger
30  * 
31  */
32 public class TeamsTableModel extends AbstractTableModel {
33
34     private static final long serialVersionUID = 1L;
35
36     List<TeamModel> list;
37
38     enum Columns {
39         Name, Members, Repositories;
40
41         @Override
42         public String toString() {
43             return name().replace('_', ' ');
44         }
45     }
46
47     public TeamsTableModel() {
48         this(new ArrayList<TeamModel>());
49     }
50
51     public TeamsTableModel(List<TeamModel> teams) {
52         this.list = teams;
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         case Members:
73             return Translation.get("gb.teamMembers");
74         case Repositories:
75             return Translation.get("gb.repositories");
76         }
77         return "";
78     }
79
80     /**
81      * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
82      * 
83      * @param columnIndex
84      *            the column being queried
85      * @return the Object.class
86      */
87     public Class<?> getColumnClass(int columnIndex) {
88         return String.class;
89     }
90
91     @Override
92     public Object getValueAt(int rowIndex, int columnIndex) {
93         TeamModel model = list.get(rowIndex);
94         Columns col = Columns.values()[columnIndex];
95         switch (col) {
96         case Name:
97             return model.name;
98         case Members:
99             return model.users.size() == 0 ? "" : String.valueOf(model.users.size());
100         case Repositories:
101             return model.repositories.size() == 0 ? "" : String.valueOf(model.repositories.size());
102         }
103         return null;
104     }
105 }