001package jmri.jmrit.roster.swing.attributetable;
002
003import jmri.jmrit.roster.Roster;
004import jmri.jmrit.roster.RosterEntry;
005
006/**
007 * Table data model for display of Roster attribute values.
008 * <p>
009 * Any desired ordering, etc. is handled outside this class.
010 * <p>
011 * The initial implementation doesn't automatically update when roster entries
012 * change, doesn't allow updating of the entries, and only shows some of the
013 * fields. But it's a start....
014 *
015 * @author Bob Jacobsen Copyright (C) 2009
016 * @since 2.7.5
017 */
018public class AttributeTableModel extends javax.swing.table.AbstractTableModel {
019
020    @Override
021    public int getRowCount() {
022        return Roster.getDefault().numEntries();
023    }
024
025    @Override
026    public int getColumnCount() {
027        return Roster.getDefault().getAllAttributeKeys().size();
028    }
029
030    @Override
031    public String getColumnName(int col) {
032        return (String) Roster.getDefault().getAllAttributeKeys().toArray()[col];
033    }
034
035    @Override
036    public Class<?> getColumnClass(int col) {
037        return String.class;
038    }
039
040    /**
041     * This implementation can't edit the values yet.
042     */
043    @Override
044    public boolean isCellEditable(int row, int col) {
045        return false;
046    }
047
048    /**
049     * Provides the empty String if attribute doesn't exist.
050     */
051    @Override
052    public Object getValueAt(int row, int col) {
053        // get column key
054        String key = getColumnName(col);
055        // get roster entry for row
056        RosterEntry re = Roster.getDefault().getEntry(row);
057        String retval = re.getAttribute(key);
058        if (retval != null) {
059            return retval;
060        }
061        return "";
062    }
063
064    @Override
065    public void setValueAt(Object value, int row, int col) {
066    }
067}