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 yards used by operations 016 * 017 * @author Daniel Boudreau Copyright (C) 2008 018 */ 019public class YardTableModel extends TrackTableModel { 020 021 public YardTableModel() { 022 super(); 023 } 024 025 public void initTable(JTable table, Location location) { 026 super.initTable(table, location, Track.YARD); 027 } 028 029 @Override 030 protected void editTrack(int row) { 031 log.debug("Edit yard"); 032 if (tef != null) { 033 tef.dispose(); 034 } 035 // use invokeLater so new window appears on top 036 SwingUtilities.invokeLater(() -> { 037 tef = new YardEditFrame(); 038 Track yard = _tracksList.get(row); 039 tef.initComponents(yard); 040 }); 041 } 042 043 @Override 044 public String getColumnName(int col) { 045 switch (col) { 046 case NAME_COLUMN: 047 return Bundle.getMessage("YardName"); 048 default: 049 return super.getColumnName(col); 050 } 051 } 052 053 // this table listens for changes to a location and its yards 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.isYard()) { 064 int row = _tracksList.indexOf(track); 065 if (Control.SHOW_PROPERTY) { 066 log.debug("Update yard 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(YardTableModel.class); 076}