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