001package jmri.jmrit.symbolicprog;
002
003import java.io.File;
004import java.io.IOException;
005import javax.swing.JLabel;
006
007import jmri.jmrit.roster.RosterEntry;
008import jmri.jmrit.symbolicprog.tabbedframe.PaneProgFrame;
009
010/**
011 * Action to import the RosterEntry values from a TCS data file.
012 * <p>
013 * TODO: Note: This ends with an update of the GUI from the RosterEntry.
014 * This means that they (RE and GUI)
015 * now agree, which has the side effect of erasing the dirty state.  Better
016 * would be to do the import directly into the GUI. See TcsImporter.
017 *
018 * @author Bob Jacobsen Copyright (C) 2003, 2023
019 * @author Dave Heap Copyright (C) 2015
020 */
021public class TcsImportAction extends GenericImportAction {
022
023    public TcsImportAction(String actionName, CvTableModel pModel, VariableTableModel vModel, PaneProgFrame pParent, JLabel pStatus, RosterEntry re) {
024        super(actionName, pModel, pParent, pStatus, "TCS files", "txt", null);
025        this.rosterEntry = re;
026        this.frame = pParent;
027        this.vModel = vModel;
028    }
029
030    RosterEntry rosterEntry;
031    PaneProgFrame frame;
032    VariableTableModel vModel;
033
034    @Override
035    boolean launchImporter(File file, CvTableModel tableModel) {
036        try {
037            // ctor launches operation
038            var importer = new TcsImporter(file, tableModel, vModel);
039            importer.setRosterEntry(rosterEntry);
040
041            // now update the GUI from the roster entry
042            frame.getRosterPane().updateGUI(rosterEntry);
043            frame.getFnLabelPane().updateFromEntry(rosterEntry);
044
045            return true;
046        } catch (IOException ex) {
047            return false;
048        }
049    }
050}