edu.harvard.deas.hyperenc.gui
Class MessageTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by edu.harvard.deas.hyperenc.gui.MessageTableModel
All Implemented Interfaces:
Serializable, TableModel

public class MessageTableModel
extends AbstractTableModel

A TableModel backed by a MessageStorage object. Displays a list of messages stored in a MessageStorage, one message per row, with selected fields of the message (for example: subject, sender, date) displayed in each of several columns.

TODO document how to use this -- when are update events fired, etc. TODO store all messages and use a filter instead of the ridiculous acrobatics we do now TODO this whole class sucks -- replace with a simpler version (use RowFilter)

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
MessageTableModel(MessageStorage msgStorage)
          TODO document constructor
 
Method Summary
 void addMessage(GuiMessage gm)
          Adds a new GuiMessage to the underlying MessageStorage.
 Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 String getColumnName(int column)
           
 GuiMessage getMessageAtRow(int rowNum)
          Returns the GuiMessage represented by the specified row.
 int getRowCount()
           
 Contact getSelectedSender()
          Returns the sender for which this model is set to show messages.
 Object getValueAt(int rowIndex, int columnIndex)
           
 boolean isCellEditable(int row, int col)
          Always returns false; no cells are editable.
 void markRead(int rowNum)
          Marks the GuiMessage in the specified row as read.
 void markUnread(int rowNum)
          Marks the GuiMessage in the specified row as unread.
 void removeMessage(int id)
          Removes the GuiMessage with the given ID from the underlying MessageStorage.
 GuiMessage replaceMessageAtRow(int rowNum, GuiMessage gm)
          Replaces the GuiMessage in row rowNum with gm.
 void selectSender(Contact contact)
          Sets this model to show only those messages in the HyperStorage from the given sender.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageTableModel

public MessageTableModel(MessageStorage msgStorage)
TODO document constructor

Parameters:
msgStorage -
Method Detail

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class<?> getColumnClass(int column)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Always returns false; no cells are editable.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Returns:
false

selectSender

public void selectSender(Contact contact)
Sets this model to show only those messages in the HyperStorage from the given sender. Fires an event to indicate that the table data has changed.

Parameters:
contact - e-mail contact of the desired sender

getSelectedSender

public Contact getSelectedSender()
Returns the sender for which this model is set to show messages.

See Also:
selectSender(Contact)

addMessage

public void addMessage(GuiMessage gm)
Adds a new GuiMessage to the underlying MessageStorage. Fires an event to indicate that the table has been updated.

Parameters:
gm - the message to add

getMessageAtRow

public GuiMessage getMessageAtRow(int rowNum)
Returns the GuiMessage represented by the specified row.

Parameters:
rowNum - a row number
Returns:
the GuiMessage in the given row

replaceMessageAtRow

public GuiMessage replaceMessageAtRow(int rowNum,
                                      GuiMessage gm)
Replaces the GuiMessage in row rowNum with gm.

Parameters:
rowNum - the row to place the message in
gm - the new message to insert
Returns:
the message that was replaced (the message that was originally in the specified row)

markRead

public void markRead(int rowNum)
Marks the GuiMessage in the specified row as read.

Parameters:
rowNum - the row to mark read

markUnread

public void markUnread(int rowNum)
Marks the GuiMessage in the specified row as unread.

Parameters:
rowNum - the row to mark unread

removeMessage

public void removeMessage(int id)
Removes the GuiMessage with the given ID from the underlying MessageStorage. Fires an event to indicate that the table has been updated.

Parameters:
id - the message ID to remove