001    package market.swing;
002    
003    import sale.SaleProcess;
004    import sale.SalesPoint;
005    import data.Catalog;
006    import data.CatalogItem;
007    import data.CountingStock;
008    import data.DataBasket;
009    import data.NotEnoughElementsException;
010    import data.stdforms.twotableformsheet.CCSStrategy;
011    
012    /**
013     * Defines the behaviour of the shifting buttons in the manager's Purchase-TwoTableFormSheet
014     */
015    public class CCSStrategyMarket extends CCSStrategy {
016    
017        /**
018             * ID for serialization.
019             */
020            private static final long serialVersionUID = 3612670945973595950L;
021    
022            public CCSStrategyMarket() {
023            super();
024        }
025    
026        /**
027         * Removes at most as much items as are left in the stock.
028         * @param p the current SaleProcess.
029         * @param sp the SalesPoint on which the TTFS is displayed.
030         * @param cSource the source Catalog.
031         * @param csDest the destination CountingStock.
032         * @param db the transaction's DataBasket.
033         * @param ci the affected CatalogItem
034         * @param nCount the amount of Items to be shifted.
035         */
036        protected void moveToSource (SaleProcess p, SalesPoint sp, Catalog cSource,
037                CountingStock csDest, DataBasket db, CatalogItem ci, int nCount) {
038            int count = csDest.countItems(ci.getName(),db);
039            count = Math.min(count, nCount);
040            try {
041                csDest.remove (ci.getName(), count, db);
042            }
043            catch (NotEnoughElementsException nee) {
044                error (p, NOT_ENOUGH_ELEMENTS_ERROR);
045            }
046            catch (data.events.VetoException ve) {
047                error (p, REMOVE_VETO_EXCEPTION);
048            }
049            catch (Exception e) {
050                System.out.println(e);
051            }
052        }
053    }