Coverage Report - org.homeunix.thecave.buddi.model.impl.WrapperLists
 
Classes in this File Line Coverage Branch Coverage Complexity
WrapperLists
0%
0/1
N/A
2.2
WrapperLists$BuddiWrapperList
0%
0/6
N/A
2.2
WrapperLists$BuddiWrapperList$1
0%
0/3
N/A
2.2
WrapperLists$ImmutableAccountList
0%
0/5
N/A
2.2
WrapperLists$ImmutableObjectWrapperList
0%
0/17
0%
0/12
2.2
 
 1  
 /*
 2  
  * Created on Aug 4, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.model.impl;
 5  
 
 6  
 import java.util.List;
 7  
 
 8  
 import org.homeunix.thecave.buddi.model.Account;
 9  
 import org.homeunix.thecave.buddi.model.AccountType;
 10  
 import org.homeunix.thecave.buddi.model.BudgetCategory;
 11  
 import org.homeunix.thecave.buddi.model.Document;
 12  
 import org.homeunix.thecave.buddi.model.ModelObject;
 13  
 import org.homeunix.thecave.buddi.model.ScheduledTransaction;
 14  
 import org.homeunix.thecave.buddi.model.Transaction;
 15  
 import org.homeunix.thecave.buddi.model.TransactionSplit;
 16  
 import org.homeunix.thecave.buddi.plugin.api.model.ImmutableAccount;
 17  
 import org.homeunix.thecave.buddi.plugin.api.model.ImmutableModelObject;
 18  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.ImmutableAccountImpl;
 19  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableAccountImpl;
 20  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableAccountTypeImpl;
 21  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableBudgetCategoryImpl;
 22  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableScheduledTransactionImpl;
 23  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableTransactionImpl;
 24  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableTransactionSplitImpl;
 25  
 
 26  
 import ca.digitalcave.moss.application.document.DocumentChangeEvent;
 27  
 import ca.digitalcave.moss.application.document.DocumentChangeListener;
 28  
 import ca.digitalcave.moss.collections.WrapperList;
 29  
 
 30  
 public class WrapperLists {
 31  
 
 32  0
         private WrapperLists() {}
 33  
 
 34  
         private abstract static class BuddiWrapperList<T, W> extends WrapperList<T, W> {
 35  
                 private final Document model;
 36  
                 private final DocumentChangeListener listener;
 37  
                 
 38  
                 public BuddiWrapperList(Document model, List<W> wrappedList, boolean sorted) {
 39  0
                         super(wrappedList, sorted);
 40  0
                         this.model = model;
 41  
                         
 42  0
                         listener = new DocumentChangeListener(){
 43  
                                 public void documentChange(DocumentChangeEvent event) {
 44  0
                                         updateWrapperList();
 45  0
                                 }
 46  
                         };
 47  
                         
 48  0
                         model.addDocumentChangeListener(listener);
 49  0
                 }
 50  
 
 51  
                 public Document getDataModel(){
 52  0
                         return model;
 53  
                 }
 54  
         }
 55  
 
 56  
 //        public static class WrapperBudgetPeriodList extends BuddiWrapperList<BudgetPeriod, BudgetPeriodBean>{
 57  
 //        public WrapperBudgetPeriodList(DataModel model, List<BudgetPeriodBean> wrappedList) {
 58  
 //        super(model, wrappedList, true);
 59  
 //        }
 60  
 
 61  
 //        @Override
 62  
 //        public BudgetPeriodBean getWrappedObject(BudgetPeriod object) {
 63  
 //        return object.getBudgetPeriodBean();
 64  
 //        }
 65  
 
 66  
 //        @Override
 67  
 //        public BudgetPeriod getWrapperObject(BudgetPeriodBean object) {
 68  
 //        return new BudgetPeriod(getDataModel(), object);
 69  
 //        }
 70  
 //        }
 71  
 
 72  0
         public static class ImmutableAccountList extends BuddiWrapperList<ImmutableAccount, Account> {
 73  
                 public ImmutableAccountList(Document model, List<Account> wrappedList) {
 74  0
                         super(model, wrappedList, true);
 75  0
                 }
 76  
 
 77  
                 @Override
 78  
                 public Account getWrappedObject(ImmutableAccount object) {
 79  0
                         return (Account) object.getRaw();
 80  
                 }
 81  
 
 82  
                 @Override
 83  
                 public ImmutableAccount getWrapperObject(Account object) {
 84  0
                         return new ImmutableAccountImpl(object);
 85  
                 }
 86  
         }
 87  
 
 88  0
         public static class ImmutableObjectWrapperList<T extends ImmutableModelObject, W extends ModelObject> extends BuddiWrapperList<T, W> {
 89  
                 public ImmutableObjectWrapperList(Document model, List<W> wrappedList) {
 90  0
                         super(model, wrappedList, true);
 91  0
                 }
 92  
 
 93  
                 @SuppressWarnings("unchecked")
 94  
                 @Override
 95  
                 public W getWrappedObject(T object) {
 96  0
                         return (W) object.getRaw();
 97  
                 }
 98  
 
 99  
                 @SuppressWarnings("unchecked")
 100  
                 @Override
 101  
                 public T getWrapperObject(W object) {
 102  0
                         if (object instanceof Account)
 103  0
                                 return (T) new MutableAccountImpl((Account) object);
 104  0
                         if (object instanceof BudgetCategory)
 105  0
                                 return (T) new MutableBudgetCategoryImpl((BudgetCategory) object);
 106  0
                         if (object instanceof Transaction)
 107  0
                                 return (T) new MutableTransactionImpl((Transaction) object);
 108  0
                         if (object instanceof ScheduledTransaction)
 109  0
                                 return (T) new MutableScheduledTransactionImpl((ScheduledTransaction) object);
 110  0
                         if (object instanceof AccountType)
 111  0
                                 return (T) new MutableAccountTypeImpl((AccountType) object);
 112  0
                         if (object instanceof TransactionSplit)
 113  0
                                 return (T) new MutableTransactionSplitImpl((TransactionSplit) object);
 114  
 
 115  
                         //Catch all
 116  0
                         return null;
 117  
                 }
 118  
         }
 119  
 }