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