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