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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
136
137
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 }