001: /*
002: * $Id: AbstractFilterModel.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components.table;
022:
023: import java.util.Vector;
024:
025: import javax.swing.table.AbstractTableModel;
026: import javax.swing.table.DefaultTableModel;
027: import javax.swing.table.TableModel;
028:
029: /**
030: */
031: abstract public class AbstractFilterModel extends AbstractTableModel {
032:
033: protected TableModel model;
034:
035: public AbstractFilterModel(TableModel tm) {
036: model = tm;
037: }
038:
039: public boolean isCellEditable(int par1, int par2) {
040: return model.isCellEditable(par1, par2);
041: }
042:
043: public Class getColumnClass(int par1) {
044: return model.getColumnClass(par1);
045: }
046:
047: public int getColumnCount() {
048: return model.getColumnCount();
049: }
050:
051: public String getColumnName(int par1) {
052: return model.getColumnName(par1);
053: }
054:
055: public void setModel(TableModel model) {
056: this .model = model;
057: this .fireTableDataChanged();
058: }
059:
060: public TableModel getModel() {
061: return model;
062: }
063:
064: public int getRowCount() {
065: return model.getRowCount();
066: }
067:
068: public void setValueAt(Object par1, int par2, int par3) {
069: model.setValueAt(par1, par2, par3);
070: }
071:
072: public Object getValueAt(int par1, int par2) {
073: return model.getValueAt(par1, par2);
074: }
075:
076: public void addRow(Vector data) throws IllegalStateException {
077: if (model instanceof DefaultTableModel) {
078: ((DefaultTableModel) model).addRow(data);
079: } else if (model instanceof AbstractFilterModel) {
080: ((AbstractFilterModel) model).addRow(data);
081: } else {
082: throw (new IllegalStateException(
083: "Error attempting to add a row to an underlying model that is not a DefaultTableModel."));
084: }
085: }
086:
087: public void removeAllRows() throws ArrayIndexOutOfBoundsException,
088: IllegalStateException {
089: while (this .getRowCount() > 0) {
090: this .removeRow(0);
091: }
092: }
093:
094: public void removeRow(int rowNum)
095: throws ArrayIndexOutOfBoundsException,
096: IllegalStateException {
097: if (model instanceof DefaultTableModel) {
098: ((DefaultTableModel) model).removeRow(rowNum);
099: } else if (model instanceof AbstractFilterModel) {
100: ((AbstractFilterModel) model).removeRow(rowNum);
101: } else {
102: throw (new IllegalStateException(
103: "Error attempting to remove a row from an underlying model that is not a DefaultTableModel."));
104: }
105: }
106: }
|