View Javadoc

1   // %638597353:hoplugins.trainingExperience.ui.model%
2   package hoplugins.trainingExperience.ui.model;
3   
4   import hoplugins.Commons;
5   import hoplugins.TrainingExperience;
6   
7   import hoplugins.trainingExperience.constants.Trainings;
8   
9   import plugins.IFutureTrainingWeek;
10  import plugins.IHOMiniModel;
11  
12  import java.util.Iterator;
13  import java.util.List;
14  import java.util.Vector;
15  
16  
17  /***
18   * Customized table model for future trainings
19   */
20  public class FutureTrainingsTableModel extends AbstractTrainingsTableModel {
21      //~ Constructors -------------------------------------------------------------------------------
22  
23      /***
24       * Creates a new FutureTrainingsTableModel object.
25       *
26       * @param miniModel
27       */
28      public FutureTrainingsTableModel(IHOMiniModel miniModel) {
29          super(miniModel);
30      }
31  
32      //~ Methods ------------------------------------------------------------------------------------
33  
34      /***
35       * When a value is updated, update the value in the right TrainingWeek in p_V_trainingsVector
36       * store the change in the DB and then update the player prevision with the new training
37       * setting
38       *
39       * @param value
40       * @param row
41       * @param col
42       */
43      public void setValueAt(Object value, int row, int col) {
44          Object[] aobj = (Object[]) p_V_data.get(row);
45  
46          aobj[col] = value;
47  
48          IFutureTrainingWeek train = (IFutureTrainingWeek) p_V_trainingsVector.get(row);
49  
50          if (col == 2) {
51              String selection = value.toString();
52  
53              train.setTyp(Trainings.getTrainingCode(selection));
54          }
55  
56          if (col == 3) {
57              Integer intense = (Integer) value;
58  
59              train.setIntensitaet(intense.intValue());
60          }
61  
62          Commons.getModel().saveFutureTraining(train);
63          fireTableCellUpdated(row, col);
64          TrainingExperience.refreshPlayerDetail();
65      }
66  
67      /***
68       * Populate the table with the future trainings stored in the db,  if not present, create it
69       * new and saves it
70       */
71      public void populate() {
72          p_V_data = new Vector();
73          p_V_trainingsVector = new Vector();
74  
75          Object[] aobj;
76  
77          IFutureTrainingWeek oldTrain = null;
78  
79          List futureTrainings = p_IHMM_miniModel.getFutureTrainingWeeks();
80  
81          for (Iterator iter = futureTrainings.iterator(); iter.hasNext();) {
82              IFutureTrainingWeek train = (IFutureTrainingWeek) iter.next();
83  
84              // if not found create it and saves it
85              if (train.getIntensitaet() == -1) {
86                  if (oldTrain != null) {
87                      train.setIntensitaet(oldTrain.getIntensitaet());
88                      train.setTyp(oldTrain.getTyp());
89                  } else {
90                      train.setIntensitaet(100);
91                      train.setTyp(0);
92                  }
93  
94                  Commons.getModel().saveFutureTraining(train);
95              }
96  
97              String selectedTrain = Trainings.getTrainingDescription(train.getTyp());
98  
99              aobj = (new Object[]{
100                        train.getWeek() + "", //$NON-NLS-1$
101             train.getSeason() + "", //$NON-NLS-1$
102             selectedTrain, new Integer(train.getIntensitaet())
103                    });
104 
105             // Add object to be visualized to the table model
106             p_V_data.add((Object) aobj);
107 
108             // Add training object to the proper vector for external use
109             p_V_trainingsVector.add(train);
110 
111             oldTrain = train;
112         }
113 
114         fireTableDataChanged();
115     }
116 }