001 package videoautomat; 002 import sale.Gate; 003 import sale.SaleProcess; 004 import sale.SalesPoint; 005 import sale.UIGate; 006 import sale.stdforms.FormSheetStrategy; 007 import videoautomat.contentcreator.RentConfirmFSContentCreator; 008 import videoautomat.contentcreator.RentPayFSContentCreator; 009 import videoautomat.contentcreator.RentTTFSContentCreator; 010 import data.DataBasketConditionImpl; 011 import data.NumberValue; 012 import data.ooimpl.MoneyBagImpl; 013 import data.stdforms.SingleTableFormSheet; 014 import data.stdforms.TwoTableFormSheet; 015 import data.stdforms.twotableformsheet.CCSStrategy; 016 import data.stdforms.twotableformsheet.CSDBStrategy; 017 import data.swing.DefaultStoringStockDBETableEntryDescriptor; 018 /** 019 * This class implements a <code>SaleProcess</code> used to rent videos. 020 * 021 */ 022 public class SaleProcessRent extends SaleProcess { 023 /** 024 * ID for Serialization. 025 */ 026 private static final long serialVersionUID = 7049901087468198485L; 027 /** 028 * Key of a Databasket-subbasket which contains the temporary removed videos of the VideoShops stock 029 */ 030 public static final String SUB_SHOP_VIDEO = "videos_cs"; 031 /** 032 * Key of Databasket-subbasket which contains the temporary added videos of the users-stock 033 */ 034 public static final String SUB_USER_VIDEO = "video_ss"; 035 /** 036 * Key of Databasket-subbasket which contains the temporary added money of the user 037 */ 038 public static final String SUB_TMP_MONEY = "money_temp"; 039 /** 040 * Key of Databasket-subbasket which contains the temporary removed money of the VideoShops MoneyBag 041 */ 042 public static final String SUB_SHOP_MONEY = "money_shop"; 043 044 045 046 /** 047 * The temporary money bag 048 */ 049 private MoneyBagImpl temporaryMoneyBag; 050 051 /** 052 * The sum 053 */ 054 private NumberValue sumNumberValue; 055 056 /** 057 * Constructs a new SaleProcessRent 058 * 059 */ 060 public SaleProcessRent() { 061 super("SaleProcessRent"); 062 } 063 /** 064 * Implementation of the inherited abstract method. 065 * 066 * @return a <code>Gate</code> where the user makes a selection 067 * 068 * @see sale.SaleProcess#getInitialGate() 069 */ 070 protected Gate getInitialGate() { 071 setTemporaryMoneyBag(new MoneyBagImpl("mb_user", VideoShop.getCurrency())); 072 073 getBasket().setCurrentSubBasket(SUB_SHOP_VIDEO); 074 CSDBStrategy csdbs = new CSDBStrategy(); 075 csdbs.setErrorHandler(FormSheetStrategy.MSG_POPUP_ERROR_HANDLER); 076 077 // UIGate erzeugen 078 UIGate uig_offer = new UIGate(null, null); 079 080 TwoTableFormSheet ttfs_rent = 081 TwoTableFormSheet.create( 082 "Choose your videos!", 083 VideoShop.getVideoStock(), 084 getBasket(), 085 uig_offer /*Verkn�pfung Gate und Formsheet */, 086 null, 087 null, 088 false, 089 new TEDVideoStock(), 090 null, 091 csdbs, 092 TwoTableFormSheet.RIGHT); 093 094 095 096 //aussehen des Formsheet mit dem ContenCreator anpassen; in diesem Fall zwei neue Button setzen 097 ttfs_rent.addContentCreator(new RentTTFSContentCreator()); 098 099 return uig_offer; 100 } 101 102 /** 103 * Returns the initial gate. 104 * 105 * @return intialGate 106 */ 107 public Gate restart(){ 108 return getInitialGate(); 109 } 110 111 112 /** 113 * @return a <code>Gate</code> where the money gets inserted 114 */ 115 116 117 public Gate getPayGate() { 118 119 120 121 NumberValue nv_sum = getSumNumberValue(); 122 CCSStrategy ccss = new CCSStrategy(); 123 ccss.setErrorHandler(FormSheetStrategy.MSG_POPUP_ERROR_HANDLER); 124 125 UIGate uig_pay = new UIGate(null, null); 126 127 //FormSheet erzeugen 128 TwoTableFormSheet ttfs_pay = 129 TwoTableFormSheet.create( 130 "Throw the money in the slot, please.", 131 VideoShop.getCurrency(), 132 getTemporaryMoneyBag(), 133 getBasket(), 134 uig_pay, 135 new ComparatorCurrency(), 136 new ComparatorCurrency(), 137 false, 138 null, 139 null, 140 ccss, 141 TwoTableFormSheet.RIGHT); 142 // ContentCreator erstellen 143 RentPayFSContentCreator formSheetCC = new RentPayFSContentCreator(this); 144 145 //so kann man dem Formsheet bestehende Daten mitgeben! z.b. um Eingabefelder schon zu bef�llen 146 formSheetCC.setPayValue(VideoShop.getCurrency().toString(nv_sum)); 147 148 ttfs_pay.addContentCreator(formSheetCC); 149 150 return uig_pay; 151 } 152 153 154 /** 155 * @return a <code>Gate</code> where the selected videos and the change money is shown 156 */ 157 public Gate getConfirmGate() { 158 159 UIGate uig_confirm = new UIGate(null, null); 160 getBasket().setCurrentSubBasket(SUB_SHOP_VIDEO); 161 SingleTableFormSheet fs = 162 SingleTableFormSheet.create( 163 "Confirm your transaction!", 164 getBasket(), 165 uig_confirm, 166 DataBasketConditionImpl.allStockItemsWithDest( 167 ((AutomatUser) ((SalesPoint) getContext()).getUser()).getVideoStock()), 168 new DefaultStoringStockDBETableEntryDescriptor()); 169 170 fs.addContentCreator(new RentConfirmFSContentCreator(this, uig_confirm)); 171 uig_confirm.setFormSheet(fs); 172 return uig_confirm; 173 } 174 175 /** 176 * Get the temporary money bag. 177 * @return the temporary money bag 178 */ 179 public MoneyBagImpl getTemporaryMoneyBag() { 180 return temporaryMoneyBag; 181 } 182 /** 183 * Set the temporary money bag. 184 * @param temporaryMoneyBag the temporary money bag to set 185 */ 186 public void setTemporaryMoneyBag(MoneyBagImpl temporaryMoneyBag) { 187 this.temporaryMoneyBag = temporaryMoneyBag; 188 } 189 /** 190 * Get the sum. 191 * @return the sum 192 */ 193 public NumberValue getSumNumberValue() { 194 return sumNumberValue; 195 } 196 /** 197 * Set the sum. 198 * @param sumNumberValue the sum to set 199 */ 200 public void setSumNumberValue(NumberValue sumNumberValue) { 201 this.sumNumberValue = sumNumberValue; 202 } 203 204 205 } 206