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