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 TrainsScheduleAction());
258        toolMenu.addSeparator();
259        toolMenu.add(new TrainsByCarTypeAction());
260        toolMenu.add(new TrainByCarTypeAction(null));
261        toolMenu.addSeparator();
262        toolMenu.add(new ChangeDepartureTimesAction());
263        toolMenu.add(new TrainsTableSetColorAction());
264        toolMenu.add(new TrainCopyAction());
265        toolMenu.addSeparator();
266        toolMenu.add(new TrainsScriptAction(this));
267        toolMenu.add(new AutomationsTableFrameAction());
268        toolMenu.add(new SetupExcelProgramFrameAction());
269        toolMenu.addSeparator();
270        toolMenu.add(new ExportTrainRosterAction());
271        toolMenu.add(new ExportTimetableAction());
272        toolMenu.add(new ExportTrainLineupsAction());
273        toolMenu.addSeparator();
274        toolMenu.add(new PrintTrainsAction(false, this));
275        toolMenu.add(new PrintTrainsAction(true, this));
276        toolMenu.add(new PrintSavedTrainManifestAction(false, null));
277        toolMenu.add(new PrintSavedTrainManifestAction(true, null));
278
279        menuBar.add(toolMenu);
280        menuBar.add(new jmri.jmrit.operations.OperationsMenu());
281        setJMenuBar(menuBar);
282
283        // add help menu to window
284        addHelpMenu("package.jmri.jmrit.operations.Operations_Trains", true); // NOI18N
285
286        initMinimumSize(new Dimension(Control.panelWidth700, Control.panelHeight250));
287
288        addHorizontalScrollBarKludgeFix(controlPane, controlPanel);
289
290        // listen for train schedule changes
291        InstanceManager.getDefault(TrainScheduleManager.class).addPropertyChangeListener(this);
292        // listen for changes in the number of trains
293        trainManager.addPropertyChangeListener(this);
294        Setup.getDefault().addPropertyChangeListener(this);
295        // listen for location switch list changes
296        addPropertyChangeLocations();
297
298        // auto save
299        AutoSave.start();
300    }
301
302    @Override
303    public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) {
304        log.debug("radio button activated");
305        // clear any sorts by column
306        clearTableSort(trainsTable);
307        if (ae.getSource() == showId) {
308            trainsModel.setSort(trainsModel.SORTBYID);
309        }
310        if (ae.getSource() == showTime) {
311            trainsModel.setSort(trainsModel.SORTBYTIME);
312        }
313        if (ae.getSource() == moveRB) {
314            trainManager.setTrainsFrameTrainAction(MOVE);
315        }
316        if (ae.getSource() == terminateRB) {
317            trainManager.setTrainsFrameTrainAction(TERMINATE);
318        }
319        if (ae.getSource() == resetRB) {
320            trainManager.setTrainsFrameTrainAction(RESET);
321        }
322        if (ae.getSource() == conductorRB) {
323            trainManager.setTrainsFrameTrainAction(CONDUCTOR);
324        }
325    }
326
327    TrainSwitchListEditFrame tslef;
328
329    // add, build, print, switch lists, terminate, and save buttons
330    @Override
331    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
332        // log.debug("train button activated");
333        if (ae.getSource() == addButton) {
334            new TrainEditFrame(null);
335        }
336        if (ae.getSource() == buildButton) {
337            runFileButton.setEnabled(false);
338            // uses a thread which allows table updates during build
339            trainManager.buildSelectedTrains(getSortByList());
340        }
341        if (ae.getSource() == printButton) {
342            trainManager.printSelectedTrains(getSortByList());
343        }
344        if (ae.getSource() == openFileButton) {
345            openFile();
346        }
347        if (ae.getSource() == runFileButton) {
348            runExcel();
349        }
350        if (ae.getSource() == switchListsButton) {
351            if (tslef != null) {
352                tslef.dispose();
353            }
354            tslef = new TrainSwitchListEditFrame();
355            tslef.initComponents();
356        }
357        if (ae.getSource() == terminateButton) {
358            trainManager.terminateSelectedTrains(getSortByList());
359        }
360        if (ae.getSource() == saveButton) {
361            storeValues();
362        }
363    }
364
365    private void openFile() {
366        // open the csv files
367        List<Train> trains = getSortByList();
368        for (Train train : trains) {
369            if (train.isBuildEnabled()) {
370                if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) {
371                    int response = JmriJOptionPane.showConfirmDialog(this,
372                            Bundle.getMessage("NeedToBuildBeforeOpenFile",
373                                    train.getName()),
374                            Bundle.getMessage("ErrorTitle"), JmriJOptionPane.OK_CANCEL_OPTION);
375                    if (response != JmriJOptionPane.OK_OPTION) {
376                        break;
377                    }
378                } else if (train.isBuilt()) {
379                    train.openFile();
380                }
381            }
382        }
383    }
384
385    private void runExcel() {
386        // Run on thread since addCsvFile(file) can wait for excel program to complete
387        Thread runExcel = jmri.util.ThreadingUtil.newThread(() -> {
388            // Processes the CSV Manifest files using an external custom program.
389            TrainCustomManifest tcm = InstanceManager.getDefault(TrainCustomManifest.class);
390            if (!tcm.doesExcelFileExist()) {
391                log.warn("Manifest creator file not found!, directory path: {}, file name: {}",
392                        tcm.getDirectoryPathName(),
393                        tcm.getFileName());
394                JmriJOptionPane.showMessageDialog(this,
395                        Bundle.getMessage("LoadDirectoryNameFileName",
396                                tcm.getDirectoryPathName(), tcm.getFileName()),
397                        Bundle.getMessage("ManifestCreatorNotFound"), JmriJOptionPane.ERROR_MESSAGE);
398                return;
399            }
400            List<Train> trains = getSortByList();
401            for (Train train : trains) {
402                if (train.isBuildEnabled()) {
403                    if (!train.isBuilt() && trainManager.isBuildMessagesEnabled()) {
404                        int response = JmriJOptionPane.showConfirmDialog(this,
405                                Bundle.getMessage("NeedToBuildBeforeRunFile",
406                                        train.getName()),
407                                Bundle.getMessage("ErrorTitle"), JmriJOptionPane.OK_CANCEL_OPTION);
408                        if (response != JmriJOptionPane.OK_OPTION) {
409                            break;
410                        }
411                    } else if (train.isBuilt()) {
412                        // Add csv manifest file to our collection to be processed.
413                        tcm.addCsvFile(train.createCsvManifestFile());
414                        train.setPrinted(true);
415                    }
416                }
417            }
418            // Now run the user specified custom Manifest processor program
419            tcm.process();
420        });
421        runExcel.setName("Run Excel program"); // NOI18N
422        runExcel.start();
423    }
424
425    SortOrder _status = SortOrder.ASCENDING;
426
427    public String getSortBy() {
428        // set the defaults
429        String sortBy = TrainsTableModel.TIMECOLUMNNAME;
430        _status = SortOrder.ASCENDING;
431        // now look to see if a sort is active
432        for (RowSorter.SortKey key : trainsTable.getRowSorter().getSortKeys()) {
433            String name = trainsModel.getColumnName(key.getColumn());
434            SortOrder status = key.getSortOrder();
435            // log.debug("Column {} status {}", name, status);
436            if (!status.equals(SortOrder.UNSORTED) && !name.isEmpty()) {
437                sortBy = name;
438                _status = status;
439                break;
440            }
441        }
442        return sortBy;
443    }
444
445    public List<Train> getSortByList() {
446        return getSortByList(getSortBy());
447    }
448
449    public List<Train> getSortByList(String sortBy) {
450        List<Train> sysList;
451
452        if (sortBy.equals(TrainsTableModel.IDCOLUMNNAME)) {
453            sysList = trainManager.getTrainsByIdList();
454        } else if (sortBy.equals(TrainsTableModel.TIMECOLUMNNAME)) {
455            sysList = trainManager.getTrainsByTimeList();
456        } else if (sortBy.equals(TrainsTableModel.DEPARTSCOLUMNNAME)) {
457            sysList = trainManager.getTrainsByDepartureList();
458        } else if (sortBy.equals(TrainsTableModel.TERMINATESCOLUMNNAME)) {
459            sysList = trainManager.getTrainsByTerminatesList();
460        } else if (sortBy.equals(TrainsTableModel.ROUTECOLUMNNAME)) {
461            sysList = trainManager.getTrainsByRouteList();
462        } else if (sortBy.equals(TrainsTableModel.STATUSCOLUMNNAME)) {
463            sysList = trainManager.getTrainsByStatusList();
464        } else if (sortBy.equals(TrainsTableModel.DESCRIPTIONCOLUMNNAME)) {
465            sysList = trainManager.getTrainsByDescriptionList();
466        } else {
467            sysList = trainManager.getTrainsByNameList();
468        }
469        return sysList;
470    }
471
472    // Modifies button text and tool tips
473    private void setPrintButtonText() {
474        if (printPreviewBox.isSelected()) {
475            printButton.setText(Bundle.getMessage("Preview"));
476            printButton.setToolTipText(Bundle.getMessage("PreviewSelectedTip"));
477            buildReportBox.setToolTipText(Bundle.getMessage("BuildReportPreviewTip"));
478        } else {
479            printButton.setText(Bundle.getMessage("Print"));
480            printButton.setToolTipText(Bundle.getMessage("PrintSelectedTip"));
481            buildReportBox.setToolTipText(Bundle.getMessage("BuildReportPrintTip"));
482        }
483    }
484
485    private void setTrainActionButton() {
486        moveRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.MOVE));
487        terminateRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.TERMINATE));
488        resetRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.RESET));
489        conductorRB.setSelected(trainManager.getTrainsFrameTrainAction().equals(TrainsTableFrame.CONDUCTOR));
490    }
491
492    @Override
493    public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) {
494        if (ae.getSource() == buildMsgBox) {
495            trainManager.setBuildMessagesEnabled(buildMsgBox.isSelected());
496        }
497        if (ae.getSource() == buildReportBox) {
498            trainManager.setBuildReportEnabled(buildReportBox.isSelected());
499        }
500        if (ae.getSource() == printPreviewBox) {
501            trainManager.setPrintPreviewEnabled(printPreviewBox.isSelected());
502            setPrintButtonText(); // set the button text for Print or Preview
503        }
504        if (ae.getSource() == openFileBox) {
505            trainManager.setOpenFileEnabled(openFileBox.isSelected());
506            runFileBox.setSelected(false);
507            trainManager.setRunFileEnabled(false);
508        }
509        if (ae.getSource() == runFileBox) {
510            trainManager.setRunFileEnabled(runFileBox.isSelected());
511            openFileBox.setSelected(false);
512            trainManager.setOpenFileEnabled(false);
513        }
514        if (ae.getSource() == showAllBox) {
515            trainsModel.setShowAll(showAllBox.isSelected());
516        }
517    }
518
519    private void updateTitle() {
520        String title = Bundle.getMessage("TitleTrainsTable");
521        TrainSchedule sch = InstanceManager.getDefault(TrainScheduleManager.class).getActiveSchedule();
522        if (sch != null) {
523            title = title + " " + sch.getName();
524        }
525        setTitle(title);
526    }
527
528    private void updateSwitchListButton() {
529        List<Location> locations = locationManager.getList();
530        for (Location location : locations) {
531            if (location != null && location.isSwitchListEnabled() && location.getStatus().equals(Location.MODIFIED)) {
532                switchListsButton.setBackground(Color.RED);
533                return;
534            }
535        }
536        switchListsButton.setBackground(Color.GREEN);
537    }
538
539    // show open files only if create csv is enabled
540    private void updateRunAndOpenButtons() {
541        openFileBox.setVisible(Setup.isGenerateCsvManifestEnabled());
542        openFileButton.setVisible(Setup.isGenerateCsvManifestEnabled());
543        runFileBox.setVisible(Setup.isGenerateCsvManifestEnabled());
544        runFileButton.setVisible(Setup.isGenerateCsvManifestEnabled());
545    }
546
547    private synchronized void addPropertyChangeLocations() {
548        List<Location> locations = locationManager.getList();
549        for (Location location : locations) {
550            location.addPropertyChangeListener(this);
551        }
552    }
553
554    private synchronized void removePropertyChangeLocations() {
555        List<Location> locations = locationManager.getList();
556        for (Location location : locations) {
557            location.removePropertyChangeListener(this);
558        }
559    }
560
561    @Override
562    public void dispose() {
563        trainsModel.dispose();
564        trainManager.runShutDownScripts();
565        trainManager.removePropertyChangeListener(this);
566        InstanceManager.getDefault(TrainScheduleManager.class).removePropertyChangeListener(this);
567        Setup.getDefault().removePropertyChangeListener(this);
568        removePropertyChangeLocations();
569        setModifiedFlag(false);
570        InstanceManager.getOptionalDefault(JTablePersistenceManager.class).ifPresent(tpm -> {
571            tpm.stopPersisting(trainsTable);
572        });
573        super.dispose();
574    }
575
576    @Override
577    protected void handleModified() {
578        if (!getModifiedFlag()) {
579            return;
580        }
581        if (Setup.isAutoSaveEnabled()) {
582            storeValues();
583            return;
584        }
585        if (OperationsXml.areFilesDirty()) {
586            int result = JmriJOptionPane.showOptionDialog(this, Bundle.getMessage("PromptQuitWindowNotWritten"),
587                    Bundle.getMessage("PromptSaveQuit"), JmriJOptionPane.YES_NO_OPTION,
588                    JmriJOptionPane.WARNING_MESSAGE, null,
589                    new String[] { ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnYesSave"), // NOI18N
590                            ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnNoClose") }, // NOI18N
591                    ResourceBundle.getBundle("jmri.util.UtilBundle").getString("WarnYesSave"));
592            if (result == JmriJOptionPane.YES_OPTION) {
593                // user wants to save
594                storeValues();
595            }
596        }
597    }
598
599    @Override
600    protected void storeValues() {
601        super.storeValues();
602    }
603
604    @Override
605    public void propertyChange(java.beans.PropertyChangeEvent e) {
606        if (Control.SHOW_PROPERTY) {
607            log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(),
608                    e.getNewValue());
609        }
610        if (e.getPropertyName().equals(TrainScheduleManager.SCHEDULE_ID_CHANGED_PROPERTY)) {
611            updateTitle();
612        }
613        if (e.getPropertyName().equals(Location.STATUS_CHANGED_PROPERTY) ||
614                e.getPropertyName().equals(Location.SWITCHLIST_CHANGED_PROPERTY)) {
615            log.debug("update switch list button location ({})", e.getSource());
616            updateSwitchListButton();
617        }
618        if (e.getPropertyName().equals(Setup.MANIFEST_CSV_PROPERTY_CHANGE)) {
619            updateRunAndOpenButtons();
620        }
621        if (e.getPropertyName().equals(TrainManager.LISTLENGTH_CHANGED_PROPERTY)) {
622            numTrains.setText(Integer.toString(trainManager.getNumEntries()));
623        }
624        if (e.getPropertyName().equals(TrainManager.TRAINS_BUILT_CHANGED_PROPERTY)) {
625            runFileButton.setEnabled(true);
626        }
627    }
628
629    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TrainsTableFrame.class);
630}