1 package org.wcb.gui.table.model;
2
3 import org.wcb.model.vo.hibernate.AirportBO;
4 import org.wcb.model.bd.AirportDelegate;
5 import org.wcb.model.util.SpringUtil;
6 import org.wcb.model.service.IServicesConstants;
7
8 import javax.swing.table.AbstractTableModel;
9 import java.util.ArrayList;
10
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 AirportModel extends AbstractTableModel {
39
40 private String[] columnName;
41 private ArrayList row;
42 private AirportDelegate delegate;
43
44 public AirportModel() {
45 this(new String[] {" ", "ICAO", "FAA", "Name", "Location", "", ""});
46 }
47
48 public AirportModel(String[] columns) {
49 this.columnName = columns;
50 }
51 public AirportDelegate getDelegate() {
52 if (delegate == null) {
53 delegate = (AirportDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.AIRPORT_DELEGATE);
54 }
55 return delegate;
56 }
57
58 public void setDelegate(AirportDelegate delegate) {
59 this.delegate = delegate;
60 }
61
62 public void refreshModel() {
63 java.util.List<AirportBO> airport = getDelegate().getAllAirports();
64 row = (ArrayList) airport;
65 fireTableDataChanged();
66 }
67
68 public String getColumnName(int column) {
69 return columnName[column];
70 }
71
72 public boolean isCellEditable(int rowVal, int column) {
73 return true;
74 }
75
76 public int getColumnCount() {
77 return columnName.length;
78 }
79
80 public int getRowCount() {
81 return row.size();
82 }
83
84 public Object getValueAt(int rowLine, int column) {
85 AirportBO item = (AirportBO) row.get(rowLine);
86 if (getColumnCount() == 7) {
87 switch(column)
88 {
89 case 1:
90 return item.getIcao();
91 case 2:
92 return item.getFaa();
93 case 3:
94 return item.getName();
95 case 4:
96 return item.getMunicipal() + ", " + item.getState();
97 default:
98 return item;
99 }
100 } else {
101 switch(column)
102 {
103 case 0:
104 return item.getIcao();
105 case 1:
106 return item.getFaa();
107 case 2:
108 return item.getName();
109 case 3:
110 return item.getMunicipal() + ", " + item.getState();
111 default:
112 return item;
113 }
114 }
115
116 }
117
118 public AirportBO getItemAt(int rowId) {
119 return (AirportBO) row.get(rowId);
120 }
121
122
123
124
125
126
127 public void removeRow(int rowId)
128 {
129 row.remove(rowId);
130 fireTableDataChanged();
131 }
132
133 public Class getColumnClass(int columnIndex) {
134 return String.class;
135 }
136 }