1
2 package hoplugins.trainingExperience.ui.model;
3
4 import hoplugins.Commons;
5
6 import hoplugins.trainingExperience.constants.Trainings;
7
8 import plugins.IHOMiniModel;
9 import plugins.ITrainingWeek;
10
11 import java.util.Iterator;
12 import java.util.Vector;
13
14
15 /***
16 * Customized table model for past trainings
17 */
18 public class PastTrainingsTableModel extends AbstractTrainingsTableModel {
19
20
21 /***
22 * Creates a new PastTrainingsTableModel object.
23 *
24 * @param miniModel
25 */
26 public PastTrainingsTableModel(IHOMiniModel miniModel) {
27 super(miniModel);
28 }
29
30
31
32 /***
33 * When a value is updated, update the value in the right TrainingWeek in p_V_trainingsVector
34 * store the change thru HO API. Refresh the main table, and deselect any player
35 *
36 * @param value
37 * @param row
38 * @param col
39 */
40 public void setValueAt(Object value, int row, int col) {
41 Object[] aobj = (Object[]) p_V_data.get(row);
42
43 aobj[col] = value;
44
45 ITrainingWeek train = (ITrainingWeek) p_V_trainingsVector.get(p_V_data.size() - row - 1);
46
47 if (col == 2) {
48 String selection = value.toString();
49
50 train.setTyp(Trainings.getTrainingCode(selection));
51 }
52
53 if (col == 3) {
54 Integer intense = (Integer) value;
55
56 train.setIntensitaet(intense.intValue());
57 }
58
59 Commons.getModel().saveTraining(train);
60 fireTableCellUpdated(row, col);
61 }
62
63 /***
64 * Populate the table with the old trainings week loaded from HO API
65 */
66 public void populate() {
67 p_V_data = new Vector();
68
69
70 p_V_trainingsVector = Commons.getModel().getTrainingsManager().getTrainingsVector();
71
72 Object[] aobj;
73
74
75 for (Iterator it = p_V_trainingsVector.iterator(); it.hasNext();) {
76 ITrainingWeek train = (ITrainingWeek) it.next();
77 String selectedTrain = Trainings.getTrainingDescription(train.getTyp());
78
79 aobj = (new Object[]{
80 train.getHattrickWeek() + "",
81 train.getHattrickSeason() + "",
82 selectedTrain, new Integer(train.getIntensitaet())
83 });
84
85
86 p_V_data.add(0, (Object) aobj);
87 }
88
89 fireTableDataChanged();
90 }
91 }