001    package market.stdform;
002    
003    import java.util.Comparator;
004    
005    import market.CIOpenPurchaseOrders;
006    import market.Conversions;
007    import market.SMarket;
008    import market.swing.CmpOpoNumbers;
009    import sale.FormSheet;
010    import sale.FormSheetContentCreator;
011    import util.swing.AbstractTableEntryDescriptor;
012    import data.stdforms.SingleTableFormSheet;
013    
014    /**
015     * This FormSheet displays an overview of the market's purchases that have not yet arrived.
016     */
017    public class FSManagerOpenPurchaseOrderMain {
018    
019        /**
020         * Creates a {@link SingleTableFormSheet}. The look of the table is defined by the
021         * {@link TEDManagerOpenPurchaseOrderMain}.
022         *
023         * @return the created SingleTableFormSheet.
024         */
025        public static SingleTableFormSheet create() {
026    
027            final SingleTableFormSheet stfs = SingleTableFormSheet.create(
028                "Erwartete Lieferungen",
029                SMarket.getOpenPurchaseOrder(),
030                null,                                     //DataBasket
031                new TEDManagerOpenPurchaseOrderMain()     //TED
032            );
033            stfs.addContentCreator(new FormSheetContentCreator() {
034                public void createFormSheetContent(final FormSheet fs) {
035                    fs.removeAllButtons();
036                    fs.addButton("Details", ButtonIDs.BTN_DETAIL, null);
037                }
038            });
039            return stfs;
040        }
041    }
042    
043    /**
044     * The {@link util.swing.TableEntryDescriptor} used by {@link FSManagerOpenPurchaseOrderMain}.
045     */
046    class TEDManagerOpenPurchaseOrderMain extends AbstractTableEntryDescriptor {
047    
048        private Comparator sortValue = new CmpOpoNumbers();
049    
050        /**
051         * @return the number of the table's columns.
052         */
053        public int getColumnCount() {
054            return 3;
055        }
056    
057        /**
058         * @param nIndex the affected column.
059         * @return columns' names.
060         */
061        public String getColumnName(int nIndex) {
062            return (new String[]{ "Bestelldatum", "Gesamtsumme", "Tage bis Ankunft"}) [nIndex];
063        }
064    
065        /**
066         * @param nIndex the affected column.
067         * @return columns' classes. They indicate how column's values should be aligned.
068         */
069        public Class getColumnClass  (int nIndex) {
070            return Number.class;
071        }
072    
073        /**
074         * @param oRecord the affected table record.
075         * @param nIndex the affected column.
076         * @return columns' values
077         */
078        public Object getValueAt(Object oRecord, int nIndex) {
079            CIOpenPurchaseOrders opo = (CIOpenPurchaseOrders)oRecord;
080            switch (nIndex) {
081                case 0: return opo.getName();
082                case 1: return Conversions.doubleToCurrency(opo.getOrdersValue().doubleValue(), " Euro");
083                case 2: return opo.getValue();
084            }
085            return null;
086        }
087    
088        /**
089         * Determines if columns can be sorted by the user.
090         *
091         * @param nIndex the affected column.
092         * @return <ul><li>true: columns can be sorted</li>
093         *              <li>false: columns cannot be sorted</li></ul>
094         */
095        public boolean canSortByColumn(int nIndex) {
096            return true;
097        }
098    
099        /**
100         * @param nIndex the affected column.
101         * @return the {@link Comparator} to be used when sorting the column.
102         */
103        public Comparator getColumnOrder(int nIndex) {
104            switch(nIndex) {
105                case 0: return null;
106                case 1: return sortValue;
107                case 2: return null;
108            }
109            return null;
110        }
111    }