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.CatalogItem; 011 import data.DataBasketConditionImpl; 012 import data.MoneyBag; 013 import data.NumberValue; 014 import data.ooimpl.MoneyBagImpl; 015 import data.stdforms.SingleTableFormSheet; 016 import data.stdforms.TwoTableFormSheet; 017 import data.stdforms.twotableformsheet.CCSStrategy; 018 import data.stdforms.twotableformsheet.CSDBStrategy; 019 import data.swing.DefaultStoringStockDBETableEntryDescriptor; 020 /** 021 * This class implements a <code>SaleProcess</code> used to rent videos. 022 * 023 */ 024 public class SaleProcessRent extends SaleProcess { 025 /* 026 * Key of a Databasket-subbasket which contains the temporary removed videos of the VideoShops stock 027 */ 028 public static final String SUB_SHOP_VIDEO = "videos_cs"; 029 /* 030 * Key of Databasket-subbasket which contains the temporary added videos of the users-stock 031 */ 032 public static final String SUB_USER_VIDEO = "video_ss"; 033 /* 034 * Key of Databasket-subbasket which contains the temporary added money of the user 035 */ 036 public static final String SUB_TMP_MONEY = "money_temp"; 037 /* 038 * Key of Databasket-subbasket which contains the temporary removed money of the VideoShops MoneyBag 039 */ 040 public static final String SUB_SHOP_MONEY = "money_shop"; 041 042 043 044 /** Key to the temp money bag for the porcess data of the process context */ 045 public static final String MB_TEMP_KEY = "mb_temp"; 046 047 048 public static final String SUM_KEY = "nv_sum"; 049 050 /** 051 * Constructs a new SaleProcessRent 052 * 053 */ 054 public SaleProcessRent() { 055 super("SaleProcessRent"); 056 } 057 /** 058 * Implementation of the inherited abstract method. 059 * 060 * @return a <code>Gate</code> where the user makes a selection 061 * 062 * @see sale.SaleProcess#getInitialGate() 063 */ 064 protected Gate getInitialGate() { 065 getContext().setProcessData(MB_TEMP_KEY, new MoneyBagImpl("mb_user", VideoShop.getCurrency())); 066 067 getBasket().setCurrentSubBasket(SUB_SHOP_VIDEO); 068 CSDBStrategy csdbs = new CSDBStrategy(); 069 csdbs.setErrorHandler(FormSheetStrategy.MSG_POPUP_ERROR_HANDLER); 070 071 // UIGate erzeugen 072 UIGate uig_offer = new UIGate(null, null); 073 074 TwoTableFormSheet ttfs_rent = 075 TwoTableFormSheet.create( 076 "Choose your videos!", 077 VideoShop.getVideoStock(), 078 getBasket(), 079 uig_offer /*Verknüpfung Gate und Formsheet */, 080 null, 081 null, 082 false, 083 new TEDVideoStock(), 084 null, 085 csdbs); 086 087 088 089 //aussehen des Formsheet mit dem ContenCreator anpassen; in diesem Fall zwei neue Button setzen 090 ttfs_rent.addContentCreator(new RentTTFSContentCreator()); 091 092 return uig_offer; 093 } 094 095 public Gate restart(){ 096 return getInitialGate(); 097 } 098 099 100 /** 101 * @return a <code>Gate</code> where the money gets inserted 102 */ 103 104 105 public Gate getPayGate() { 106 107 108 109 NumberValue nv_sum = (NumberValue) getContext().getProcessData(SUM_KEY); 110 CCSStrategy ccss = new CCSStrategy(); 111 ccss.setErrorHandler(FormSheetStrategy.MSG_POPUP_ERROR_HANDLER); 112 113 UIGate uig_pay = new UIGate(null, null); 114 115 //FormSheet erzeugen 116 TwoTableFormSheet ttfs_pay = 117 TwoTableFormSheet.create( 118 "Throw the money in the slot, please.", 119 VideoShop.getCurrency(), 120 (MoneyBag)getContext().getProcessData(MB_TEMP_KEY), 121 getBasket(), 122 uig_pay, 123 new ComparatorCurrency<CatalogItem>(), 124 new ComparatorCurrency<CatalogItem>(), 125 false, 126 null, 127 null, 128 ccss); 129 // ContentCreator erstellen 130 RentPayFSContentCreator formSheetCC = new RentPayFSContentCreator(this); 131 132 //so kann man dem Formsheet bestehende Daten mitgeben! z.b. um Eingabefelder schon zu befüllen 133 formSheetCC.setPayValue(VideoShop.getCurrency().toString(nv_sum)); 134 135 ttfs_pay.addContentCreator(formSheetCC); 136 137 return uig_pay; 138 } 139 140 141 /** 142 * @return a <code>Gate</code> where the selected videos and the change money is shown 143 */ 144 public Gate getConfirmGate() { 145 146 UIGate uig_confirm = new UIGate(null, null); 147 getBasket().setCurrentSubBasket(SUB_SHOP_VIDEO); 148 SingleTableFormSheet fs = 149 SingleTableFormSheet.create( 150 "Confirm your transaction!", 151 getBasket(), 152 uig_confirm, 153 DataBasketConditionImpl.allStockItemsWithDest( 154 ((AutomatUser) ((SalesPoint) getContext()).getUser()).getVideoStock()), 155 new DefaultStoringStockDBETableEntryDescriptor()); 156 157 fs.addContentCreator(new RentConfirmFSContentCreator(this, uig_confirm)); 158 uig_confirm.setFormSheet(fs); 159 return uig_confirm; 160 } 161 162 163 } 164