edu.jhu.tmaj.client.tables.data
Class GeneralTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by edu.jhu.tmaj.client.tables.data.GeneralTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
BeanTableModel

public class GeneralTableModel
extends javax.swing.table.AbstractTableModel

The TableModel used for JTables in TMAJ. This class makes sure that no outside classes modify its table-data, that is the column identifiers and the list of lists that represent the data in the cells. This is imperative for protecting the data structure of this class. For example, if a class were to get a reference to columnIdentifiers and remove an element, it would leave this class in an inconsistent state. All changes to the data in the table must go through this class. When a user changes data in this TableModel, the JTable is notified as this class fires off events.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
GeneralTableModel()
           
GeneralTableModel(java.util.List list_of_lists, java.util.List fieldNames)
           
 
Method Summary
 void addRow(java.util.List rowList)
           
 void clearRows()
           
static java.util.List<java.lang.String> convertListOfMaps_TO_ListOfTabDelimitedStrings(java.util.List<java.util.Map> listOfMaps, java.util.List fieldNames)
           
static java.util.List<java.lang.String> convertToListOfTabDelimitedStrings(GeneralTableModel tableModel)
          Converts a TableModel to a list of tab-delimited Strings.
 int findColumn(java.lang.String columnName)
           
 int getColumnCount()
           
 java.util.List getColumnIdentifiers()
           
 java.lang.String getColumnName(int column)
           
 java.util.List<java.util.List> getDataList()
          Returns a List of Lists that represents the objects in the table's cells.
static java.util.List getNumberedList(int startNumber, int length)
          Returns a String array starting with the startNumber.
 int getRowCount()
           
 java.lang.Object getValueAt(int row, int column)
           
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false.
 void removeRow(int row)
           
 void setColumnIdentifiers(java.util.List newColumnIdentifiers)
           
 void setData(java.util.List<java.util.List> dataList, java.util.List columnIdentifiers)
           
 void setDataList(java.util.List dataList)
           
 void setValueAt(java.lang.Object aValue, int row, int column)
           
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralTableModel

public GeneralTableModel()

GeneralTableModel

public GeneralTableModel(java.util.List list_of_lists,
                         java.util.List fieldNames)
Method Detail

getColumnCount

public final int getColumnCount()

getRowCount

public final int getRowCount()

getValueAt

public final java.lang.Object getValueAt(int row,
                                         int column)

getColumnName

public final java.lang.String getColumnName(int column)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

findColumn

public final int findColumn(java.lang.String columnName)
Overrides:
findColumn in class javax.swing.table.AbstractTableModel

setDataList

public final void setDataList(java.util.List dataList)

setData

public final void setData(java.util.List<java.util.List> dataList,
                          java.util.List columnIdentifiers)

clearRows

public final void clearRows()

removeRow

public final void removeRow(int row)

addRow

public final void addRow(java.util.List rowList)

setColumnIdentifiers

public final void setColumnIdentifiers(java.util.List newColumnIdentifiers)

getColumnIdentifiers

public final java.util.List getColumnIdentifiers()

getDataList

public final java.util.List<java.util.List> getDataList()
Returns a List of Lists that represents the objects in the table's cells. Trying to modify these Lists will result in an UnsupportedOperationException. The only way table data should be modified is through this class. It is still possible to change objects in this list, but this should be avoided.


setValueAt

public final void setValueAt(java.lang.Object aValue,
                             int row,
                             int column)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns false.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel

convertListOfMaps_TO_ListOfTabDelimitedStrings

public static java.util.List<java.lang.String> convertListOfMaps_TO_ListOfTabDelimitedStrings(java.util.List<java.util.Map> listOfMaps,
                                                                                              java.util.List fieldNames)

convertToListOfTabDelimitedStrings

public static java.util.List<java.lang.String> convertToListOfTabDelimitedStrings(GeneralTableModel tableModel)
Converts a TableModel to a list of tab-delimited Strings. This List can then be written to a file.


getNumberedList

public static java.util.List getNumberedList(int startNumber,
                                             int length)
Returns a String array starting with the startNumber. This method is made to create the column numbers for a JTable in a JScrollPane. (If you do not put a JTable in a JScrollPane, you will not see the columns.) If the startNumber is not 0, the displayed columnNumber will not match the TableModel Number. For example, if the startNumber if 1, the tableModel number will be 1 less than the displayed number. Example: getNumberList(1,5) would return {"1","2","3","4","5"}