KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > components > table > AbstractFilterModel


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.components.table;
6
7 import javax.swing.table.AbstractTableModel JavaDoc;
8 import javax.swing.table.DefaultTableModel JavaDoc;
9 import javax.swing.table.TableModel JavaDoc;
10 import java.util.Vector JavaDoc;
11
12
13 /**
14  * @author Onyeje Bose
15  * @version 1.0
16  */

17 abstract public class AbstractFilterModel extends AbstractTableModel JavaDoc {
18     //~ Instance fields ////////////////////////////////////////////////////////
19

20     protected TableModel JavaDoc model;
21
22     //~ Constructors ///////////////////////////////////////////////////////////
23

24     public AbstractFilterModel(TableModel JavaDoc tm) {
25         model = tm;
26     }
27
28     //~ Methods ////////////////////////////////////////////////////////////////
29

30     public boolean isCellEditable(int par1, int par2) {
31         return model.isCellEditable(par1, par2);
32     }
33
34     public Class JavaDoc getColumnClass(int par1) {
35         return model.getColumnClass(par1);
36     }
37
38     public int getColumnCount() {
39         return model.getColumnCount();
40     }
41
42     public String JavaDoc getColumnName(int par1) {
43         return model.getColumnName(par1);
44     }
45
46     public void setModel(TableModel JavaDoc model) {
47         this.model = model;
48         this.fireTableDataChanged();
49     }
50
51     public TableModel JavaDoc getModel() {
52         return model;
53     }
54
55     public int getRowCount() {
56         return model.getRowCount();
57     }
58
59     public void setValueAt(Object JavaDoc par1, int par2, int par3) {
60         model.setValueAt(par1, par2, par3);
61     }
62
63     public Object JavaDoc getValueAt(int par1, int par2) {
64         return model.getValueAt(par1, par2);
65     }
66
67     public void addRow(Vector JavaDoc data) throws IllegalStateException JavaDoc {
68         if (model instanceof DefaultTableModel JavaDoc) {
69             ((DefaultTableModel JavaDoc) model).addRow(data);
70         } else if (model instanceof AbstractFilterModel) {
71             ((AbstractFilterModel) model).addRow(data);
72         } else {
73             throw (new IllegalStateException JavaDoc("Error attempting to add a row to an underlying model that is not a DefaultTableModel."));
74         }
75     }
76
77     public void removeAllRows() throws ArrayIndexOutOfBoundsException JavaDoc, IllegalStateException JavaDoc {
78         while (this.getRowCount() > 0) {
79             this.removeRow(0);
80         }
81     }
82
83     public void removeRow(int rowNum) throws ArrayIndexOutOfBoundsException JavaDoc, IllegalStateException JavaDoc {
84         if (model instanceof DefaultTableModel JavaDoc) {
85             ((DefaultTableModel JavaDoc) model).removeRow(rowNum);
86         } else if (model instanceof AbstractFilterModel) {
87             ((AbstractFilterModel) model).removeRow(rowNum);
88         } else {
89             throw (new IllegalStateException JavaDoc("Error attempting to remove a row from an underlying model that is not a DefaultTableModel."));
90         }
91     }
92 }
93
Popular Tags