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