java.lang.Object
java.util.Observable
com.pjsofts.eurobudget.DataModel
- public class DataModel
- extends java.util.Observable
It acts as the controller of all data persistent in this soft and as facade of FileData
also extends the current model to get more info.
As in MVC, it allows listeners to register to be informed about changes.
Facade of FileData to keep this one simple
also allows to remove link between FileData and Editors ..
may have multilple listeners depending on each item ...
Model: DataModel ,FileData
View: Editors (entities, bank, txn ..) that are observers of this controller
Controller: DataModel
All methods that modify data should be centralized in this class and notify
observers with this policy:
when a change reflect is made on accounts: use Account.class as argument of notify method
same for others data changes (use class that represent the data)
Warning use this notification feature with parcimony (a thousand changes on transactions should
not update thousand times a view which works on all transactions)
|
Method Summary |
void |
addAccount(com.pjsofts.eurobudget.beans.Account b)
|
void |
addBank(com.pjsofts.eurobudget.beans.Bank e)
|
void |
addDefaultCostCategories()
join current with default |
void |
addDefaultRevenueCategories()
join current with default |
void |
addEntity(com.pjsofts.eurobudget.beans.Entity e)
|
com.pjsofts.eurobudget.beans.Category |
addNewCategory(int type)
add new Main Ctg
type cost or revenu, not special |
com.pjsofts.eurobudget.beans.Category |
addNewSubCategory(com.pjsofts.eurobudget.beans.Category main,
int type)
type cost or revenu, not special |
private boolean |
checkLinksForCategory(com.pjsofts.eurobudget.beans.Category oldValue,
int type)
|
private boolean |
checkLinksForEntity(com.pjsofts.eurobudget.beans.Entity oldValue)
|
private boolean |
checkLinksForSubCategory(com.pjsofts.eurobudget.beans.CategoryPair cp,
boolean keepMainChoice)
|
com.pjsofts.eurobudget.beans.Account |
getAccount(java.lang.String name)
retrieve an account from a string name
Keep filedata in synch |
com.pjsofts.eurobudget.beans.Account |
getAccountOrCreate(java.lang.String name)
retrieve or create an account from a string name
Keep filedata in synch |
java.util.List |
getAccounts()
Getter for property accounts. |
java.util.List |
getBanks()
|
com.pjsofts.eurobudget.beans.Category |
getCategoryFromString(java.lang.String name,
int type)
retrieve or create a category from a string name
Keep filedata in synch |
java.util.SortedSet |
getCategoryGroups()
Getter for property revenueCategories. |
java.util.SortedMap |
getCostCategories()
Getter for property costCategories. |
java.util.List |
getCostCategoriesAsPair()
|
static DataModel |
getDebugDataModel()
|
static java.util.SortedSet |
getDefaultCategoryGroups()
|
static java.util.SortedMap |
getDefaultCostCategories()
return a new map of categories each time |
static java.util.SortedMap |
getDefaultRevenueCategories()
|
static java.util.List |
getDefaultSpecialCategories()
|
static com.pjsofts.eurobudget.beans.TypeOfGood[] |
getDefaultTypeOfGood()
|
java.util.List |
getEntities()
|
com.pjsofts.eurobudget.beans.Entity |
getEntityFromString(java.lang.String name)
retrieve or create an entity from a string name
Keep filedata in synch |
com.pjsofts.eurobudget.beans.FileData |
getFileData()
|
java.util.List |
getGoods(boolean modifiable)
Getter for property goods. |
com.pjsofts.eurobudget.beans.TypeOfGood[] |
getGoodTypes()
Getter for property goodTypes. |
private java.util.List |
getListOfCategoryPair(java.util.Map map,
int type,
boolean addNullChoice,
com.pjsofts.eurobudget.beans.Category mainToRemove,
com.pjsofts.eurobudget.beans.Category subToRemove)
util method |
static DataModel |
getNewDataModel()
|
com.pjsofts.eurobudget.beans.Entity |
getOwner()
Getter for property owner. |
java.util.SortedMap |
getRevenueCategories()
Getter for property revenueCategories. |
java.util.List |
getRevenueCategoriesAsPair()
|
java.util.List |
getSpecialCategories()
Getter for property revenueCategories. |
java.util.List |
getSpecialCategoriesAsPair()
|
com.pjsofts.eurobudget.beans.Category |
getSubCategoryFromString(com.pjsofts.eurobudget.beans.Category main,
java.lang.String name,
int type)
retrieve or create a category from a string name
Keep filedata in synch |
boolean |
isLinkedCategory(com.pjsofts.eurobudget.beans.Category c)
should shake all links with other data and propose another choice |
boolean |
isLinkedEntity(com.pjsofts.eurobudget.beans.Entity e)
should shake all links with other data and propose another choice |
boolean |
isNotificationOn()
Getter for property notification. |
private java.util.SortedMap |
joinCtgMaps(java.util.SortedMap map1,
java.util.SortedMap map2)
|
void |
markAllTxnAsVerified(com.pjsofts.eurobudget.beans.Account account,
java.util.Date targetDate)
Balance or Mark all transaction until this date (included) as verified. |
void |
notify(java.lang.Object arg)
convenient method to notify observers of data model changes when thoses
changes are done outside the data model class itself. |
void |
removeAccount(com.pjsofts.eurobudget.beans.Account b)
precondition: confirmation already asked to user |
private void |
removeAllRelated(com.pjsofts.eurobudget.beans.Account account)
remove all related items of this accounts (meaning not contained inside the account but outside) |
void |
removeBank(com.pjsofts.eurobudget.beans.Bank e)
|
boolean |
removeCategory(com.pjsofts.eurobudget.beans.Category c,
int type)
type cost or revenu, not special |
boolean |
removeEntity(com.pjsofts.eurobudget.beans.Entity e)
|
boolean |
removeSubCategory(com.pjsofts.eurobudget.beans.CategoryPair cp,
boolean keepMainChoice)
type cost or revenu, not special |
boolean |
renameCategory(com.pjsofts.eurobudget.beans.Category ctg,
int type,
java.lang.String newName)
type cost or revenu, not special, replace it in right place in the list |
boolean |
renameSubCategory(com.pjsofts.eurobudget.beans.CategoryPair cp,
java.lang.String newName)
type cost or revenu, not special,
replace it in right place in the list |
void |
replaceBank(com.pjsofts.eurobudget.beans.Bank oldValue,
com.pjsofts.eurobudget.beans.Bank newValue)
replace this entity by a new one everywhere |
void |
replaceCategory(com.pjsofts.eurobudget.beans.Category oldValue,
com.pjsofts.eurobudget.beans.CategoryPair newValue)
replace object's main ctg by a new pair main/sub
scan all transactions of all account and replace all category pair
that have same oldValue as main category with a newValue |
void |
replaceCategoryPair(com.pjsofts.eurobudget.beans.CategoryPair oldValue,
com.pjsofts.eurobudget.beans.CategoryPair newValue)
if oldValue.getMain is CategoryNULL, means all... |
void |
replaceEntity(com.pjsofts.eurobudget.beans.Entity srcEntity,
com.pjsofts.eurobudget.beans.Entity newEntity)
replace this entity by a new one everywhere |
void |
setAccounts(java.util.Vector v)
|
void |
setBanks(java.util.Vector v)
|
void |
setCategoryGroups(java.util.Set set)
|
void |
setCostCategories(java.util.SortedMap map)
Getter for property costCategories. |
void |
setEntities(java.util.Vector v)
sort the list and set it |
void |
setGoods(java.util.List goods)
Setter for property goods. |
void |
setGoodTypes(com.pjsofts.eurobudget.beans.TypeOfGood[] goodTypes)
Setter for property goodTypes. |
void |
setNotificationOn(boolean notificationOn)
Setter for property notification. |
void |
setOwner(com.pjsofts.eurobudget.beans.Entity e)
|
void |
setRevenueCategories(java.util.SortedMap map)
Getter for property revenueCategories. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
notificationOn
private boolean notificationOn
- Global notification flag (used to activate/desactivate it when needed like during import).
Notes on conventions on use of Observable/Observers :
DataModel will throw a notifyChange each time needed, with following argument :
- Category.class : to signal a change on Category lists
- Entity.class : to signal a change on Entity list
- Account.class : to signal a change on Category
- Bank.class : to signal a change on Bank
- null means All may have changed
fileData
private com.pjsofts.eurobudget.beans.FileData fileData
- final recipient of data ..
i18n
private static final java.util.ResourceBundle i18n
DataModel
public DataModel(com.pjsofts.eurobudget.beans.FileData fileData)
- Creates a new instance of DataModel
getFileData
public com.pjsofts.eurobudget.beans.FileData getFileData()
notify
public void notify(java.lang.Object arg)
- convenient method to notify observers of data model changes when thoses
changes are done outside the data model class itself.
setOwner
public void setOwner(com.pjsofts.eurobudget.beans.Entity e)
addEntity
public void addEntity(com.pjsofts.eurobudget.beans.Entity e)
removeEntity
public boolean removeEntity(com.pjsofts.eurobudget.beans.Entity e)
getEntities
public java.util.List getEntities()
setEntities
public void setEntities(java.util.Vector v)
- sort the list and set it
getEntityFromString
public com.pjsofts.eurobudget.beans.Entity getEntityFromString(java.lang.String name)
- retrieve or create an entity from a string name
Keep filedata in synch
isLinkedEntity
public boolean isLinkedEntity(com.pjsofts.eurobudget.beans.Entity e)
- should shake all links with other data and propose another choice
replaceEntity
public void replaceEntity(com.pjsofts.eurobudget.beans.Entity srcEntity,
com.pjsofts.eurobudget.beans.Entity newEntity)
- replace this entity by a new one everywhere
checkLinksForEntity
private boolean checkLinksForEntity(com.pjsofts.eurobudget.beans.Entity oldValue)
getBanks
public java.util.List getBanks()
setBanks
public void setBanks(java.util.Vector v)
addBank
public void addBank(com.pjsofts.eurobudget.beans.Bank e)
removeBank
public void removeBank(com.pjsofts.eurobudget.beans.Bank e)
replaceBank
public void replaceBank(com.pjsofts.eurobudget.beans.Bank oldValue,
com.pjsofts.eurobudget.beans.Bank newValue)
- replace this entity by a new one everywhere
getOwner
public com.pjsofts.eurobudget.beans.Entity getOwner()
- Getter for property owner.
getAccounts
public java.util.List getAccounts()
- Getter for property accounts.
setAccounts
public void setAccounts(java.util.Vector v)
addAccount
public void addAccount(com.pjsofts.eurobudget.beans.Account b)
markAllTxnAsVerified
public void markAllTxnAsVerified(com.pjsofts.eurobudget.beans.Account account,
java.util.Date targetDate)
- Balance or Mark all transaction until this date (included) as verified.
update last balanced date of the account
removeAccount
public void removeAccount(com.pjsofts.eurobudget.beans.Account b)
- precondition: confirmation already asked to user
removeAllRelated
private void removeAllRelated(com.pjsofts.eurobudget.beans.Account account)
- remove all related items of this accounts (meaning not contained inside the account but outside)
getAccountOrCreate
public com.pjsofts.eurobudget.beans.Account getAccountOrCreate(java.lang.String name)
- retrieve or create an account from a string name
Keep filedata in synch
getAccount
public com.pjsofts.eurobudget.beans.Account getAccount(java.lang.String name)
- retrieve an account from a string name
Keep filedata in synch
getGoodTypes
public com.pjsofts.eurobudget.beans.TypeOfGood[] getGoodTypes()
- Getter for property goodTypes.
setGoodTypes
public void setGoodTypes(com.pjsofts.eurobudget.beans.TypeOfGood[] goodTypes)
- Setter for property goodTypes.
getGoods
public java.util.List getGoods(boolean modifiable)
- Getter for property goods.
setGoods
public void setGoods(java.util.List goods)
- Setter for property goods.
getCostCategories
public java.util.SortedMap getCostCategories()
- Getter for property costCategories.
getCostCategoriesAsPair
public java.util.List getCostCategoriesAsPair()
getListOfCategoryPair
private java.util.List getListOfCategoryPair(java.util.Map map,
int type,
boolean addNullChoice,
com.pjsofts.eurobudget.beans.Category mainToRemove,
com.pjsofts.eurobudget.beans.Category subToRemove)
- util method
getRevenueCategories
public java.util.SortedMap getRevenueCategories()
- Getter for property revenueCategories.
getRevenueCategoriesAsPair
public java.util.List getRevenueCategoriesAsPair()
getSpecialCategories
public java.util.List getSpecialCategories()
- Getter for property revenueCategories.
getSpecialCategoriesAsPair
public java.util.List getSpecialCategoriesAsPair()
getCategoryGroups
public java.util.SortedSet getCategoryGroups()
- Getter for property revenueCategories.
setCategoryGroups
public void setCategoryGroups(java.util.Set set)
setCostCategories
public void setCostCategories(java.util.SortedMap map)
- Getter for property costCategories.
addDefaultCostCategories
public void addDefaultCostCategories()
- join current with default
joinCtgMaps
private java.util.SortedMap joinCtgMaps(java.util.SortedMap map1,
java.util.SortedMap map2)
setRevenueCategories
public void setRevenueCategories(java.util.SortedMap map)
- Getter for property revenueCategories.
addDefaultRevenueCategories
public void addDefaultRevenueCategories()
- join current with default
addNewCategory
public com.pjsofts.eurobudget.beans.Category addNewCategory(int type)
- add new Main Ctg
type cost or revenu, not special
getCategoryFromString
public com.pjsofts.eurobudget.beans.Category getCategoryFromString(java.lang.String name,
int type)
- retrieve or create a category from a string name
Keep filedata in synch
removeCategory
public boolean removeCategory(com.pjsofts.eurobudget.beans.Category c,
int type)
- type cost or revenu, not special
renameCategory
public boolean renameCategory(com.pjsofts.eurobudget.beans.Category ctg,
int type,
java.lang.String newName)
- type cost or revenu, not special, replace it in right place in the list
replaceCategory
public void replaceCategory(com.pjsofts.eurobudget.beans.Category oldValue,
com.pjsofts.eurobudget.beans.CategoryPair newValue)
- replace object's main ctg by a new pair main/sub
scan all transactions of all account and replace all category pair
that have same oldValue as main category with a newValue
replaceCategoryPair
public void replaceCategoryPair(com.pjsofts.eurobudget.beans.CategoryPair oldValue,
com.pjsofts.eurobudget.beans.CategoryPair newValue)
- if oldValue.getMain is CategoryNULL, means all...
replace this category pair by a new one everywhere
addNewSubCategory
public com.pjsofts.eurobudget.beans.Category addNewSubCategory(com.pjsofts.eurobudget.beans.Category main,
int type)
- type cost or revenu, not special
removeSubCategory
public boolean removeSubCategory(com.pjsofts.eurobudget.beans.CategoryPair cp,
boolean keepMainChoice)
- type cost or revenu, not special
getSubCategoryFromString
public com.pjsofts.eurobudget.beans.Category getSubCategoryFromString(com.pjsofts.eurobudget.beans.Category main,
java.lang.String name,
int type)
- retrieve or create a category from a string name
Keep filedata in synch
renameSubCategory
public boolean renameSubCategory(com.pjsofts.eurobudget.beans.CategoryPair cp,
java.lang.String newName)
- type cost or revenu, not special,
replace it in right place in the list
isLinkedCategory
public boolean isLinkedCategory(com.pjsofts.eurobudget.beans.Category c)
- should shake all links with other data and propose another choice
checkLinksForCategory
private boolean checkLinksForCategory(com.pjsofts.eurobudget.beans.Category oldValue,
int type)
checkLinksForSubCategory
private boolean checkLinksForSubCategory(com.pjsofts.eurobudget.beans.CategoryPair cp,
boolean keepMainChoice)
getDefaultCostCategories
public static java.util.SortedMap getDefaultCostCategories()
- return a new map of categories each time
getDefaultRevenueCategories
public static java.util.SortedMap getDefaultRevenueCategories()
getDefaultSpecialCategories
public static java.util.List getDefaultSpecialCategories()
getDefaultCategoryGroups
public static java.util.SortedSet getDefaultCategoryGroups()
getDefaultTypeOfGood
public static com.pjsofts.eurobudget.beans.TypeOfGood[] getDefaultTypeOfGood()
getNewDataModel
public static DataModel getNewDataModel()
getDebugDataModel
public static DataModel getDebugDataModel()
isNotificationOn
public boolean isNotificationOn()
- Getter for property notification.
setNotificationOn
public void setNotificationOn(boolean notificationOn)
- Setter for property notification.