001: package org.apache.lucene.swing.models;
002:
003: /**
004: * Copyright 2005 The Apache Software Foundation
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import javax.swing.table.AbstractTableModel;
020: import java.util.ArrayList;
021: import java.util.Iterator;
022:
023: /**
024: * @author Jonathan Simon - jonathan_s_simon@yahoo.com
025: */
026: public class BaseTableModel extends AbstractTableModel {
027: private ArrayList columnNames = new ArrayList();
028: private ArrayList rows = new ArrayList();
029:
030: public BaseTableModel(Iterator data) {
031: columnNames.add("Name");
032: columnNames.add("Type");
033: columnNames.add("Phone");
034: columnNames.add("Street");
035: columnNames.add("City");
036: columnNames.add("State");
037: columnNames.add("Zip");
038:
039: while (data.hasNext()) {
040: Object nextRow = (Object) data.next();
041: rows.add(nextRow);
042: }
043: }
044:
045: public int getColumnCount() {
046: return columnNames.size();
047: }
048:
049: public int getRowCount() {
050: return rows.size();
051: }
052:
053: public void addRow(RestaurantInfo info) {
054: rows.add(info);
055: fireTableDataChanged();
056: }
057:
058: public void removeRow(RestaurantInfo info) {
059: rows.remove(info);
060: fireTableDataChanged();
061: }
062:
063: public boolean isCellEditable(int rowIndex, int columnIndex) {
064: return false;
065: }
066:
067: public Class getColumnClass(int columnIndex) {
068: return String.class;
069: }
070:
071: public Object getValueAt(int rowIndex, int columnIndex) {
072: RestaurantInfo restaurantInfo = (RestaurantInfo) rows
073: .get(rowIndex);
074: if (columnIndex == 0) { // name
075: return restaurantInfo.getName();
076: } else if (columnIndex == 1) { // category
077: return restaurantInfo.getType();
078: } else if (columnIndex == 2) { // phone
079: return restaurantInfo.getPhone();
080: } else if (columnIndex == 3) { // street
081: return restaurantInfo.getStreet();
082: } else if (columnIndex == 4) { // city
083: return restaurantInfo.getCity();
084: } else if (columnIndex == 5) { // state
085: return restaurantInfo.getState();
086: } else if (columnIndex == 6) { // zip
087: return restaurantInfo.getZip();
088: } else {
089: return "";
090: }
091: }
092:
093: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
094: //no op
095: }
096:
097: public String getColumnName(int columnIndex) {
098: return columnNames.get(columnIndex).toString();
099: }
100:
101: }
|