1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components.table;
22
23 import java.util.Vector;
24
25 import javax.swing.table.AbstractTableModel;
26 import javax.swing.table.DefaultTableModel;
27 import javax.swing.table.TableModel;
28
29
30 /***
31 */
32 abstract public class AbstractFilterModel extends AbstractTableModel {
33
34 protected TableModel model;
35
36
37 public AbstractFilterModel(TableModel tm) {
38 model = tm;
39 }
40
41
42 public boolean isCellEditable(int par1, int par2) {
43 return model.isCellEditable(par1, par2);
44 }
45
46 public Class getColumnClass(int par1) {
47 return model.getColumnClass(par1);
48 }
49
50 public int getColumnCount() {
51 return model.getColumnCount();
52 }
53
54 public String getColumnName(int par1) {
55 return model.getColumnName(par1);
56 }
57
58 public void setModel(TableModel model) {
59 this.model = model;
60 this.fireTableDataChanged();
61 }
62
63 public TableModel getModel() {
64 return model;
65 }
66
67 public int getRowCount() {
68 return model.getRowCount();
69 }
70
71 public void setValueAt(Object par1, int par2, int par3) {
72 model.setValueAt(par1, par2, par3);
73 }
74
75 public Object getValueAt(int par1, int par2) {
76 return model.getValueAt(par1, par2);
77 }
78
79 public void addRow(Vector data) throws IllegalStateException {
80 if (model instanceof DefaultTableModel) {
81 ((DefaultTableModel) model).addRow(data);
82 } else if (model instanceof AbstractFilterModel) {
83 ((AbstractFilterModel) model).addRow(data);
84 } else {
85 throw (new IllegalStateException("Error attempting to add a row to an underlying model that is not a DefaultTableModel."));
86 }
87 }
88
89 public void removeAllRows() throws ArrayIndexOutOfBoundsException, IllegalStateException {
90 while (this.getRowCount() > 0) {
91 this.removeRow(0);
92 }
93 }
94
95 public void removeRow(int rowNum) throws ArrayIndexOutOfBoundsException, IllegalStateException {
96 if (model instanceof DefaultTableModel) {
97 ((DefaultTableModel) model).removeRow(rowNum);
98 } else if (model instanceof AbstractFilterModel) {
99 ((AbstractFilterModel) model).removeRow(rowNum);
100 } else {
101 throw (new IllegalStateException("Error attempting to remove a row from an underlying model that is not a DefaultTableModel."));
102 }
103 }
104 }