commit | author | age
|
f14f76
|
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.Collections;
|
|
19 |
import java.util.Date;
|
|
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import javax.swing.table.AbstractTableModel;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Table model of a list of Gitblit server registrations.
|
|
26 |
*
|
|
27 |
* @author James Moger
|
|
28 |
*
|
|
29 |
*/
|
84c1d5
|
30 |
public class RegistrationsTableModel extends AbstractTableModel {
|
f14f76
|
31 |
|
JM |
32 |
private static final long serialVersionUID = 1L;
|
|
33 |
|
|
34 |
List<GitblitRegistration> list;
|
|
35 |
|
|
36 |
enum Columns {
|
|
37 |
Name, URL, Last_Login;
|
|
38 |
|
|
39 |
@Override
|
|
40 |
public String toString() {
|
|
41 |
return name().replace('_', ' ');
|
|
42 |
}
|
|
43 |
}
|
|
44 |
|
84c1d5
|
45 |
public RegistrationsTableModel(List<GitblitRegistration> list) {
|
f14f76
|
46 |
this.list = list;
|
JM |
47 |
Collections.sort(this.list);
|
|
48 |
}
|
|
49 |
|
|
50 |
@Override
|
|
51 |
public int getRowCount() {
|
|
52 |
return list.size();
|
|
53 |
}
|
|
54 |
|
|
55 |
@Override
|
|
56 |
public int getColumnCount() {
|
|
57 |
return Columns.values().length;
|
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
public String getColumnName(int column) {
|
|
62 |
Columns col = Columns.values()[column];
|
|
63 |
switch (col) {
|
|
64 |
case Name:
|
|
65 |
return Translation.get("gb.name");
|
|
66 |
case URL:
|
|
67 |
return Translation.get("gb.url");
|
|
68 |
case Last_Login:
|
|
69 |
return Translation.get("gb.lastLogin");
|
|
70 |
}
|
|
71 |
return "";
|
|
72 |
}
|
|
73 |
|
|
74 |
/**
|
|
75 |
* Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
|
|
76 |
*
|
|
77 |
* @param columnIndex
|
|
78 |
* the column being queried
|
|
79 |
* @return the Object.class
|
|
80 |
*/
|
|
81 |
public Class<?> getColumnClass(int columnIndex) {
|
|
82 |
if (columnIndex == Columns.Last_Login.ordinal()) {
|
|
83 |
return Date.class;
|
|
84 |
}
|
|
85 |
return String.class;
|
|
86 |
}
|
|
87 |
|
|
88 |
@Override
|
|
89 |
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
90 |
GitblitRegistration model = list.get(rowIndex);
|
|
91 |
Columns col = Columns.values()[columnIndex];
|
|
92 |
switch (col) {
|
|
93 |
case Name:
|
|
94 |
return model.name;
|
|
95 |
case URL:
|
|
96 |
return model.url;
|
|
97 |
case Last_Login:
|
|
98 |
return model.lastLogin;
|
|
99 |
}
|
|
100 |
return null;
|
|
101 |
}
|
|
102 |
}
|