001package jmri.jmrit.operations.locations;
002
003import java.beans.PropertyChangeEvent;
004
005import javax.swing.JTable;
006import javax.swing.SwingUtilities;
007
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011import jmri.jmrit.operations.setup.Control;
012
013/**
014 * Table Model for edit of interchanges used by operations
015 *
016 * @author Daniel Boudreau Copyright (C) 2008
017 */
018public class InterchangeTableModel extends TrackTableModel {
019
020    public InterchangeTableModel() {
021        super();
022    }
023
024    public void initTable(JTable table, Location location) {
025        super.initTable(table, location, Track.INTERCHANGE);
026    }
027
028    @Override
029    protected void editTrack(int row) {
030        log.debug("Edit interchange");
031        if (tef != null) {
032            tef.dispose();
033        }
034        // use invokeLater so new window appears on top
035        SwingUtilities.invokeLater(() -> {
036            tef = new InterchangeEditFrame();
037            Track interchange = _tracksList.get(row);
038            tef.initComponents(_location, interchange);
039            tef.setTitle(Bundle.getMessage("EditInterchange"));
040        });
041    }
042    
043    @Override
044    public String getColumnName(int col) {
045        switch (col) {
046            case NAME_COLUMN:
047                return Bundle.getMessage("InterchangeName");
048            default:
049                return super.getColumnName(col);
050        }
051    }
052
053    // this table listens for changes to a location and its interchanges
054    @Override
055    public void propertyChange(PropertyChangeEvent e) {
056        if (Control.SHOW_PROPERTY) {
057            log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), e
058                    .getNewValue());
059        }
060        super.propertyChange(e);
061        if (e.getSource().getClass().equals(Track.class)) {
062            Track track = ((Track) e.getSource());
063            if (track.isInterchange()) {
064                int row = _tracksList.indexOf(track);
065                if (Control.SHOW_PROPERTY) {
066                    log.debug("Update interchange table row: {} track: {}", row, track.getName());
067                }
068                if (row >= 0) {
069                    fireTableRowsUpdated(row, row);
070                }
071            }
072        }
073    }
074
075    private final static Logger log = LoggerFactory.getLogger(InterchangeTableModel.class);
076}