001package jmri.jmrit.beantable.routetable;
002
003import jmri.InstanceManager;
004
005import javax.swing.table.AbstractTableModel;
006import java.beans.PropertyChangeListener;
007
008/**
009 * Base table model for selecting outputs.
010 *
011 * Split from {@link jmri.jmrit.beantable.RouteTableAction}
012 *
013 * @author Dave Duchamp Copyright (C) 2004
014 * @author Bob Jacobsen Copyright (C) 2007
015 * @author Simon Reader Copyright (C) 2008
016 * @author Pete Cressman Copyright (C) 2009
017 * @author Egbert Broerse Copyright (C) 2016
018 * @author Paul Bender Copyright (C) 2020
019 */
020abstract class RouteOutputModel extends AbstractTableModel implements PropertyChangeListener {
021
022    @Override
023    public Class<?> getColumnClass(int c) {
024        if (c == INCLUDE_COLUMN) {
025            return Boolean.class;
026        } else {
027            return String.class;
028        }
029    }
030
031    @Override
032    public void propertyChange(java.beans.PropertyChangeEvent e) {
033        if (e.getPropertyName().equals("length")) {
034            // a new NamedBean is available in the manager
035            fireTableDataChanged();
036        }
037    }
038
039    void dispose() {
040        InstanceManager.turnoutManagerInstance().removePropertyChangeListener(this);
041    }
042
043    @Override
044    public String getColumnName(int c) {
045        return RouteAddFrame.COLUMN_NAMES[c];
046    }
047
048    @Override
049    public int getColumnCount() {
050        return 4;
051    }
052
053    @Override
054    public boolean isCellEditable(int r, int c) {
055        return ((c == INCLUDE_COLUMN) || (c == STATE_COLUMN));
056    }
057
058    static final int SNAME_COLUMN = 0;
059    static final int UNAME_COLUMN = 1;
060    static final int INCLUDE_COLUMN = 2;
061    static final int STATE_COLUMN = 3;
062
063}