001    package data.swing;
002    
003    import data.*;
004    
005    import util.swing.*;
006    
007    /**
008     * A {@link TableEntryDescriptor} that can be used with a {@link CatalogTableModel}.
009     *
010     * <p>There will be two columns headed "Name" and "Value". The first will display the
011     * CatalogItems' names, the second their values.</p>
012     *
013     * @author Steffen Zschaler
014     * @version 2.0 23/08/1999
015     * @since v2.0
016     */
017    public class DefaultCatalogItemTED extends AbstractTableEntryDescriptor {
018    
019        /**
020         * Create a new DefaultCatalogItemTED.
021         */
022        public DefaultCatalogItemTED() {
023            super();
024        }
025    
026        /**
027         * @return 2.
028         * @override Sometimes
029         */
030        public int getColumnCount() {
031            return 2;
032        }
033    
034        /**
035         * @return "Name" for the first, "Value" for the second column.
036         * @override Sometimes
037         */
038        public String getColumnName(int nIdx) {
039            String[] asNames = {
040                    "Name", "Value"};
041            return asNames[nIdx];
042        }
043    
044        /**
045         * @return <code>String.class</code> for the first, <code>{@link Value}.class</code> for the second column.
046         * @override Sometimes
047         */
048        public Class getColumnClass(int nIdx) {
049            Class[] acClasses = {
050                    String.class, Value.class};
051            return acClasses[nIdx];
052        }
053    
054        /**
055         * @return the CatalogItem's name for the first, its value for the second column.
056         * @override Sometimes
057         */
058        public Object getValueAt(Object oData, int nIdx) {
059            if (nIdx == 0) {
060                return ((CatalogItem)oData).getName();
061            } else {
062                return ((CatalogItem)oData).getValue();
063            }
064        }
065    }