| 1 | package net.oni2.aeinstaller.gui.modtable; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | import java.util.ResourceBundle; | 
 
 
 
 
 | 4 | import java.util.Vector; | 
 
 
 
 
 | 5 |  | 
 
 
 
 
 | 6 | import javax.swing.table.AbstractTableModel; | 
 
 
 
 
 | 7 | import javax.swing.table.TableColumn; | 
 
 
 
 
 | 8 |  | 
 
 
 
 
 | 9 | import net.oni2.aeinstaller.backend.depot.DepotConfig; | 
 
 
 
 
 | 10 | import net.oni2.aeinstaller.backend.depot.DepotManager; | 
 
 
 
 
 | 11 | import net.oni2.aeinstaller.backend.depot.model.NodeMod; | 
 
 
 
 
 | 12 |  | 
 
 
 
 
 | 13 | /** | 
 
 
 
 
 | 14 | * @author Christian Illy | 
 
 
 
 
 | 15 | */ | 
 
 
 
 
 | 16 | public 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; | 
 
 
 
 
 | 24 | private Vector<Boolean> install; | 
 
 
 
 
 | 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) { | 
 
 
 
 
 | 48 | vocabModTypeID = DepotManager | 
 
 
 
 
 | 49 | .getInstance() | 
 
 
 
 
 | 50 | .getVocabulary( | 
 
 
 
 
 | 51 | DepotConfig.getVocabularyName_ModType()) | 
 
 
 
 
 | 52 | .getVid(); | 
 
 
 
 
 | 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) { | 
 
 
 
 
 | 63 | vocabPlatformID = DepotManager | 
 
 
 
 
 | 64 | .getInstance() | 
 
 
 
 
 | 65 | .getVocabulary( | 
 
 
 
 
 | 66 | DepotConfig.getVocabularyName_Platform()) | 
 
 
 
 
 | 67 | .getVid(); | 
 
 
 
 
 | 68 | } | 
 
 
 
 
 | 69 | int tid = node.getTaxonomyTerms().get(vocabPlatformID) | 
 
 
 
 
 | 70 | .iterator().next(); | 
 
 
 
 
 | 71 | return DepotManager.getInstance().getTaxonomyTerm(tid) | 
 
 
 
 
 | 72 | .getName(); | 
 
 
 
 
 | 73 | case 4: | 
 
 
 
 
 | 74 | return install.get(row); | 
 
 
 
 
 | 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"); | 
 
 
 
 
 | 90 | case 4: | 
 
 
 
 
 | 91 | return bundle.getString("mod.install"); | 
 
 
 
 
 | 92 | } | 
 
 
 
 
 | 93 | return null; | 
 
 
 
 
 | 94 | } | 
 
 
 
 
 | 95 |  | 
 
 
 
 
 | 96 | @Override | 
 
 
 
 
 | 97 | public int getRowCount() { | 
 
 
 
 
 | 98 | return items.size(); | 
 
 
 
 
 | 99 | } | 
 
 
 
 
 | 100 |  | 
 
 
 
 
 | 101 | @Override | 
 
 
 
 
 | 102 | public int getColumnCount() { | 
 
 
 
 
 | 103 | return 5; | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 117 | case 4: | 
 
 
 
 
 | 118 | return Boolean.class; | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 152 | case 4: | 
 
 
 
 
 | 153 | w = 60; | 
 
 
 
 
 | 154 | col.setPreferredWidth(w); | 
 
 
 
 
 | 155 | col.setMinWidth(w); | 
 
 
 
 
 | 156 | col.setMaxWidth(w); | 
 
 
 
 
 | 157 | break; | 
 
 
 
 
 | 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(); | 
 
 
 
 
 | 166 | install = new Vector<Boolean>(); | 
 
 
 
 
 | 167 | // TODO check installed | 
 
 
 
 
 | 168 | for (int i = 0; i < items.size(); i++) { | 
 
 
 
 
 | 169 | install.add(i, false); | 
 
 
 
 
 | 170 | } | 
 
 
 
 
 | 171 | } | 
 
 
 
 
 | 172 |  | 
 
 
 
 
 | 173 | /** | 
 
 
 
 
 | 174 | * Get the items vector | 
 
 
 
 
 | 175 | * | 
 
 
 
 
 | 176 | * @return Items | 
 
 
 
 
 | 177 | */ | 
 
 
 
 
 | 178 | public Vector<NodeMod> getItems() { | 
 
 
 
 
 | 179 | return items; | 
 
 
 
 
 | 180 | } | 
 
 
 
 
 | 181 |  | 
 
 
 
 
 | 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 |  | 
 
 
 
 
 | 195 | } |