| 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 int vocabModTypeID = -1; |
| 25 |
private int vocabPlatformID = -1; |
| 26 |
|
| 27 |
/** |
| 28 |
* Create a new model |
| 29 |
*/ |
| 30 |
public ModTableModel() { |
| 31 |
reloadData(); |
| 32 |
} |
| 33 |
|
| 34 |
@Override |
| 35 |
public Object getValueAt(int row, int col) { |
| 36 |
NodeMod node = items.get(row); |
| 37 |
switch (col) { |
| 38 |
case -1: |
| 39 |
return node; |
| 40 |
case 0: |
| 41 |
return node.getTitle(); |
| 42 |
case 1: |
| 43 |
return node.getFields().get("package_number"); |
| 44 |
case 2: |
| 45 |
String type = ""; |
| 46 |
if (vocabModTypeID < 0) { |
| 47 |
vocabModTypeID = DepotManager.getInstance() |
| 48 |
.getVocabulary(DepotConfig.getVocabularyName_ModType()).getVid(); |
| 49 |
} |
| 50 |
for (int tid : node.getTaxonomyTerms().get(vocabModTypeID)) { |
| 51 |
if (type.length() > 0) |
| 52 |
type += ", "; |
| 53 |
type += DepotManager.getInstance().getTaxonomyTerm(tid) |
| 54 |
.getName(); |
| 55 |
} |
| 56 |
return type; |
| 57 |
case 3: |
| 58 |
if (vocabPlatformID < 0) { |
| 59 |
vocabPlatformID = DepotManager.getInstance() |
| 60 |
.getVocabulary(DepotConfig.getVocabularyName_Platform()).getVid(); |
| 61 |
} |
| 62 |
int tid = node.getTaxonomyTerms().get(vocabPlatformID) |
| 63 |
.iterator().next(); |
| 64 |
return DepotManager.getInstance().getTaxonomyTerm(tid) |
| 65 |
.getName(); |
| 66 |
} |
| 67 |
return null; |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public String getColumnName(int col) { |
| 72 |
switch (col) { |
| 73 |
case 0: |
| 74 |
return bundle.getString("mod.name"); |
| 75 |
case 1: |
| 76 |
return bundle.getString("mod.package_number"); |
| 77 |
case 2: |
| 78 |
return bundle.getString("mod.type"); |
| 79 |
case 3: |
| 80 |
return bundle.getString("mod.platform"); |
| 81 |
} |
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public int getRowCount() { |
| 87 |
return items.size(); |
| 88 |
} |
| 89 |
|
| 90 |
@Override |
| 91 |
public int getColumnCount() { |
| 92 |
return 4; |
| 93 |
} |
| 94 |
|
| 95 |
@Override |
| 96 |
public Class<?> getColumnClass(int col) { |
| 97 |
switch (col) { |
| 98 |
case 0: |
| 99 |
return String.class; |
| 100 |
case 1: |
| 101 |
return Integer.class; |
| 102 |
case 2: |
| 103 |
return String.class; |
| 104 |
case 3: |
| 105 |
return String.class; |
| 106 |
} |
| 107 |
return null; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Set the constraints on the columns size for the given column |
| 112 |
* |
| 113 |
* @param colNum |
| 114 |
* Column number |
| 115 |
* @param col |
| 116 |
* Column object |
| 117 |
*/ |
| 118 |
public void setColumnConstraints(int colNum, TableColumn col) { |
| 119 |
int w; |
| 120 |
switch (colNum) { |
| 121 |
case 0: |
| 122 |
col.setPreferredWidth(150); |
| 123 |
break; |
| 124 |
case 1: |
| 125 |
w = 55; |
| 126 |
col.setPreferredWidth(w); |
| 127 |
col.setMinWidth(w); |
| 128 |
col.setMaxWidth(w); |
| 129 |
break; |
| 130 |
case 2: |
| 131 |
col.setPreferredWidth(100); |
| 132 |
break; |
| 133 |
case 3: |
| 134 |
w = 70; |
| 135 |
col.setPreferredWidth(w); |
| 136 |
col.setMinWidth(w); |
| 137 |
col.setMaxWidth(w); |
| 138 |
break; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Reload the nodes data after an update to the cache |
| 144 |
*/ |
| 145 |
public void reloadData() { |
| 146 |
items = DepotManager.getInstance().getModPackageNodes(); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Get the items vector |
| 151 |
* |
| 152 |
* @return Items |
| 153 |
*/ |
| 154 |
public Vector<NodeMod> getItems() { |
| 155 |
return items; |
| 156 |
} |
| 157 |
|
| 158 |
} |