001package jmri.jmrit.operations.locations.gui;
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.locations.*;
012import jmri.jmrit.operations.setup.Control;
013
014/**
015 * Table Model for edit of interchanges used by operations
016 *
017 * @author Daniel Boudreau Copyright (C) 2008
018 */
019public class InterchangeTableModel extends TrackTableModel {
020
021    public InterchangeTableModel() {
022        super();
023    }
024
025    public void initTable(JTable table, Location location) {
026        super.initTable(table, location, Track.INTERCHANGE);
027    }
028
029    @Override
030    protected void editTrack(int row) {
031        log.debug("Edit interchange");
032        if (tef != null) {
033            tef.dispose();
034        }
035        // use invokeLater so new window appears on top
036        SwingUtilities.invokeLater(() -> {
037            tef = new InterchangeEditFrame();
038            Track interchange = _tracksList.get(row);
039            tef.initComponents(interchange);
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}