001package jmri.jmrit.operations.trains.gui;
002
003import java.awt.Color;
004import java.awt.Dimension;
005import java.util.List;
006import java.util.ResourceBundle;
007
008import javax.swing.*;
009
010import jmri.InstanceManager;
011import jmri.jmrit.operations.OperationsFrame;
012import jmri.jmrit.operations.OperationsXml;
013import jmri.jmrit.operations.automation.gui.AutomationsTableFrameAction;
014import jmri.jmrit.operations.locations.Location;
015import jmri.jmrit.operations.locations.LocationManager;
016import jmri.jmrit.operations.setup.Control;
017import jmri.jmrit.operations.setup.Setup;
018import jmri.jmrit.operations.setup.backup.AutoSave;
019import jmri.jmrit.operations.setup.gui.*;
020import jmri.jmrit.operations.trains.Train;
021import jmri.jmrit.operations.trains.TrainManager;
022import jmri.jmrit.operations.trains.excel.SetupExcelProgramFrameAction;
023import jmri.jmrit.operations.trains.excel.TrainCustomManifest;
024import jmri.jmrit.operations.trains.schedules.*;
025import jmri.jmrit.operations.trains.tools.*;
026import jmri.swing.JTablePersistenceManager;
027import jmri.util.swing.JmriJOptionPane;
028
029/**
030 * Frame for adding and editing the train roster for operations.
031 *
032 * @author Bob Jacobsen Copyright (C) 2001
033 * @author Daniel Boudreau Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013,
034 *         2014
035 */
036public class TrainsTableFrame extends OperationsFrame implements java.beans.PropertyChangeListener {
037
038    public static final String MOVE = Bundle.getMessage("Move");
039    public static final String TERMINATE = Bundle.getMessage("Terminate");
040    public static final String RESET = Bundle.getMessage("Reset");
041    public static final String CONDUCTOR = Bundle.getMessage("Conductor");
042
043    TrainManager trainManager = InstanceManager.getDefault(TrainManager.class);
044    LocationManager locationManager = InstanceManager.getDefault(LocationManager.class);
045
046    public TrainsTableModel trainsModel;
047    JTable trainsTable;
048    JScrollPane trainsPane;
049
050    // labels
051    JLabel numTrains = new JLabel();
052    JLabel textTrains = new JLabel(Bundle.getMessage("trains"));
053    JLabel textSep1 = new JLabel("      ");
054
055    // radio buttons
056    JRadioButton showTime = new JRadioButton(Bundle.getMessage("Time"));
057    JRadioButton showId = new JRadioButton(Bundle.getMessage("Id"));
058
059    JRadioButton moveRB = new JRadioButton(MOVE);
060    JRadioButton terminateRB = new JRadioButton(TERMINATE);
061    JRadioButton resetRB = new JRadioButton(RESET);
062    JRadioButton conductorRB = new JRadioButton(CONDUCTOR);
063
064    // major buttons
065    JButton addButton = new JButton(Bundle.getMessage("AddTrain"));
066    JButton buildButton = new JButton(Bundle.getMessage("Build"));
067    JButton printButton = new JButton(Bundle.getMessage("Print"));
068    JButton openFileButton = new JButton(Bundle.getMessage("OpenFile"));
069    JButton runFileButton = new JButton(Bundle.getMessage("RunFile"));
070    JButton switchListsButton = new JButton(Bundle.getMessage("SwitchLists"));
071    JButton terminateButton = new JButton(Bundle.getMessage("Terminate"));
072    JButton saveButton = new JButton(Bundle.getMessage("SaveBuilds"));
073
074    // check boxes
075    JCheckBox buildMsgBox = new JCheckBox(Bundle.getMessage("BuildMessages"));
076    JCheckBox buildReportBox = new JCheckBox(Bundle.getMessage("BuildReport"));
077    JCheckBox printPreviewBox = new JCheckBox(Bundle.getMessage("Preview"));
078    JCheckBox openFileBox = new JCheckBox(Bundle.getMessage("OpenFile"));
079    JCheckBox runFileBox = new JCheckBox(Bundle.getMessage("RunFile"));
080    public JCheckBox showAllBox = new JCheckBox(Bundle.getMessage("ShowAllTrains"));
081
082    public TrainsTableFrame() {
083        super();
084
085        updateTitle();
086
087        // create ShutDownTasks
088        createShutDownTask();
089        // always check for dirty operations files
090        setModifiedFlag(true);
091
092        // general GUI configuration
093        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
094
095        // Set up the jtable in a Scroll Pane..
096        trainsModel = new TrainsTableModel();
097        trainsTable = new JTable(trainsModel);
098        trainsPane = new JScrollPane(trainsTable);
099        trainsModel.initTable(trainsTable, this);
100
101        // Set up the control panel
102        // row 1
103        JPanel cp1 = new JPanel();
104        cp1.setLayout(new BoxLayout(cp1, BoxLayout.X_AXIS));
105
106        JPanel show = new JPanel();
107        show.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("ShowClickToSort")));
108        show.add(showTime);
109        show.add(showId);
110
111        JPanel build = new JPanel();
112        build.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Build")));
113        build.add(showAllBox);
114
115        JPanel function = new JPanel();
116        function.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Function")));
117        function.add(printPreviewBox);
118        function.add(openFileBox);
119        function.add(runFileBox);
120
121        JPanel options = new JPanel();
122        options.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Options")));
123        options.add(buildMsgBox);
124        options.add(buildReportBox);
125
126        JPanel action = new JPanel();
127        action.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Action")));
128        action.add(moveRB);
129        action.add(conductorRB);
130        action.add(terminateRB);
131        action.add(resetRB);
132
133        cp1.add(show);
134        cp1.add(build);
135        cp1.add(function);
136        cp1.add(options);
137        cp1.add(action);
138
139        // tool tips, see setPrintButtonText() for more tool tips
140        addButton.setToolTipText(Bundle.getMessage("AddTrainTip"));
141        buildButton.setToolTipText(Bundle.getMessage("BuildSelectedTip"));
142        switchListsButton.setToolTipText(Bundle.getMessage("PreviewPrintSwitchListsTip"));
143
144        terminateButton.setToolTipText(Bundle.getMessage("TerminateSelectedTip"));
145        saveButton.setToolTipText(Bundle.getMessage("SaveBuildsTip"));
146        openFileButton.setToolTipText(Bundle.getMessage("OpenFileButtonTip"));
147        runFileButton.setToolTipText(Bundle.getMessage("RunFileButtonTip"));
148        buildMsgBox.setToolTipText(Bundle.getMessage("BuildMessagesTip"));
149        printPreviewBox.setToolTipText(Bundle.getMessage("PreviewTip"));
150        openFileBox.setToolTipText(Bundle.getMessage("OpenFileTip"));
151        runFileBox.setToolTipText(Bundle.getMessage("RunFileTip"));
152        showAllBox.setToolTipText(Bundle.getMessage("ShowAllTrainsTip"));
153
154        moveRB.setToolTipText(Bundle.getMessage("MoveTip"));
155        terminateRB.setToolTipText(Bundle.getMessage("TerminateTip"));
156        resetRB.setToolTipText(Bundle.getMessage("ResetTip"));
157        conductorRB.setToolTipText(Bundle.getMessage("ConductorTip"));
158
159        // row 2
160        JPanel addTrain = new JPanel();
161        addTrain.setBorder(BorderFactory.createTitledBorder(""));
162        addTrain.add(numTrains);
163        addTrain.add(textTrains);
164        addTrain.add(textSep1);
165        addTrain.add(addButton);
166
167        numTrains.setText(Integer.toString(trainManager.getNumEntries()));
168
169        JPanel select = new JPanel();
170        select.setBorder(BorderFactory.createTitledBorder(""));
171        select.add(buildButton);
172        select.add(printButton);
173        select.add(openFileButton);
174        select.add(runFileButton);
175        select.add(switchListsButton);
176        select.add(terminateButton);
177
178        JPanel save = new JPanel();
179        save.setBorder(BorderFactory.createTitledBorder(""));
180        save.add(saveButton);
181
182        JPanel cp2 = new JPanel();
183        cp2.setLayout(new BoxLayout(cp2, BoxLayout.X_AXIS));
184        cp2.add(addTrain);
185        cp2.add(select);
186        cp2.add(save);
187
188        // place controls in scroll pane
189        JPanel controlPanel = new JPanel();
190        controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
191        controlPanel.add(cp1);
192        controlPanel.add(cp2);
193
194        JScrollPane controlPane = new JScrollPane(controlPanel);
195
196        getContentPane().add(trainsPane);
197        getContentPane().add(controlPane);
198
199        // setup buttons
200        addButtonAction(addButton);
201        addButtonAction(buildButton);
202        addButtonAction(printButton);
203        addButtonAction(openFileButton);
204        addButtonAction(runFileButton);
205        addButtonAction(switchListsButton);
206        addButtonAction(terminateButton);
207        addButtonAction(saveButton);
208
209        ButtonGroup showGroup = new ButtonGroup();
210        showGroup.add(showTime);
211        showGroup.add(showId);
212        showTime.setSelected(true);
213
214        ButtonGroup actionGroup = new ButtonGroup();
215        actionGroup.add(moveRB);
216        actionGroup.add(conductorRB);
217        actionGroup.add(terminateRB);
218        actionGroup.add(resetRB);
219
220        addRadioButtonAction(showTime);
221        addRadioButtonAction(showId);
222
223        addRadioButtonAction(moveRB);
224        addRadioButtonAction(terminateRB);
225        addRadioButtonAction(resetRB);
226        addRadioButtonAction(conductorRB);
227
228        buildMsgBox.setSelected(trainManager.isBuildMessagesEnabled());
229        buildReportBox.setSelected(trainManager.isBuildReportEnabled());
230        printPreviewBox.setSelected(trainManager.isPrintPreviewEnabled());
231        openFileBox.setSelected(trainManager.isOpenFileEnabled());
232        runFileBox.setSelected(trainManager.isRunFileEnabled());
233        showAllBox.setSelected(trainsModel.isShowAll());
234
235        // show open files only if create csv is enabled
236        updateRunAndOpenButtons();
237
238        addCheckBoxAction(buildMsgBox);
239        addCheckBoxAction(buildReportBox);
240        addCheckBoxAction(printPreviewBox);
241        addCheckBoxAction(showAllBox);
242        addCheckBoxAction(openFileBox);
243        addCheckBoxAction(runFileBox);
244
245        // Set the button text to Print or Preview
246        setPrintButtonText();
247        // Set the train action button text to Move or Terminate
248        setTrainActionButton();
249
250        // build menu
251        JMenuBar menuBar = new JMenuBar();
252        JMenu toolMenu = new JMenu(Bundle.getMessage("MenuTools"));
253        toolMenu.add(new OptionAction());
254        toolMenu.add(new PrintOptionAction());
255        toolMenu.add(new BuildReportOptionAction());
256        toolMenu.addSeparator();
257        toolMenu.add(new TrainsByCarTypeAction());
258        toolMenu.add(new ChangeDepartureTimesAction());
259        toolMenu.add(new TrainsScheduleAction());
260        toolMenu.add(new TrainsTableSetColorAction());
261        toolMenu.add(new TrainCopyAction());
262        toolMenu.addSeparator();
263        toolMenu.add(new TrainsScriptAction(this));
264        toolMenu.add(new AutomationsTableFrameAction());
265        toolMenu.add(new SetupExcelProgramFrameAction());
266        toolMenu.addSeparator();
267        toolMenu.add(new ExportTrainRosterAction());
268        toolMenu.add(new ExportTimetableAction());
269        toolMenu.add(new ExportTrainLineupsAction());
270        toolMenu.addSeparator();
271        toolMenu.add(new TrainByCarTypeAction(null));
272        toolMenu.addSeparator();
273        toolMenu.add(new PrintTrainsAction(false, this));
274        toolMenu.add(new PrintTrainsAction(true, this));
275        toolMenu.add(new PrintSavedTrainManifestAction(false, null));
276        toolMenu.add(new PrintSavedTrainManifestAction(true, null));
277
278        menuBar.add(toolMenu);
279        menuBar.add(new jmri.jmrit.operations.OperationsMenu());
280        setJMenuBar(menuBar);
281
282        // add help menu to window
283        addHelpMenu("package.jmri.jmrit.operations.Operations_Trains", true); // NOI18N
284
285        initMinimumSize(new Dimension(Control.panelWidth700, Control.panelHeight250));
286
287        addHorizontalScrollBarKludgeFix(controlPane, controlPanel);
288
289        // listen for train schedule changes
290        InstanceManager.getDefault(TrainScheduleManager.class).addPropertyChangeListener(this);
291        // listen for changes in the number of trains
292        trainManager.addPropertyChangeListener(this);
293        Setup.getDefault().addPropertyChangeListener(this);
294        // listen for location switch list changes
295        addPropertyChangeLocations();
296
297        // auto save
298        AutoSave.start();
299    }
300
301    @Override
302    public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) {
303        log.debug("radio button activated");
304        // clear any sorts by column
305        clearTableSort(trainsTable);
306        if (ae.getSource() == showId) {
307            trainsModel.setSort(trainsModel.SORTBYID);
308        }
309        if (ae.getSource() == showTime) {
310            trainsModel.setSort(trainsModel.SORTBYTIME);
311        }
312        if (ae.getSource() == moveRB) {
313            trainManager.setTrainsFrameTrainAction(MOVE);
314        }
315        if (ae.getSource() == terminateRB) {
316            trainManager.setTrainsFrameTrainAction(TERMINATE);
317        }
318        if (ae.getSource() == resetRB) {
319            trainManager.setTrainsFrameTrainAction(RESET);
320        }
321        if (ae.getSource() == conductorRB) {
322            trainManager.setTrainsFrameTrainAction(CONDUCTOR);
323        }
324    }
325
326    TrainSwitchListEditFrame tslef;
327
328    // add, build, print, switch lists, terminate, and save buttons
329    @Override
330    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
331        // log.debug("train button activated");
332        if (ae.getSource() == addButton) {
333            new TrainEditFrame(null);
334        }
335        if (ae.getSource() == buildButton) {
336            runFileButton.setEnabled(false);
337            // uses a thread which allows table updates during build
338            trainManager.buildSelectedTrains(getSortByList());
339        }
340        if (ae.getSource() == printButton) {
341            trainManager.printSelectedTrains(getSortByList());
342        }
343        if (ae.getSource() == openFileButton) {
344            openFile();
345        }
346        if (ae.getSource() == runFileButton) {
347            runExcel();
348        }
349        if (ae.getSource() == switchListsButton) {
350            if (tslef != null) {
351                tslef.dispose();
352            }
353            tslef = new TrainSwitchListEditFrame();
354            tslef.initComponents();
355        }
356        if (ae.getSource() == terminateButton) {
357            trainManager.terminateSelectedTrains(getSortByList());
358        }
359        if (ae.getSource() == saveButton) {
360            storeValues();
361        }
362    }
363
364    private void openFile() {
365        // open the csv files
366        List<Train> trains = getSortByList();
367        for (Train train : trains) {
368            if (train.isBuildEnabled()) {
369                if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) {
370                    int response = JmriJOptionPane.showConfirmDialog(this,
371                            Bundle.getMessage("NeedToBuildBeforeOpenFile",
372                                    train.getName()),
373                            Bundle.getMessage("ErrorTitle"), JmriJOptionPane.OK_CANCEL_OPTION);
374                    if (response != JmriJOptionPane.OK_OPTION) {
375                        break;
376                    }
377                } else if (train.isBuilt()) {
378                    train.openFile();
379                }
380            }
381        }
382    }
383
384    private void runExcel() {
385        // Run on thread since addCsvFile(file) can wait for excel program to complete
386        Thread runExcel = jmri.util.ThreadingUtil.newThread(() -> {
387            // Processes the CSV Manifest files using an external custom program.
388            TrainCustomManifest tcm = InstanceManager.getDefault(TrainCustomManifest.class);
389            if (!tcm.doesExcelFileExist()) {
390                log.warn("Manifest creator file not found!, directory path: {}, file name: {}",
391                        tcm.getDirectoryPathName(),
392                        tcm.getFileName());
393                JmriJOptionPane.showMessageDialog(this,
394                        Bundle.getMessage("LoadDirectoryNameFileName",
395                                tcm.getDirectoryPathName(), tcm.getFileName()),
396                        Bundle.getMessage("ManifestCreatorNotFound"), JmriJOptionPane.ERROR_MESSAGE);
397                return;
398            }
399            List<Train> trains = getSortByList();
400            for (Train train : trains) {
401                if (train.isBuildEnabled()) {
402                    if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) {
403                        int response = JmriJOptionPane.showConfirmDialog(this,
404                                Bundle.getMessage("NeedToBuildBeforeRunFile",
405                                        train.getName()),
406                                Bundle.getMessage("ErrorTitle"), JmriJOptionPane.OK_CANCEL_OPTION);
407                        if (response != JmriJOptionPane.OK_OPTION) {
408                            break;
409                        }
410                    } else if (train.isBuilt()) {
411                        // Add csv manifest file to our collection to be processed.
412                        tcm.addCsvFile(train.createCsvManifestFile());
413                        train.setPrinted(true);
414                    }
415                }
416            }
417            // Now run the user specified custom Manifest processor program
418            tcm.process();
419        });
420        runExcel.setName("Run Excel program"); // NOI18N
421        runExcel.start();
422    }
423
424    SortOrder _status = SortOrder.ASCENDING;
425
426    public String getSortBy() {
427        // set the defaults
428        String sortBy = TrainsTableModel.TIMECOLUMNNAME;
429        _status = SortOrder.ASCENDING;
430        // now look to see if a sort is active
431        for (RowSorter.SortKey key : trainsTable.getRowSorter().getSortKeys()) {
432            String name = trainsModel.getColumnName(key.getColumn());
433            SortOrder status = key.getSortOrder();
434            // log.debug("Column {} status {}", name, status);
435            if (!status.equals(SortOrder.UNSORTED) && !name.isEmpty()) {
436                sortBy = name;
437                _status = status;
438                break;
439            }
440        }
441        return sortBy;
442    }
443
444    public List<Train> getSortByList() {
445        return getSortByList(getSortBy());
446    }
447
448    public List<Train> getSortByList(String sortBy) {
449        List<Train> sysList;
450
451        if (sortBy.equals(TrainsTableModel.IDCOLUMNNAME)) {
452            sysList = trainManager.getTrainsByIdList();
453        } else if (sortBy.equals(TrainsTableModel.TIMECOLUMNNAME)) {
454            sysList = trainManager.getTrainsByTimeList();
455        } else if (sortBy.equals(TrainsTableModel.DEPARTSCOLUMNNAME)) {
456            sysList = trainManager.getTrainsByDepartureList();
457        } else if (sortBy.equals(TrainsTableModel.TERMINATESCOLUMNNAME)) {
458            sysList = trainManager.getTrainsByTerminatesList();
459        } else if (sortBy.equals(TrainsTableModel.ROUTECOLUMNNAME)) {
460            sysList = trainManager.getTrainsByRouteList();
461        } else if (sortBy.equals(TrainsTableModel.STATUSCOLUMNNAME)) {
462            sysList = trainManager.getTrainsByStatusList();
463        } else if (sortBy.equals(TrainsTableModel.DESCRIPTIONCOLUMNNAME)) {
464            sysList = trainManager.getTrainsByDescriptionList();
465        } else {
466            sysList = trainManager.getTrainsByNameList();
467        }
468        return sysList;
469    }
470
471    // Modifies button text and tool tips
472    private void setPrintButtonText() {
473        if (printPreviewBox.isSelected()) {
474            printButton.setText(Bundle.getMessage("Preview"));
475            printButton.setToolTipText(Bundle.getMessage("PreviewSelectedTip"));
476            buildReportBox.setToolTipText(Bundle.getMessage("BuildReportPreviewTip"));
477        } else {
478            printButton.setText(Bundle.getMessage("Print"));
479            printButton.setToolTipText(Bundle.getMessage("PrintSelectedTip"));
480            buildReportBox.setToolTipText(Bundle.getMessage("BuildReportPrintTip"));
481        }
482    }
483
484    private void setTrainActionButton() {
485        moveRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.MOVE));
486        terminateRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.TERMINATE));
487        resetRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.RESET));
488        conductorRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.CONDUCTOR));
489    }
490
491    @Override
492    public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) {
493        if (ae.getSource() == buildMsgBox) {
494            trainManager.setBuildMessagesEnabled(buildMsgBox.isSelected());
495        }
496        if (ae.getSource() == buildReportBox) {
497            trainManager.setBuildReportEnabled(buildReportBox.isSelected());
498        }
499        if (ae.getSource() == printPreviewBox) {
500            trainManager.setPrintPreviewEnabled(printPreviewBox.isSelected());
501            setPrintButtonText(); // set the button text for Print or Preview
502        }
503        if (ae.getSource() == openFileBox) {
504            trainManager.setOpenFileEnabled(openFileBox.isSelected());
505            runFileBox.setSelected(false);
506            trainManager.setRunFileEnabled(false);
507        }
508        if (ae.getSource() == runFileBox) {
509            trainManager.setRunFileEnabled(runFileBox.isSelected());
510            openFileBox.setSelected(false);
511            trainManager.setOpenFileEnabled(false);
512        }
513        if (ae.getSource() == showAllBox) {
514            trainsModel.setShowAll(showAllBox.isSelected());
515        }
516    }
517
518    private void updateTitle() {
519        String title = Bundle.getMessage("TitleTrainsTable");
520        TrainSchedule sch = InstanceManager.getDefault(TrainScheduleManager.class).getActiveSchedule();
521        if (sch != null) {
522            title = title + " " + sch.getName();
523        }
524        setTitle(title);
525    }
526
527    private void updateSwitchListButton() {
528        List<Location> locations = locationManager.getList();
529        for (Location location : locations) {
530            if (location != null && location.isSwitchListEnabled() && location.getStatus().equals(Location.MODIFIED)) {
531                switchListsButton.setBackground(Color.RED);
532                return;
533            }
534        }
535        switchListsButton.setBackground(Color.GREEN);
536    }
537
538    // show open files only if create csv is enabled
539    private void updateRunAndOpenButtons() {
540        openFileBox.setVisible(Setup.isGenerateCsvManifestEnabled());
541        openFileButton.setVisible(Setup.isGenerateCsvManifestEnabled());
542        runFileBox.setVisible(Setup.isGenerateCsvManifestEnabled());
543        runFileButton.setVisible(Setup.isGenerateCsvManifestEnabled());
544    }
545
546    private synchronized void addPropertyChangeLocations() {
547        List<Location> locations = locationManager.getList();
548        for (Location location : locations) {
549            location.addPropertyChangeListener(this);
550        }
551    }
552
553    private synchronized void removePropertyChangeLocations() {
554        List<Location> locations = locationManager.getList();
555        for (Location location : locations) {
556            location.removePropertyChangeListener(this);
557        }
558    }
559
560    @Override
561    public void dispose() {
562        trainsModel.dispose();
563        trainManager.runShutDownScripts();
564        trainManager.removePropertyChangeListener(this);
565        InstanceManager.getDefault(TrainScheduleManager.class).removePropertyChangeListener(this);
566        Setup.getDefault().removePropertyChangeListener(this);
567        removePropertyChangeLocations();
568        setModifiedFlag(false);
569        InstanceManager.getOptionalDefault(JTablePersistenceManager.class).ifPresent(tpm -> {
570            tpm.stopPersisting(trainsTable);
571        });
572        super.dispose();
573    }
574
575    @Override
576    protected void handleModified() {
577        if (!getModifiedFlag()) {
578            return;
579        }
580        if (Setup.isAutoSaveEnabled()) {
581            storeValues();
582            return;
583        }
584        if (OperationsXml.areFilesDirty()) {
585            int result = JmriJOptionPane.showOptionDialog(this, Bundle.getMessage("PromptQuitWindowNotWritten"),
586                    Bundle.getMessage("PromptSaveQuit"), JmriJOptionPane.YES_NO_OPTION,
587                    JmriJOptionPane.WARNING_MESSAGE, null,
588                    new String[] { ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnYesSave"), // NOI18N
589                            ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnNoClose") }, // NOI18N
590                    ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnYesSave"));
591            if (result == JmriJOptionPane.YES_OPTION) {
592                // user wants to save
593                storeValues();
594            }
595        }
596    }
597
598    @Override
599    protected void storeValues() {
600        super.storeValues();
601    }
602
603    @Override
604    public void propertyChange(java.beans.PropertyChangeEvent e) {
605        if (Control.SHOW_PROPERTY) {
606            log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(),
607                    e.getNewValue());
608        }
609        if (e.getPropertyName().equals(TrainScheduleManager.SCHEDULE_ID_CHANGED_PROPERTY)) {
610            updateTitle();
611        }
612        if (e.getPropertyName().equals(Location.STATUS_CHANGED_PROPERTY) ||
613                e.getPropertyName().equals(Location.SWITCHLIST_CHANGED_PROPERTY)) {
614            log.debug("update switch list button location ({})", e.getSource());
615            updateSwitchListButton();
616        }
617        if (e.getPropertyName().equals(Setup.MANIFEST_CSV_PROPERTY_CHANGE)) {
618            updateRunAndOpenButtons();
619        }
620        if (e.getPropertyName().equals(TrainManager.LISTLENGTH_CHANGED_PROPERTY)) {
621            numTrains.setText(Integer.toString(trainManager.getNumEntries()));
622        }
623        if (e.getPropertyName().equals(TrainManager.TRAINS_BUILT_CHANGED_PROPERTY)) {
624            runFileButton.setEnabled(true);
625        }
626    }
627
628    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TrainsTableFrame.class);
629}