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