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 DataBasketTableModel} modelling
009 * {@link DataBasketEntry DataBasketEntries} that describe operations on items in a {@link CountingStock}.
010 *
011 * <p>There will be two columns, headed "Name" and "Count". The first will give the item's
012 * name, the second the number of items of that sort available.</p>
013 *
014 * @author Steffen Zschaler
015 * @version 2.0 23/08/1999
016 * @since v2.0
017 */
018 public class DefaultCountingStockDBETableEntryDescriptor extends AbstractTableEntryDescriptor {
019
020 /**
021 * ID for serialization.
022 */
023 private static final long serialVersionUID = -4430208665224971966L;
024
025 /**
026 * Create a new DefaultCountingStockDBETableEntryDescriptor.
027 */
028 public DefaultCountingStockDBETableEntryDescriptor() {
029 super();
030 }
031
032 /**
033 * @return 2.
034 * @override Sometimes
035 */
036 public int getColumnCount() {
037 return 2;
038 }
039
040 /**
041 * @return "Name" for the first and "Count" for the second column.
042 * @override Sometimes
043 */
044 public String getColumnName(int nIdx) {
045 String[] asNames = {
046 "Name", "Count"};
047 return asNames[nIdx];
048 }
049
050 /**
051 * @return <code>String.class</code> for the first and <code>Integer.class</code> for the second column.
052 * @override Sometimes
053 */
054 public Class<?> getColumnClass(int nIdx) {
055 Class[] acClasses = {
056 String.class, Integer.class};
057 return acClasses[nIdx];
058 }
059
060 /**
061 * @return the item's name for the first and the number of available items for the second column.
062 * @override Sometimes
063 */
064 public Object getValueAt(Object oData, int nIdx) {
065 DataBasketEntry dbe = (DataBasketEntry)oData;
066
067 switch (nIdx) {
068 case 0:
069 return dbe.getSecondaryKey();
070 case 1:
071 return dbe.getValue();
072 }
073
074 return null;
075 }
076 }