James Moger
2012-10-22 eba89539a29deba954035056437279088c3e047b
commit | author | age
19c634 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.Date;
21 import java.util.List;
22
23 import javax.swing.table.AbstractTableModel;
24
25 import com.gitblit.models.RepositoryModel;
26
841651 27 /**
JM 28  * Table model of a list of repositories.
29  * 
30  * @author James Moger
31  * 
32  */
84c1d5 33 public class RepositoriesTableModel extends AbstractTableModel {
19c634 34
JM 35     private static final long serialVersionUID = 1L;
36
37     List<RepositoryModel> list;
38
39     enum Columns {
b7f591 40         Name, Description, Owner, Indicators, Last_Change, Size;
19c634 41
JM 42         @Override
43         public String toString() {
44             return name().replace('_', ' ');
45         }
46     }
47
84c1d5 48     public RepositoriesTableModel() {
841651 49         this(new ArrayList<RepositoryModel>());
JM 50     }
51
84c1d5 52     public RepositoriesTableModel(List<RepositoryModel> repositories) {
841651 53         this.list = repositories;
JM 54         Collections.sort(this.list);
19c634 55     }
JM 56
57     @Override
58     public int getRowCount() {
841651 59         return list.size();
19c634 60     }
JM 61
62     @Override
63     public int getColumnCount() {
64         return Columns.values().length;
65     }
66
67     @Override
68     public String getColumnName(int column) {
69         Columns col = Columns.values()[column];
b7f591 70         switch (col) {
JM 71         case Name:
72             return Translation.get("gb.name");
73         case Description:
74             return Translation.get("gb.description");
75         case Owner:
76             return Translation.get("gb.owner");
77         case Last_Change:
78             return Translation.get("gb.lastChange");
79         case Size:
80             return Translation.get("gb.size");
81         }
82         return "";
19c634 83     }
JM 84
85     /**
86      * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
87      * 
88      * @param columnIndex
89      *            the column being queried
90      * @return the Object.class
91      */
92     public Class<?> getColumnClass(int columnIndex) {
93         Columns col = Columns.values()[columnIndex];
94         switch (col) {
841651 95         case Name:
b7f591 96         case Indicators:
841651 97             return RepositoryModel.class;
19c634 98         case Last_Change:
JM 99             return Date.class;
100         }
101         return String.class;
102     }
103
104     @Override
105     public Object getValueAt(int rowIndex, int columnIndex) {
106         RepositoryModel model = list.get(rowIndex);
107         Columns col = Columns.values()[columnIndex];
108         switch (col) {
109         case Name:
841651 110             return model;
19c634 111         case Description:
JM 112             return model.description;
113         case Owner:
114             return model.owner;
b7f591 115         case Indicators:
841651 116             return model;
19c634 117         case Last_Change:
JM 118             return model.lastChange;
119         case Size:
fe3262 120             if (model.hasCommits) {
JM 121                 return model.size;
122             }
123             return "(empty)";
19c634 124         }
JM 125         return null;
126     }
127 }