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