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