1 /* 2 * Copyright (c) 2003-2008 by Cosylab d. d. 3 * 4 * This file is part of CosyBeans-Common. 5 * 6 * CosyBeans-Common is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * CosyBeans-Common is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package com.cosylab.gui.components.table; 21 22 import com.cosylab.gui.components.table.cells.TableCell; 23 24 25 /** 26 * Default implementation of the ObjectTableEngine. 27 * 28 */ 29 public class DefaultObjectTableEngine implements ObjectTableEngine 30 { 31 32 public DefaultObjectTableEngine() 33 { 34 super(); 35 } 36 37 /* (non-Javadoc) 38 * @see com.cosylab.gui.components.table.TableRowFactory#getTableRow(java.lang.Object) 39 */ 40 public TableRow getTableRow(Object key) 41 { 42 TableCell[] tc = getTableCells(key); 43 44 TableRowArray rta = new TableRowArray(); 45 46 for (int i = 0; i < tc.length; i++) { 47 rta.addValue(tc[i]); 48 } 49 50 return rta; 51 52 } 53 54 /* (non-Javadoc) 55 * @see com.cosylab.gui.components.table.TableRowFactory#releaseTableRow(java.lang.Object, com.cosylab.gui.components.table.TableRow) 56 */ 57 public void releaseTableRow(Object key, TableRow row) 58 { 59 // not used 60 } 61 62 /** 63 * Override this method to convert key object to own array of 64 * <code>TableCell</code> instances. Default implementation creates for 65 * each object own <code>TableCell</code> and returns it in an array. 66 * 67 * @param key key object 68 * 69 * @return array of table cells 70 */ 71 protected TableCell[] getTableCells(Object key) 72 { 73 if (key instanceof Object[]) { 74 Object[] o = (Object[])key; 75 76 TableCell[] tc = new TableCell[o.length]; 77 78 for (int i = 0; i < o.length; i++) { 79 tc[i] = new TableCell(null, o[i], o[i], null); 80 } 81 } 82 83 return new TableCell[]{ new TableCell(null, key, key, null) }; 84 } 85 86 /** 87 * Dummy implementation: casts row element to TableCell and sets value 88 * @see com.cosylab.gui.components.table.ObjectTableEngine#setValue(Object, Object, TableRow, int) 89 */ 90 public void setValue(Object value, Object key, TableRow row, int col) { 91 TableCell r= (TableCell)row.getValueAt(col); 92 r.setValue(value); 93 } 94 95 /* (non-Javadoc) 96 * @see com.cosylab.gui.components.table.ObjectTableEngine#getColumnName(int) 97 */ 98 public String getColumnName(int i) { 99 return null; 100 } 101 } 102 103 /* __oOo__ */