001    package market.stdform;
002    
003    import market.SICustomer;
004    import market.UCustomer;
005    import sale.FormSheet;
006    import sale.FormSheetContentCreator;
007    import users.UserManager;
008    import util.swing.AbstractTableEntryDescriptor;
009    import util.swing.TableEntryDescriptor;
010    import data.StoringStock;
011    import data.stdforms.SingleTableFormSheet;
012    
013    
014    /**
015     * This FormSheet displays the customers who are waiting at the till in a table,
016     * with the customer who waits the longest time at the top.
017     */
018    public class FSSellerCustomerTable {
019    
020        /**
021         * @return the customer table.
022         *
023         * @param ss the StoringStock  containing the waiting customers  in form of {@link SICustomer}.
024         */
025        public static SingleTableFormSheet getCustomerTable(StoringStock ss){
026    
027            SingleTableFormSheet stfs = SingleTableFormSheet.create(
028                    "Kunden-Warteschlange",
029                    ss,
030                    null,
031                    getTED());
032    
033            stfs.addContentCreator(new FormSheetContentCreator() {
034                protected void createFormSheetContent(final FormSheet fs) {
035                    fs.removeAllButtons();
036                    fs.addButton("Kunden bedienen", ButtonIDs.BTN_OK, null);
037                    fs.addButton("Auftrag stornieren", ButtonIDs.BTN_CANCEL, null);
038                }}
039            );
040            return stfs;
041        }
042    
043        /**
044         * @return the TableEntryDescriptor of the table, declaring two columns: the userID and full name of the customer.
045         */
046        private static TableEntryDescriptor getTED(){
047            AbstractTableEntryDescriptor ted = new AbstractTableEntryDescriptor(){
048                public int getColumnCount() {
049                    return 2;
050                }
051    
052                public String getColumnName(int nIdx) {
053                    return (new String[]{ "KundenID", "Name"}) [nIdx];
054                }
055    
056                public Class getColumnClass(int nIdx) {
057                    return (new Class[] {String.class, String.class}) [nIdx];
058                }
059    
060                public Object getValueAt(Object oRecord, int nIdx) {
061                    UCustomer customer = (UCustomer)UserManager.getGlobalUM().getUser(((SICustomer)oRecord).getName());
062                    switch(nIdx){
063                        case 0: return customer.getName();
064                        case 1: return customer.getFullName();
065                    }
066                    return null;
067                }
068            };
069            return ted;
070        }
071    }