1   package org.wcb.gui.table.model;
2   
3   import org.wcb.model.bd.LogbookDelegate;
4   import org.wcb.model.vo.hibernate.Logbook;
5   import org.wcb.model.vo.FAA8710LineItem;
6   import org.wcb.gui.util.MathFAA8710Utility;
7   
8   import javax.swing.table.AbstractTableModel;
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  /**
13   * <small>
14   * <p/>
15   * Copyright (c)  2006  wbogaardt.
16   * This library is free software; you can redistribute it and/or
17   * modify it under the terms of the GNU Lesser General Public
18   * License as published by the Free Software Foundation; either
19   * version 2.1 of the License, or (at your option) any later version.
20   *
21   * This library is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24   * Lesser General Public License for more details.
25   *
26   * You should have received a copy of the GNU Lesser General Public
27   * License along with this library; if not, write to the Free Software
28   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29   * <p/>
30   * $File:  $ <br>
31   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Aug 31, 2006 11:12:41 AM $ <br>
32   * </small>
33   *
34   * @author wbogaardt
35   *         //This sums up values for the 8710 form.
36   */
37  
38  public class Faa8710Model  extends AbstractTableModel {
39  
40      private String[] columnName = {"Description", "Airplanes", "Rotocraft", "Powered Lift", "Gliders", "Lighter Than Air", "Simulator", "Training Device", "PCATD"};
41      private ArrayList row;
42      private LogbookDelegate delegate;
43      private MathFAA8710Utility mathUtil;
44  
45      public Faa8710Model() {
46      }
47  
48      public LogbookDelegate getDelegate() {
49          return delegate;
50      }
51  
52      public void setDelegate(LogbookDelegate delegate) {
53          this.delegate = delegate;
54      }
55  
56      public void setMathUtility(MathFAA8710Utility mathUtility) {
57          mathUtil = mathUtility;
58      }
59  
60      public MathFAA8710Utility getMathUtility() {
61          return mathUtil;
62      }
63  
64      public void refreshModel() {
65          List<Logbook> rows = delegate.getAllLogbookEntries();
66          List<FAA8710LineItem> items = new ArrayList<FAA8710LineItem>();
67          items.add(mathUtil.getTotalTime(rows));
68          items.add(mathUtil.getInstructionRecievedTime(rows));
69          items.add(mathUtil.getSoloTime(rows));
70          items.add(mathUtil.getPICTime(rows));
71          items.add(mathUtil.getSICTime(rows));
72          items.add(mathUtil.getXcountryInstructionTime(rows));
73          items.add(mathUtil.getXcountrySoloTime(rows));
74          items.add(mathUtil.getXcountryPICTime(rows));
75          items.add(mathUtil.getXcountrySICTime(rows));
76          items.add(mathUtil.getInstrumentTime(rows));
77          items.add(mathUtil.getNightInstructionTime(rows));
78          items.add(mathUtil.getNightLandingsCount(rows));
79          items.add(mathUtil.getNightPICTime(rows));
80          items.add(mathUtil.getNightSICTime(rows));
81          items.add(mathUtil.getNightPICLandings(rows));
82          items.add(mathUtil.getNightSICLandings(rows));
83          row = (ArrayList) items;
84          fireTableDataChanged();
85      }
86  
87      public String getColumnName(int column) {
88          return columnName[column];
89      }
90  
91      public boolean isCellEditable(int rowVal, int column) {
92          return true;
93      }
94  
95      public int getColumnCount() {
96          return columnName.length;
97      }
98  
99      public int getRowCount() {
100         return row.size();
101     }
102 
103     public Object getValueAt(int rowLine, int column) {
104         FAA8710LineItem item = (FAA8710LineItem) row.get(rowLine);
105         switch(column)
106         {
107             case 0:
108                 return item.getDescription();
109             case 1:
110                 return item.getAirplanes();
111             case 2:
112                 return item.getRotocraft();
113             case 3:
114                 return item.getPoweredLift();
115             case 4:
116                 return item.getGliders();
117             case 5:
118                 return item.getLighterThanAir();
119             case 6:
120                 return item.getSimulator();
121             case 7:
122                 return item.getTrainingDevice();
123             case 8:
124                 return item.getPCATD();
125             default:
126                 return item;
127         }
128     }
129 
130     public FAA8710LineItem getItemAt(int rowId) {
131         return (FAA8710LineItem) row.get(rowId);
132     }
133 
134     /**
135      * Remove the identified row from the
136      * model and fire a data table change event.
137      * @param rowId Row number to remove
138      */
139     public void removeRow(int rowId)
140     {
141         row.remove(rowId);
142         fireTableDataChanged();
143     }
144 
145     public Class getColumnClass(int columnIndex) {
146         return String.class;
147     }
148 }