001 /* 002 * This program is free software; you can redistribute it and/or modify 003 * it under the terms of the GNU General Public License as published by 004 * the Free Software Foundation; version 2 of the License. 005 * 006 * This program is distributed in the hope that it will be useful, 007 * but WITHOUT ANY WARRANTY; without even the implied warranty of 008 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 009 * GNU General Public License for more details. 010 * 011 * You should have received a copy of the GNU General Public License along 012 * with this program; if not, write to the Free Software Foundation, Inc., 013 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 014 */ 015 package org.tastybug.bugwerk.bugtrail.widget.ticket; 016 017 import javax.swing.table.AbstractTableModel; 018 019 import org.tastybug.bugwerk.blueprint.model.Ticket; 020 021 /** 022 * Models the content of <code>TicketTable</code>. 023 * <br> 024 * 025 * <hr> 026 * Copyright 2006 Philipp Bartsch.<br> 027 * <a href="http://www.tastybug.com">www.tastybug.com</a><br> 028 * <hr> 029 * Created on Feb 8, 2006<br> 030 * @author Philipp Bartsch, philipp.bartsch{at}tastybug{dot}com</a> 031 */ 032 public class TicketTableModel extends AbstractTableModel { 033 034 035 /**The <code>serialVersionUID</code>*/ 036 private static final long serialVersionUID = -3951294211435738836L; 037 038 private Ticket ticket; 039 private String[] keys; 040 041 /** 042 * Creates the model upon the given ticket. 043 * 044 * @param _ticket the ticket that is to be displayed 045 */ 046 protected TicketTableModel (final Ticket _ticket) { 047 update(_ticket); 048 } 049 050 /** 051 * Re-reads the ticket, as it has changed. 052 * 053 * @param changedTicket the changed ticket 054 */ 055 public void update (final Ticket changedTicket) { 056 this.ticket = changedTicket; 057 if (ticket == null) { 058 keys = new String[0]; 059 } else { 060 keys = (String[]) ticket.getAsMap().keySet().toArray(new String[0]); 061 } 062 } 063 064 /** 065 * Returns an empty string, no column headers used. 066 * 067 * @see javax.swing.table.AbstractTableModel#getColumnName(int) 068 */ 069 public String getColumnName(int col) { 070 return ""; 071 } 072 073 /** 074 * Returns 2; 075 * 076 * @see javax.swing.table.TableModel#getColumnCount() 077 */ 078 public int getColumnCount() { 079 return 2; 080 } 081 082 /** 083 * Returns <code>false</code>, the table is not editable. 084 * 085 * @return <code>false</code> 086 */ 087 public boolean isEditable () { 088 return false; 089 } 090 091 /** 092 * Returns the number of present base properties. 093 * 094 * @see javax.swing.table.TableModel#getRowCount() 095 */ 096 public int getRowCount() { 097 return keys.length; 098 } 099 100 /** 101 * Returns a table cell value. 102 * 103 * @see javax.swing.table.TableModel#getValueAt(int, int) 104 */ 105 public Object getValueAt(int row, int col) { 106 if (col == 0) { 107 return keys[row]; 108 } else if (keys.length == 0 || row > keys.length) { 109 return ""; 110 } else { 111 return ticket.getAsMap().get(keys[row]); 112 } 113 } 114 115 /** 116 * Returns <code>String.class</code>. 117 * 118 * @see javax.swing.table.AbstractTableModel#getColumnClass(int) 119 */ 120 public Class getColumnClass(int c) { 121 return String.class; 122 } 123 }