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 StoringStock source and a DataBasket destination. 012 * 013 * @author Steffen Zschaler 014 * @version 2.0 20/08/1999 015 * @since v2.0 016 */ 017 public class SSDBStrategy 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 ssSource the source StoringStock. 025 * @param dbDest the destination DataBasket. 026 * @param si the StockItem that is selected in the source. 027 * @param ttfs the FormSheet that triggers the process. 028 * 029 * @override Never 030 */ 031 public Transition getMoveToDestProcess(SaleProcess p, SalesPoint sp, StoringStock ssSource, 032 DataBasket dbDest, StockItem si, TwoTableFormSheet ttfs) { 033 return new GateChangeTransition(getCheckMoveToDestGate(p, sp, ssSource, dbDest, si, ttfs)); 034 } 035 036 /** 037 * Get the first gate of the sub-process that will move items from the source to the destination. 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 ssSource the source StoringStock. 045 * @param dbDest the destination DataBasket. 046 * @param si the StockItem that is selected in the source. 047 * @param ttfs the FormSheet that triggers the process. 048 * 049 * @override Never Instead, override {@link #checkMoveToDest} and/or {@link #moveToDest}. 050 */ 051 protected Gate getCheckMoveToDestGate(SaleProcess p, final SalesPoint sp, final StoringStock ssSource, 052 final DataBasket dbDest, final StockItem si, final TwoTableFormSheet ttfs) { 053 return new Gate() { 054 public Transition getNextTransition(SaleProcess p, User u) throws InterruptedException { 055 int nCheckReturn = checkMoveToDest(p, sp, ssSource, dbDest, si); 056 057 if (nCheckReturn == 0) { 058 return new Transition() { 059 public Gate perform(SaleProcess p, User u) { 060 moveToDest(p, sp, ssSource, dbDest, 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 ssSource the source StoringStock. 081 * @param dbDest the destination DataBasket. 082 * @param si the StockItem that is selected in the source. 083 * 084 * @override Sometimes The default implementation returns 0. 085 */ 086 protected int checkMoveToDest(SaleProcess p, SalesPoint sp, StoringStock ssSource, DataBasket dbDest, 087 StockItem si) throws InterruptedException { 088 return 0; 089 } 090 091 /** 092 * Move the indicated item from the source 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 ssSource the source StoringStock. 098 * @param dbDest the destination DataBasket. 099 * @param si the StockItem that is selected in the source. 100 * 101 * @override Sometimes 102 */ 103 protected void moveToDest(SaleProcess p, SalesPoint sp, StoringStock ssSource, DataBasket dbDest, 104 StockItem si) { 105 try { 106 ssSource.remove(si, dbDest); 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 destination to the source. 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 ssSource the source StoringStock. 119 * @param dbDest the destination DataBasket. 120 * @param dbe the DataBasketEntry that is selected in the destination. 121 * @param ttfs the FormSheet that triggers the process. 122 * 123 * @override Never 124 */ 125 public Transition getMoveToSourceProcess(SaleProcess p, SalesPoint sp, StoringStock ssSource, 126 DataBasket dbDest, DataBasketEntry dbe, TwoTableFormSheet ttfs) { 127 return new GateChangeTransition(getCheckMoveToSourceGate(p, sp, ssSource, dbDest, dbe, ttfs)); 128 } 129 130 /** 131 * Get the first gate of the sub-process that will move items from the destination to the source. 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 ssSource the source StoringStock. 139 * @param dbDest the destination DataBasket. 140 * @param dbe the DataBasketEntry that is selected in the destination. 141 * @param ttfs the FormSheet that triggers the process. 142 * 143 * @override Never Instead, override {@link #checkMoveToSource} and/or {@link #moveToSource}. 144 */ 145 protected Gate getCheckMoveToSourceGate(SaleProcess p, final SalesPoint sp, final StoringStock ssSource, 146 final DataBasket dbDest, final DataBasketEntry dbe, final TwoTableFormSheet ttfs) { 147 return new Gate() { 148 public Transition getNextTransition(SaleProcess p, User u) throws InterruptedException { 149 int nCheckReturn = checkMoveToSource(p, sp, ssSource, dbDest, dbe); 150 151 if (nCheckReturn == 0) { 152 return new Transition() { 153 public Gate perform(SaleProcess p, User u) { 154 moveToSource(p, sp, ssSource, dbDest, 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 ssSource the source StoringStock. 175 * @param dbDest the destination DataBasket. 176 * @param dbe the DataBasketEntry that is selected in the destination. 177 * 178 * @override Sometimes The default implementation returns 0. 179 */ 180 protected int checkMoveToSource(SaleProcess p, SalesPoint sp, StoringStock ssSource, DataBasket dbDest, 181 DataBasketEntry dbe) throws InterruptedException { 182 return 0; 183 } 184 185 /** 186 * Move the indicated item into the source 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 ssSource the source StoringStock. 192 * @param dbDest the destination DataBasket. 193 * @param dbe the DataBasketEntry that is selected in the destination. 194 * 195 * @override Sometimes 196 */ 197 protected void moveToSource(SaleProcess p, SalesPoint sp, StoringStock ssSource, DataBasket dbDest, 198 DataBasketEntry dbe) { 199 ssSource.add((StockItem)dbe.getValue(), dbDest); 200 } 201 }