View Javadoc

1   // %1126721330416: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.vo.PlayerTransfer;
9   
10  import java.text.SimpleDateFormat;
11  
12  import java.util.List;
13  
14  import javax.swing.table.AbstractTableModel;
15  
16  
17  /***
18   * TableModel representing transfers for a player.
19   *
20   * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
21   */
22  public class PlayerTransferTableModel extends AbstractTableModel {
23      //~ Static fields/initializers -----------------------------------------------------------------
24  
25      private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
26  
27      //~ Instance fields ----------------------------------------------------------------------------
28  
29      private List values;
30      private String[] colNames = new String[8];
31  
32      //~ Constructors -------------------------------------------------------------------------------
33  
34      /***
35       * Creates a PlayerTransferTableModel.
36       *
37       * @param values List of values to show in table.
38       */
39      public PlayerTransferTableModel(List values) {
40          super();
41  
42          this.colNames[0] = Commons.getModel().getResource().getProperty("Datum"); //$NON-NLS-1$
43          this.colNames[1] = Commons.getModel().getResource().getProperty("Season"); //$NON-NLS-1$
44          this.colNames[2] = PluginProperty.getString("Week"); //$NON-NLS-1$
45          this.colNames[3] = PluginProperty.getString("Buyer"); //$NON-NLS-1$
46          this.colNames[4] = ""; //$NON-NLS-1$
47          this.colNames[5] = PluginProperty.getString("Seller"); //$NON-NLS-1$
48          this.colNames[6] = PluginProperty.getString("Price"); //$NON-NLS-1$
49          this.colNames[7] = PluginProperty.getString("TSI"); //$NON-NLS-1$
50  
51          this.values = values;
52      }
53  
54      //~ Methods ------------------------------------------------------------------------------------
55  
56      /*** {@inheritDoc} */
57      public final int getColumnCount() {
58          return colNames.length;
59      }
60  
61      /*** {@inheritDoc} */
62      public final String getColumnName(int column) {
63          return colNames[column];
64      }
65  
66      /*** {@inheritDoc} */
67      public final int getRowCount() {
68          return values.size();
69      }
70  
71      /*** {@inheritDoc} */
72      public final Object getValueAt(int rowIndex, int columnIndex) {
73          final PlayerTransfer transfer = (PlayerTransfer) values.get(rowIndex);
74  
75          switch (columnIndex) {
76              case 0:
77                  return FORMAT.format(transfer.getDate());
78  
79              case 1:
80                  return new Integer(transfer.getSeason());
81  
82              case 2:
83                  return new Integer(transfer.getWeek());
84  
85              case 3:
86                  return transfer.getBuyerName();
87  
88              case 4:
89                  return new Integer(PlayerTransfer.BUY);
90  
91              case 5:
92                  return transfer.getSellerName();
93  
94              case 6:
95                  return new Integer(transfer.getPrice());
96  
97              case 7:
98                  return new Integer(transfer.getTsi());
99  
100             default:
101                 return ""; //$NON-NLS-1$
102         }
103     }
104 }