View Javadoc

1   // %1126721330541:hoplugins.transfers.ui.model%
2   package hoplugins.transfers.ui.model;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.utils.PluginProperty;
7   
8   import hoplugins.transfers.constants.TransferTypes;
9   import hoplugins.transfers.dao.TransferTypeDAO;
10  import hoplugins.transfers.utils.PlayerRetriever;
11  import hoplugins.transfers.vo.TransferredPlayer;
12  
13  import plugins.ISpieler;
14  
15  import java.util.List;
16  
17  import javax.swing.table.AbstractTableModel;
18  
19  
20  /***
21   * TableModel representing the effect of training.
22   *
23   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
24   */
25  public class TransferTypeTableModel extends AbstractTableModel {
26      //~ Instance fields ----------------------------------------------------------------------------
27  
28      private List values;
29      private String[] colNames = new String[4];
30  
31      //~ Constructors -------------------------------------------------------------------------------
32  
33      /***
34       * Creates a TransferTypeTableModel.
35       *
36       * @param values List of values to show in table.
37       */
38      public TransferTypeTableModel(List values) {
39          super();
40  
41          this.colNames[0] = Commons.getModel().getResource().getProperty("ID");
42          this.colNames[1] = Commons.getModel().getResource().getProperty("Name");
43          this.colNames[2] = PluginProperty.getString("Type");
44          this.colNames[3] = PluginProperty.getString("Income");
45  
46          //this.colNames[2] = PluginProperty.getString("Week"); //$NON-NLS-1$
47          this.values = values;
48      }
49  
50      //~ Methods ------------------------------------------------------------------------------------
51  
52      /***
53       * Method that returns if a cell is editable or not
54       *
55       * @param row Row number
56       * @param column Column number
57       *
58       * @return <code>true</code> is cell is editable, <code>false</code> if not.
59       */
60      public final boolean isCellEditable(int row, int column) {
61          return column == 2;
62      }
63  
64      /*** {@inheritDoc} */
65      public final int getColumnCount() {
66          return colNames.length;
67      }
68  
69      /*** {@inheritDoc} */
70      public final String getColumnName(int column) {
71          return colNames[column];
72      }
73  
74      /*** {@inheritDoc} */
75      public final int getRowCount() {
76          return values.size();
77      }
78  
79      /***
80       * When a value is updated, update the value in the right TrainingWeek in p_V_trainingsVector
81       * store the change thru HO API. Refresh the main table, and deselect any player
82       *
83       * @param value Value to set
84       * @param row Row number
85       * @param col Column number
86       */
87      public final void setValueAt(Object value, int row, int col) {
88          if (col == 2) {
89              final String type = value.toString();
90              final Object id = getValueAt(row, 0);
91  
92              try {
93                  TransferTypeDAO.setType(Integer.parseInt("" + id),
94                                          TransferTypes.getTransferCode(type));
95              } catch (Exception e) {
96                  // DO Nothing
97              }
98          }
99  
100         fireTableCellUpdated(row, col);
101     }
102 
103     /*** {@inheritDoc} */
104     public final Object getValueAt(int rowIndex, int columnIndex) {
105         final TransferredPlayer transfer = (TransferredPlayer) values.get(rowIndex);
106 
107         switch (columnIndex) {
108             case 0:
109                 return new Integer(transfer.getPlayerId());
110 
111             case 1:
112                 return transfer.getPlayerName();
113 
114             case 2:
115                 return TransferTypes.getTransferDesc(transfer.getTransferType());
116 
117             case 3:
118                 return new Integer(transfer.getIncome());
119 
120             default:
121                 return ""; //$NON-NLS-1$
122         }
123     }
124 }