001    package market.stdform;
002    
003    import java.util.Hashtable;
004    
005    import market.CIArticle;
006    import market.Conversions;
007    import sale.FormSheet;
008    import sale.FormSheetContentCreator;
009    import util.swing.AbstractTableEntryDescriptor;
010    import data.CountingStock;
011    import data.stdforms.SingleTableFormSheet;
012    import data.swing.CountingStockTableModel;
013    
014    /**
015     * This FormSheet displays the order of a customer in a table
016     * with one further column to tick off the articles, it is used by workers to execute the order.
017     */
018    public class FSWorkerOrder{
019    
020        /**
021         * @param customer the customer who`s order gets executed.
022         * @param order the order that gets executed.
023         * @param done Hashtable with boolean values used for the tick-off column.
024         */
025        public static SingleTableFormSheet getOrderTable(String customer, CountingStock order, final Hashtable<CIArticle, Object> done){
026    
027            AbstractTableEntryDescriptor ted = new AbstractTableEntryDescriptor(){
028                            private static final long serialVersionUID = -6796571499809624870L;
029    
030                            public int getColumnCount() {
031                    return 3;
032                }
033    
034                public String getColumnName(int nIdx) {
035                    return (new String[]{ "Artikel", "Anzahl", "Erledigt"}) [nIdx];
036                }
037    
038                public Class<?> getColumnClass(int nIdx) {
039                    return (new Class[] {String.class, Number.class, Boolean.class}) [nIdx];
040                }
041    
042                public Object getValueAt(Object oRecord, int nIdx) {
043                    CIArticle article = Conversions.recordToCIArticle(oRecord);
044                    int count = ((CountingStockTableModel.Record)oRecord).getCount();
045                    switch (nIdx) {
046                        case 0: return article.getArticleName();
047                        case 1: return new Integer(count).toString();
048                        case 2: return done.get(article);
049                    }
050                    return null;
051                }
052    
053                public boolean canSortByColumn(int nIndex) {
054                    return false;
055                 }
056                
057                public boolean isElementEditable(Object oRecord, int nIdx) {
058                    return nIdx == 2;
059                }
060                                            
061                public void setValueAt(Object oRecord, int nIndex, Object oValue) {
062                    if (nIndex == 2) {
063                            done.put(Conversions.recordToCIArticle(oRecord), oValue);
064                    }
065                }
066            };
067    
068            final SingleTableFormSheet stfs = SingleTableFormSheet.create(
069                    "Kundenauftrag von "+ customer,
070                    order,
071                    null,
072                    ted);
073    
074            stfs.addContentCreator(new FormSheetContentCreator() {
075                            private static final long serialVersionUID = 1128483388797998676L;
076                            protected void createFormSheetContent(final FormSheet fs) {
077                    fs.removeAllButtons();
078                    fs.addButton("Auftrag abschliessen", ButtonIDs.BTN_ACCEPT, null);
079                    fs.addButton("Fehlbestand", ButtonIDs.BTN_EDIT, null);
080                    fs.addButton("Zurück", ButtonIDs.BTN_BACK, null);
081                }
082            });
083            return stfs;
084        }
085    }