001 package videoautomat;
002
003 import sale.Gate;
004 import sale.SaleProcess;
005 import sale.SalesPoint;
006 import sale.UIGate;
007 import videoautomat.contentcreator.HandBackSTFSContentCreator;
008 import videoautomat.contentcreator.HandBackTTFSContentCreator;
009 import data.IntegerValue;
010 import data.NumberValue;
011 import data.StoringStock;
012 import data.ooimpl.MoneyBagImpl;
013 import data.ooimpl.StoringStockImpl;
014 import data.stdforms.SingleTableFormSheet;
015 import data.stdforms.TwoTableFormSheet;
016 import data.stdforms.twotableformsheet.SSSSStrategy;
017
018 /**
019 * This class implements a <code>SaleProcess</code> to hand back the videos.
020 * @author Alexander Herrmann
021 */
022 public class SaleProcessHandBack extends SaleProcess {
023
024 /*
025 * Key of StoringStock to store temporary videos.
026 */
027 public static final String SS_TEMP_KEY = "ss_temp";
028
029 /*
030 * Key of a MoneyBag to store temporary the change money
031 */
032 public static final String MB_TEMP_KEY = "mb_temp";
033
034 /*
035 * Key of a NumberValue representing the change money
036 */
037 public static final String CHG_MONEY_KEY = "nv_change";
038
039 /**
040 * Constructs a new <code>SaleProcessHandBack</code>
041 *
042 */
043 public SaleProcessHandBack() {
044 super("SaleProcessGiveback");
045 }
046
047 /**
048 * Implementation of the inherited abstract method.
049 *
050 * @return the <code>Gate</code> where the user will see his/her current rented videos.
051 * @see sale.SaleProcess#getInitialGate()
052 * @author Alexander Herrmann
053 */
054 protected Gate getInitialGate() {
055
056 // generate Gate
057 UIGate uig_video = new UIGate(null, null);
058
059 getContext().setProcessData(SS_TEMP_KEY, new StoringStockImpl("temp", VideoShop.getVideoCatalog()));
060 getContext().setProcessData(MB_TEMP_KEY, new MoneyBagImpl("temp", VideoShop.getCurrency()));
061 getContext().setProcessData(CHG_MONEY_KEY, new IntegerValue(0));
062
063 TwoTableFormSheet ttfs_handback =
064 TwoTableFormSheet.create(
065 "Give back a video",
066 ((AutomatUser) ((SalesPoint) this.getContext()).getUser()).getVideoStock(),
067 (StoringStock) getContext().getProcessData(SS_TEMP_KEY),
068 getBasket(),
069 uig_video,
070 null,
071 null,
072 new TEDVideoCassette(),
073 new TEDVideoCassette(),
074 new SSSSStrategy()
075 );
076
077 ttfs_handback.addContentCreator(new HandBackTTFSContentCreator());
078
079 return uig_video;
080 }
081
082 public Gate restart()
083 {
084 return getInitialGate();
085 }
086
087 /**
088 * @return the <code>Gate</code> where the user will see his/her change money.
089 * @author Alexander Herrmann
090 */
091 public Gate getChangeGate() {
092
093 // generate Gate
094 UIGate uig_change = new UIGate(null, null);
095
096 SingleTableFormSheet stfs_change =
097 SingleTableFormSheet.create(
098 "Here is your change!",
099 (MoneyBagImpl) getContext().getProcessData(MB_TEMP_KEY),
100 uig_change,
101 getBasket());
102
103 stfs_change.addContentCreator(new HandBackSTFSContentCreator(
104 (NumberValue) getContext().getProcessData(SaleProcessHandBack.CHG_MONEY_KEY)));
105
106 return uig_change;
107 }
108
109 }