org.jbudget.gui.month
Class DatesInfoTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.jbudget.gui.month.DatesInfoTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, EventDispatcher.AccountListener, EventDispatcher.AllocationListener, EventDispatcher.TransactionListener, EventDispatcher.UserListener

public class DatesInfoTableModel
extends javax.swing.table.AbstractTableModel
implements EventDispatcher.TransactionListener, EventDispatcher.AllocationListener, EventDispatcher.UserListener, EventDispatcher.AccountListener

Model for the table that displays the daily income/expense/balance data for different categories.

Author:
petrov
See Also:
Serialized Form

Nested Class Summary
static class DatesInfoTableModel.CellData
          A class that is used to return the data that represents the cell
static class DatesInfoTableModel.State
          A class that describes the state of the table model.
 
Field Summary
protected  java.util.Calendar calendar
          A calendar instance.
(package private)  java.util.List<java.util.List<DatesInfoTableModel.CellData>> data
          List of cell data.
(package private)  DatesTableModel datesTableModel
          A model that gets the appropriate day of the month.
(package private)  java.util.Set<org.jbudget.Core.MoneyPit> emptyItems
          A set of MoneyPit objects that correspond to empty (zero balance) accounts or expense categories.
(package private)  java.util.Set<org.jbudget.Core.MoneyPit> idleItems
          A list of MoneyPit objects that correspond to idle (no transactions or allocations) accounts or expense categories.
(package private)  java.util.List<java.util.List<org.jbudget.Core.MoneyPit>> items
          List of Budget items associated with columns.
(package private)  org.jbudget.Core.Month month
          The month.
(package private)  java.util.List<java.lang.String> names
          List of column names.
private  DatesInfoTableModel.State state
          State object that describes what columns should be created.
(package private)  java.util.List<java.lang.String> toolTips
          List of tool tips for columns.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DatesInfoTableModel(DatesInfoTableModel otherModel)
          copy constructor
DatesInfoTableModel(org.jbudget.Core.Month month, DatesTableModel datesTableModel)
          Creates a new instance of DeatesInfoTableModel
DatesInfoTableModel(org.jbudget.Core.Month month, DatesTableModel datesTableModel, DatesInfoTableModel.State state)
          Creates a new instance of DeatesInfoTableModel
 
Method Summary
 void accountAdded(org.jbudget.Core.Account account)
           
 void accountRemoved(int accountId)
           
 void accountUpdated(org.jbudget.Core.Account account)
           
 void allocationAdded(org.jbudget.Core.Transaction allocation)
          Called when an allocation is added to the month.
 void allocationRemoved(java.util.List<org.jbudget.Core.Transaction.Transfer> transfers, int cDay, int cMonth, int cYear)
          Called when an allocation is removed from the month.
private  boolean checkMoneyPit(org.jbudget.Core.MoneyPit pit)
          This method is used to check if a transaction/allocation has the source or a destination that was hidden because it is empty (zero balance) or idle (no trancations = constant balance)
 void collapseColumn(int columnIndex)
          Collapses a column that corresponds to an expense category with subcategories.
 void collapseParent(int columnIndex)
          Collapses a parent category of the category corresponding to the selected column
 void dispose()
          cleans up
 void expandColumn(int columnIndex)
          Expands a column that was previously collapsed.
 void fireTableStructureChanged()
           
 java.lang.String generateToolTip(int rowIndex, int columnIndex)
          A method that constructs the tool tip for a cell in the table.
 java.lang.Class getColumnClass(int index)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int index)
           
 java.lang.String getColumnToolTip(int index)
           
(package private)  java.util.List<org.jbudget.Core.Account> getEmptyAccounts()
          Returns a list of accounts that have zero balance in every day in the current month.
(package private)  java.util.List<org.jbudget.Core.ExpenseCategory> getEmptyCategories()
          Returns a list of expense categories that have zero balance in every day in the current month.
(package private)  java.util.List<org.jbudget.Core.Account> getInactiveAccounts()
          Returns a list of accounts that have no transactions recorded in the current month.
(package private)  java.util.List<org.jbudget.Core.ExpenseCategory> getInactiveCategories()
          Returns a list of expense categories that have no transactions or allocations in the current month.
 java.util.List<org.jbudget.Core.MoneyPit> getItemsForColumn(int columnIndex)
          List of accounts/categories for a given columnIndex.
 org.jbudget.Core.Month getMonth()
          Returns the month object associated with the model
 int getRowCount()
           
 DatesInfoTableModel.State getState()
          Returns the State object used by this model
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 void hideColumn(int columnIndex)
          Marks the account or the root expense category in the column as hidden
private  void initializeData()
          Creates cell data cache.
private  void initializeItems()
          Initializes items and names lists.
 boolean isCollapsable(int columnIndex)
           
 boolean isExpandable(int columnIndex)
           
 boolean isParentCollapsable(int columnIndex)
           
 void setState(DatesInfoTableModel.State state)
          Changes the State object.
 void transactionAdded(org.jbudget.Core.Transaction transaction)
          Called when a transaction is added to the month.
 void transactionRemoved(java.util.List<org.jbudget.Core.Transaction.Transfer> transfers, int cDay, int cMonth, int cYear)
          Called when a transaction is removed from the month.
private  void updateCells(org.jbudget.Core.MoneyPit pit1, org.jbudget.Core.MoneyPit pit2, java.util.Date date)
          Updates cells that correspond to the given MoneyPit objects.
private  void updateData(int column, int row, boolean notify)
          Updates cached data for a given cell.
private  void updateModel()
          Reinitializes the table structure and data
 void userAdded(org.jbudget.Core.User user)
           
 void userChanged(org.jbudget.Core.User user)
           
 void userRemoved(int uid)
           
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

final java.util.List<java.util.List<org.jbudget.Core.MoneyPit>> items
List of Budget items associated with columns.


emptyItems

final java.util.Set<org.jbudget.Core.MoneyPit> emptyItems
A set of MoneyPit objects that correspond to empty (zero balance) accounts or expense categories.


idleItems

final java.util.Set<org.jbudget.Core.MoneyPit> idleItems
A list of MoneyPit objects that correspond to idle (no transactions or allocations) accounts or expense categories.


names

final java.util.List<java.lang.String> names
List of column names.


toolTips

final java.util.List<java.lang.String> toolTips
List of tool tips for columns.


data

final java.util.List<java.util.List<DatesInfoTableModel.CellData>> data
List of cell data. Fist list is the same as items, the second list is over all dates.


datesTableModel

final DatesTableModel datesTableModel
A model that gets the appropriate day of the month.


month

final org.jbudget.Core.Month month
The month.


calendar

protected final java.util.Calendar calendar
A calendar instance.


state

private DatesInfoTableModel.State state
State object that describes what columns should be created.

Constructor Detail

DatesInfoTableModel

public DatesInfoTableModel(org.jbudget.Core.Month month,
                           DatesTableModel datesTableModel)
Creates a new instance of DeatesInfoTableModel


DatesInfoTableModel

public DatesInfoTableModel(org.jbudget.Core.Month month,
                           DatesTableModel datesTableModel,
                           DatesInfoTableModel.State state)
Creates a new instance of DeatesInfoTableModel


DatesInfoTableModel

public DatesInfoTableModel(DatesInfoTableModel otherModel)
copy constructor

Method Detail

dispose

public void dispose()
cleans up


setState

public void setState(DatesInfoTableModel.State state)
Changes the State object.


getState

public DatesInfoTableModel.State getState()
Returns the State object used by this model


getMonth

public org.jbudget.Core.Month getMonth()
Returns the month object associated with the model


updateModel

private void updateModel()
Reinitializes the table structure and data


initializeItems

private void initializeItems()
Initializes items and names lists. Creates the lists of MoneyPit objects that are included in the items list depending on the flag values.


initializeData

private void initializeData()
Creates cell data cache. Creates a CellData object for every cell and stores it in the data object.


updateData

private void updateData(int column,
                        int row,
                        boolean notify)
Updates cached data for a given cell.

Parameters:
notify - if true the table(listeners) will be notified that the content of the cell changed.

getColumnClass

public java.lang.Class getColumnClass(int index)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

getColumnName

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

getColumnToolTip

public java.lang.String getColumnToolTip(int index)

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface javax.swing.table.TableModel

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface javax.swing.table.TableModel

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Specified by:
getValueAt in interface javax.swing.table.TableModel

getItemsForColumn

public java.util.List<org.jbudget.Core.MoneyPit> getItemsForColumn(int columnIndex)
List of accounts/categories for a given columnIndex. For a given columnIndex in the table returns an unmodifiable list of accounts or expense categories that correspond to the columnIndex.


hideColumn

public void hideColumn(int columnIndex)
Marks the account or the root expense category in the column as hidden


collapseColumn

public void collapseColumn(int columnIndex)
Collapses a column that corresponds to an expense category with subcategories. Has no effect for all other types of columns.


collapseParent

public void collapseParent(int columnIndex)
Collapses a parent category of the category corresponding to the selected column


expandColumn

public void expandColumn(int columnIndex)
Expands a column that was previously collapsed. Has no effect for other kinds of columns.


isExpandable

public boolean isExpandable(int columnIndex)

isCollapsable

public boolean isCollapsable(int columnIndex)

isParentCollapsable

public boolean isParentCollapsable(int columnIndex)

generateToolTip

public java.lang.String generateToolTip(int rowIndex,
                                        int columnIndex)
A method that constructs the tool tip for a cell in the table.


transactionAdded

public void transactionAdded(org.jbudget.Core.Transaction transaction)
Called when a transaction is added to the month.

Specified by:
transactionAdded in interface EventDispatcher.TransactionListener

transactionRemoved

public void transactionRemoved(java.util.List<org.jbudget.Core.Transaction.Transfer> transfers,
                               int cDay,
                               int cMonth,
                               int cYear)
Called when a transaction is removed from the month.

Specified by:
transactionRemoved in interface EventDispatcher.TransactionListener

allocationAdded

public void allocationAdded(org.jbudget.Core.Transaction allocation)
Called when an allocation is added to the month.

Specified by:
allocationAdded in interface EventDispatcher.AllocationListener

allocationRemoved

public void allocationRemoved(java.util.List<org.jbudget.Core.Transaction.Transfer> transfers,
                              int cDay,
                              int cMonth,
                              int cYear)
Called when an allocation is removed from the month.

Specified by:
allocationRemoved in interface EventDispatcher.AllocationListener

checkMoneyPit

private boolean checkMoneyPit(org.jbudget.Core.MoneyPit pit)
This method is used to check if a transaction/allocation has the source or a destination that was hidden because it is empty (zero balance) or idle (no trancations = constant balance)


userAdded

public void userAdded(org.jbudget.Core.User user)
Specified by:
userAdded in interface EventDispatcher.UserListener

userRemoved

public void userRemoved(int uid)
Specified by:
userRemoved in interface EventDispatcher.UserListener

userChanged

public void userChanged(org.jbudget.Core.User user)
Specified by:
userChanged in interface EventDispatcher.UserListener

accountAdded

public void accountAdded(org.jbudget.Core.Account account)
Specified by:
accountAdded in interface EventDispatcher.AccountListener

accountRemoved

public void accountRemoved(int accountId)
Specified by:
accountRemoved in interface EventDispatcher.AccountListener

accountUpdated

public void accountUpdated(org.jbudget.Core.Account account)
Specified by:
accountUpdated in interface EventDispatcher.AccountListener

updateCells

private void updateCells(org.jbudget.Core.MoneyPit pit1,
                         org.jbudget.Core.MoneyPit pit2,
                         java.util.Date date)
Updates cells that correspond to the given MoneyPit objects. All rows that correspond to dates after the given date(inclusive) are updated. Used to handle transaction and allocation added/removed events.


fireTableStructureChanged

public void fireTableStructureChanged()
Overrides:
fireTableStructureChanged in class javax.swing.table.AbstractTableModel

getEmptyAccounts

java.util.List<org.jbudget.Core.Account> getEmptyAccounts()
Returns a list of accounts that have zero balance in every day in the current month. This is equivalent to having zero starting balance and no transactions (Assuming nonzero transaction amounts).


getInactiveAccounts

java.util.List<org.jbudget.Core.Account> getInactiveAccounts()
Returns a list of accounts that have no transactions recorded in the current month.


getEmptyCategories

java.util.List<org.jbudget.Core.ExpenseCategory> getEmptyCategories()
Returns a list of expense categories that have zero balance in every day in the current month. This is equivalent to having zero starting balance and no transactions or allocations. (Assuming nonzero transaction amounts).


getInactiveCategories

java.util.List<org.jbudget.Core.ExpenseCategory> getInactiveCategories()
Returns a list of expense categories that have no transactions or allocations in the current month.