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 yards used by operations
015 *
016 * @author Daniel Boudreau Copyright (C) 2008
017 */
018public class YardTableModel extends TrackTableModel {
019
020    public YardTableModel() {
021        super();
022    }
023
024    public void initTable(JTable table, Location location) {
025        super.initTable(table, location, Track.YARD);
026    }
027
028    @Override
029    protected void editTrack(int row) {
030        log.debug("Edit yard");
031        if (tef != null) {
032            tef.dispose();
033        }
034        // use invokeLater so new window appears on top
035        SwingUtilities.invokeLater(() -> {
036            tef = new YardEditFrame();
037            Track yard = _tracksList.get(row);
038            tef.initComponents(yard);
039        });
040    }
041    
042    @Override
043    public String getColumnName(int col) {
044        switch (col) {
045            case NAME_COLUMN:
046                return Bundle.getMessage("YardName");
047            default:
048                return super.getColumnName(col);
049        }
050    }
051
052    // this table listens for changes to a location and its yards
053    @Override
054    public void propertyChange(PropertyChangeEvent e) {
055        if (Control.SHOW_PROPERTY) {
056            log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), e
057                    .getNewValue());
058        }
059        super.propertyChange(e);
060        if (e.getSource().getClass().equals(Track.class)) {
061            Track track = ((Track) e.getSource());
062            if (track.isYard()) {
063                int row = _tracksList.indexOf(track);
064                if (Control.SHOW_PROPERTY) {
065                    log.debug("Update yard table row: {} track: ({})", row, track.getName());
066                }
067                if (row >= 0) {
068                    fireTableRowsUpdated(row, row);
069                }
070            }
071        }
072    }
073
074    private final static Logger log = LoggerFactory.getLogger(YardTableModel.class);
075}