James Moger
2012-02-16 3cc6e2de29a0fa33dd585e938e1614a6dd5f9755
commit | author | age
17820f 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.FeedModel;
25
26 /**
27  * Table model of a list of available feeds.
28  * 
29  * @author James Moger
30  * 
31  */
32 public class FeedsTableModel extends AbstractTableModel {
33
34     private static final long serialVersionUID = 1L;
35
36     List<FeedModel> list;
37
38     enum Columns {
38688b 39         Subscribed, Repository, Branch;
17820f 40
JM 41         @Override
42         public String toString() {
43             return name().replace('_', ' ');
44         }
45     }
46
47     public FeedsTableModel() {
48         this(new ArrayList<FeedModel>());
49     }
50
51     public FeedsTableModel(List<FeedModel> feeds) {
52         this.list = feeds;
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 Repository:
71             return Translation.get("gb.repository");
72         case Branch:
73             return Translation.get("gb.branch");
74         }
75         return "";
76     }
77
78     /**
79      * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
80      * 
81      * @param columnIndex
82      *            the column being queried
83      * @return the Object.class
84      */
85     public Class<?> getColumnClass(int columnIndex) {
86         Columns col = Columns.values()[columnIndex];
87         switch (col) {
88         case Subscribed:
89             return Boolean.class;
90         }
91         return String.class;
92     }
93
94     @Override
95     public boolean isCellEditable(int rowIndex, int columnIndex) {
96         Columns col = Columns.values()[columnIndex];
97         switch (col) {
98         case Subscribed:
99             return true;
100         }
101         return false;
102     }
103
104     @Override
105     public Object getValueAt(int rowIndex, int columnIndex) {
106         FeedModel model = list.get(rowIndex);
107         Columns col = Columns.values()[columnIndex];
108         switch (col) {
109         case Repository:
110             return model.repository;
111         case Branch:
112             return model.branch;
113         case Subscribed:
114             return model.subscribed;
115         }
116         return null;
117     }
118
119     public FeedModel get(int modelRow) {
120         return list.get(modelRow);
121     }
122 }