001 package data.stdforms.twotableformsheet;
002
003 import sale.*;
004
005 import data.*;
006 import data.stdforms.*;
007
008 import users.*;
009
010 /**
011 * MoveStrategy for a StoringStock source and destination.
012 *
013 * @author Steffen Zschaler
014 * @version 2.0 20/08/1999
015 * @since v2.0
016 */
017 public class SSSSStrategy extends MoveStrategy {
018
019 /**
020 * ID for serialization.
021 */
022 private static final long serialVersionUID = 3240707067489768710L;
023
024 /**
025 * Get the sub-process that will move items from the source to the destination.
026 *
027 * @param p the process into which the sub-process wil be embedded.
028 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
029 * @param ssSource the source StoringStock.
030 * @param ssDest the destination StoringStock.
031 * @param db the DataBasket relative to which to perform the operation.
032 * @param si the StockItem that is selected in the source.
033 * @param ttfs the FormSheet that triggers the process.
034 *
035 * @override Never
036 */
037 public Transition getMoveToDestProcess(SaleProcess p, SalesPoint sp, StoringStock ssSource,
038 StoringStock ssDest, DataBasket db, StockItem si, TwoTableFormSheet ttfs) {
039 return new GateChangeTransition(getCheckMoveToDestGate(p, sp, ssSource, ssDest, db, si, ttfs));
040 }
041
042 /**
043 * Get the first gate of the sub-process that will move items from the source to the destination.
044 *
045 * <p>This Gate will check whether the move is allowable, and if so, will trigger a Transition that
046 * performs it.</p>
047 *
048 * @return {@link #getCheckMoveGate}.
049 *
050 * @param p the process into which the sub-process wil be embedded.
051 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
052 * @param ssSource the source StoringStock.
053 * @param ssDest the destination StoringStock.
054 * @param db the DataBasket relative to which to perform the operation.
055 * @param si the StockItem that is selected in the source.
056 * @param ttfs the FormSheet that triggers the process.
057 *
058 * @override Never Instead, override {@link #checkMove} and/or {@link #moveImpl}.
059 */
060 protected Gate getCheckMoveToDestGate(SaleProcess p, SalesPoint sp, StoringStock ssSource,
061 StoringStock ssDest, DataBasket db, StockItem si, TwoTableFormSheet ttfs) {
062 return getCheckMoveGate(p, sp, ssSource, ssDest, db, si, ttfs);
063 }
064
065 /**
066 * Get the sub-process that will move items from the destination to the source.
067 *
068 * @param p the process into which the sub-process wil be embedded.
069 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
070 * @param ssSource the source StoringStock.
071 * @param ssDest the destination StoringStock.
072 * @param db the DataBasket relative to which to perform the operation.
073 * @param si the StockItem that is selected in the destination.
074 * @param ttfs the FormSheet that triggers the process.
075 *
076 * @override Never
077 */
078 public Transition getMoveToSourceProcess(SaleProcess p, SalesPoint sp, StoringStock ssSource,
079 StoringStock ssDest, DataBasket db, StockItem si, TwoTableFormSheet ttfs) {
080 return new GateChangeTransition(getCheckMoveToSourceGate(p, sp, ssSource, ssDest, db, si, ttfs));
081 }
082
083 /**
084 * Get the first gate of the sub-process that will move items from the destination to the source.
085 *
086 * <p>This Gate will check whether the move is allowable, and if so, will trigger a Transition that
087 * performs it.</p>
088 *
089 * @return {@link #getCheckMoveGate}.
090 *
091 * @param p the process into which the sub-process wil be embedded.
092 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
093 * @param ssSource the source StoringStock.
094 * @param ssDest the destination StoringStock.
095 * @param db the DataBasket relative to which to perform the operation.
096 * @param si the StockItem that is selected in the destination.
097 * @param ttfs the FormSheet that triggers the process.
098 *
099 * @override Never Instead, override {@link #checkMove} and/or {@link #moveImpl}.
100 */
101 protected Gate getCheckMoveToSourceGate(SaleProcess p, SalesPoint sp, StoringStock ssSource,
102 StoringStock ssDest, DataBasket db, StockItem si, TwoTableFormSheet ttfs) {
103 return getCheckMoveGate(p, sp, ssDest, ssSource, db, si, ttfs);
104 }
105
106 /**
107 * Get the first gate of a sub-process that will move items from one Stock into another.
108 *
109 * <p>This Gate will check whether the move is allowable, and if so, will trigger a Transition that
110 * performs it.</p>
111 *
112 * @param p the process into which the sub-process wil be embedded.
113 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
114 * @param ssSource the source StoringStock.
115 * @param ssDest the destination StoringStock.
116 * @param db the DataBasket relative to which to perform the operation.
117 * @param si the StockItem which is to be moved from the source into the destination Stock.
118 * @param ttfs the FormSheet that triggers the process.
119 *
120 * @override Never Instead, override {@link #checkMove} and/or {@link #moveImpl}.
121 */
122 protected Gate getCheckMoveGate(SaleProcess p, final SalesPoint sp, final StoringStock ssSource,
123 final StoringStock ssDest, final DataBasket db, final StockItem si, final TwoTableFormSheet ttfs) {
124 return new Gate() {
125 private static final long serialVersionUID = 4828550322944653983L;
126
127 public Transition getNextTransition(SaleProcess p, User u) throws InterruptedException {
128 int nCheckReturn = checkMove(p, sp, ssSource, ssDest, db, si);
129
130 if (nCheckReturn == 0) {
131 return new Transition() {
132 private static final long serialVersionUID = -3257944253378108255L;
133
134 public Gate perform(SaleProcess p, User u) {
135 moveImpl(p, sp, ssSource, ssDest, db, si);
136
137 return ttfs.getGate();
138 }
139 };
140 } else {
141 error(p, nCheckReturn);
142
143 return new GateChangeTransition(ttfs.getGate());
144 }
145 }
146 };
147 }
148
149 /**
150 * Check whether the indicated move is allowable. If so, return 0, otherwise return a non-zero error value
151 * that can be passed on to {@link sale.stdforms.FormSheetStrategy#error}. You can assume that you are at a {@link Gate}.
152 *
153 * @param p the process into which the sub-process wil be embedded.
154 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
155 * @param ssSource the source StoringStock.
156 * @param ssDest the destination StoringStock.
157 * @param db the DataBasket relative to which to perform the operation.
158 * @param si the StockItem which is to be moved.
159 *
160 * @override Sometimes The default implementation returns 0.
161 */
162 protected int checkMove(SaleProcess p, SalesPoint sp, StoringStock ssSource, StoringStock ssDest,
163 DataBasket db, StockItem si) throws InterruptedException {
164 return 0;
165 }
166
167 /**
168 * Move the indicated item from the source StoringStock into the destination StoringStock. You
169 * can assume that you are in a {@link Transition}.
170 *
171 * @param p the process into which the sub-process wil be embedded.
172 * @param sp the SalesPoint, if any, at which the FormSheet is being displayed.
173 * @param ssSource the source StoringStock.
174 * @param ssDest the destination StoringStock.
175 * @param db the DataBasket relative to which to perform the operation.
176 * @param si the StockItem which is to be moved.
177 *
178 * @override Sometimes
179 */
180 protected void moveImpl(SaleProcess p, SalesPoint sp, StoringStock ssSource, StoringStock ssDest,
181 DataBasket db, StockItem si) {
182 try {
183 ssDest.add(ssSource.remove(si, db), db);
184 }
185 catch (data.events.VetoException ve) {
186 error(p, REMOVE_VETO_EXCEPTION);
187 }
188 }
189 }