source: AE/installer2/src/net/oni2/aeinstaller/gui/modtable/ModTableModel.java@ 598

Last change on this file since 598 was 593, checked in by alloc, 12 years ago
File size: 4.0 KB
RevLine 
[591]1package net.oni2.aeinstaller.gui.modtable;
2
3import java.util.ResourceBundle;
4import java.util.Vector;
5
6import javax.swing.table.AbstractTableModel;
7import javax.swing.table.TableColumn;
8
9import net.oni2.aeinstaller.backend.depot.DepotConfig;
10import net.oni2.aeinstaller.backend.depot.DepotManager;
11import net.oni2.aeinstaller.backend.depot.model.NodeMod;
12
13/**
14 * @author Christian Illy
15 */
16public class ModTableModel extends AbstractTableModel {
17
18 private static final long serialVersionUID = -8278155705802697354L;
19
20 private ResourceBundle bundle = ResourceBundle.getBundle(getClass()
21 .getName());
22
23 private Vector<NodeMod> items;
[593]24 private Vector<Boolean> install;
[591]25 private int vocabModTypeID = -1;
26 private int vocabPlatformID = -1;
27
28 /**
29 * Create a new model
30 */
31 public ModTableModel() {
32 reloadData();
33 }
34
35 @Override
36 public Object getValueAt(int row, int col) {
37 NodeMod node = items.get(row);
38 switch (col) {
39 case -1:
40 return node;
41 case 0:
42 return node.getTitle();
43 case 1:
44 return node.getFields().get("package_number");
45 case 2:
46 String type = "";
47 if (vocabModTypeID < 0) {
[593]48 vocabModTypeID = DepotManager
49 .getInstance()
50 .getVocabulary(
51 DepotConfig.getVocabularyName_ModType())
52 .getVid();
[591]53 }
54 for (int tid : node.getTaxonomyTerms().get(vocabModTypeID)) {
55 if (type.length() > 0)
56 type += ", ";
57 type += DepotManager.getInstance().getTaxonomyTerm(tid)
58 .getName();
59 }
60 return type;
61 case 3:
62 if (vocabPlatformID < 0) {
[593]63 vocabPlatformID = DepotManager
64 .getInstance()
65 .getVocabulary(
66 DepotConfig.getVocabularyName_Platform())
67 .getVid();
[591]68 }
69 int tid = node.getTaxonomyTerms().get(vocabPlatformID)
70 .iterator().next();
71 return DepotManager.getInstance().getTaxonomyTerm(tid)
72 .getName();
[593]73 case 4:
74 return install.get(row);
[591]75 }
76 return null;
77 }
78
79 @Override
80 public String getColumnName(int col) {
81 switch (col) {
82 case 0:
83 return bundle.getString("mod.name");
84 case 1:
85 return bundle.getString("mod.package_number");
86 case 2:
87 return bundle.getString("mod.type");
88 case 3:
89 return bundle.getString("mod.platform");
[593]90 case 4:
91 return bundle.getString("mod.install");
[591]92 }
93 return null;
94 }
95
96 @Override
97 public int getRowCount() {
98 return items.size();
99 }
100
101 @Override
102 public int getColumnCount() {
[593]103 return 5;
[591]104 }
105
106 @Override
107 public Class<?> getColumnClass(int col) {
108 switch (col) {
109 case 0:
110 return String.class;
111 case 1:
112 return Integer.class;
113 case 2:
114 return String.class;
115 case 3:
116 return String.class;
[593]117 case 4:
118 return Boolean.class;
[591]119 }
120 return null;
121 }
122
123 /**
124 * Set the constraints on the columns size for the given column
125 *
126 * @param colNum
127 * Column number
128 * @param col
129 * Column object
130 */
131 public void setColumnConstraints(int colNum, TableColumn col) {
132 int w;
133 switch (colNum) {
134 case 0:
135 col.setPreferredWidth(150);
136 break;
137 case 1:
138 w = 55;
139 col.setPreferredWidth(w);
140 col.setMinWidth(w);
141 col.setMaxWidth(w);
142 break;
143 case 2:
144 col.setPreferredWidth(100);
145 break;
146 case 3:
147 w = 70;
148 col.setPreferredWidth(w);
149 col.setMinWidth(w);
150 col.setMaxWidth(w);
151 break;
[593]152 case 4:
153 w = 60;
154 col.setPreferredWidth(w);
155 col.setMinWidth(w);
156 col.setMaxWidth(w);
157 break;
[591]158 }
159 }
160
161 /**
162 * Reload the nodes data after an update to the cache
163 */
164 public void reloadData() {
165 items = DepotManager.getInstance().getModPackageNodes();
[593]166 install = new Vector<Boolean>();
167 // TODO check installed
168 for (int i = 0; i < items.size(); i++) {
169 install.add(i, false);
170 }
[591]171 }
172
173 /**
174 * Get the items vector
175 *
176 * @return Items
177 */
178 public Vector<NodeMod> getItems() {
179 return items;
180 }
181
[593]182 @Override
183 public boolean isCellEditable(int rowIndex, int columnIndex) {
184 return columnIndex == 4;
185 }
186
187 @Override
188 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
189 super.setValueAt(aValue, rowIndex, columnIndex);
190 if (columnIndex == 4) {
191 install.set(rowIndex, (Boolean) aValue);
192 }
193 }
194
[591]195}
Note: See TracBrowser for help on using the repository browser.