001    package data.swing;
002    
003    /**
004     * A {@link util.swing.TableEntryDescriptor} that can be used with a {@link CountingStockTableModel}.
005     *
006     * <p>There will be three columns: "Name", "Value" and "Count". The first will
007     * display the items' names, the secind their values and the third will show how many items of a sort are
008     * actually in the Stock.</p>
009     *
010     * @author Steffen Zschaler
011     * @version 2.0 23/08/1999
012     * @since v2.0
013     */
014    public class DefaultCountingStockItemTED extends DefaultCatalogItemTED {
015    
016        /**
017         * Create a new DefaultCountingStockItemTED.
018         */
019        public DefaultCountingStockItemTED() {
020            super();
021        }
022    
023        /**
024         * @return 3.
025         * @override Sometimes
026         */
027        public int getColumnCount() {
028            return 3;
029        }
030    
031        /**
032         * @return "Name" for the first, "Value" for the second and "Count" for the
033         * third column.
034         * @override Sometimes
035         */
036        public String getColumnName(int nIdx) {
037            if (nIdx == 2) {
038                return "Count";
039            } else {
040                return super.getColumnName(nIdx);
041            }
042        }
043    
044        /**
045         * @return <code>String.class</code> for the first, <code>{@link data.Value}.class</code> for the second and
046         * <code>Integer.class</code> for the third column.
047         * @override Sometimes
048         */
049        public Class getColumnClass(int nIdx) {
050            if (nIdx == 2) {
051                return Integer.class;
052            } else {
053                return super.getColumnClass(nIdx);
054            }
055        }
056    
057        /**
058         * @return the item's name for the first, its value for the second and the number of items for the third
059         * column.
060         * @override Sometimes
061         */
062        public Object getValueAt(Object oData, int nIdx) {
063            CountingStockTableModel.Record r = (CountingStockTableModel.Record)oData;
064    
065            if (nIdx == 2) {
066                return new Integer(r.getCount());
067            } else {
068                return super.getValueAt(r.getDescriptor(), nIdx);
069            }
070        }
071    }