001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.table; 017 018 import java.util.List; 019 020 /** 021 * Designed to display object arrays / lists in a list for multi-column tables, 022 * or just plain objects for single column table. Nicely aligned with Hibernate 023 * List behaivior for query result sets. 024 * 025 * @author keith 026 */ 027 public abstract class ListTableModel extends BaseTableModel { 028 029 public ListTableModel() { 030 super(); 031 } 032 033 public ListTableModel(List rows) { 034 super(rows); 035 } 036 037 protected Object getValueAtInternal(Object row, int columnIndex) { 038 if (row != null && getDataColumnCount() > 1) { 039 if (row.getClass().isArray()) { 040 Object[] arrayRow = (Object[])row; 041 return arrayRow[columnIndex]; 042 } 043 else if (row instanceof List) { 044 return ((List)row).get(columnIndex); 045 } 046 else { 047 throw new IllegalArgumentException("Unsupported row collection type " + row); 048 } 049 } 050 051 if (row != null && row.getClass().isArray()) 052 return ((Object[])row)[0]; 053 054 return row; 055 } 056 }