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