001package jmri.jmrit.symbolicprog;
002
003import java.awt.event.ActionEvent;
004import java.io.File;
005import javax.swing.AbstractAction;
006import javax.swing.JFileChooser;
007import javax.swing.JFrame;
008import javax.swing.JLabel;
009import org.slf4j.Logger;
010import org.slf4j.LoggerFactory;
011
012/**
013 * Action to import the CV values from a LokProgrammer CV list file.
014 *
015 * @author Bob Jacobsen Copyright (C) 2003
016 * @author Dave Heap Copyright (C) 2015
017 */
018public class GenericImportAction extends AbstractAction {
019
020    CvTableModel mModel;
021    JFrame mParent;
022    JLabel mStatus;
023    String mActionName;
024    String mFileFilterName;
025    String mFileExt1;
026    String mFileExt2;
027    JFileChooser fileChooser;
028
029    public GenericImportAction(String actionName, CvTableModel pModel, JFrame pParent, JLabel pStatus, String fileFilterName, String fileExt1, String fileExt2) {
030        super(actionName);
031        mModel = pModel;
032        mParent = pParent;
033        mStatus = pStatus;
034        mActionName = actionName;
035        mFileFilterName = fileFilterName;
036        mFileExt1 = fileExt1;
037        mFileExt2 = fileExt2;
038
039    }
040
041    @Override
042    public void actionPerformed(ActionEvent e) {
043
044        log.debug("start to import {}", mActionName);
045        mStatus.setText(java.text.MessageFormat.format(
046                SymbolicProgBundle.getMessage("MenuImportAction"),
047                new Object[]{mActionName}));
048
049        if (fileChooser == null) {
050            fileChooser = jmri.jmrit.XmlFile.userFileChooser(mFileFilterName, mFileExt1, mFileExt2);
051
052        }
053
054        int retVal = fileChooser.showOpenDialog(mParent);
055
056        if (retVal == JFileChooser.APPROVE_OPTION) {
057            File file = fileChooser.getSelectedFile();
058            log.debug("Import from {} \"{}\"", mActionName, file);
059
060            if (launchImporter(file, mModel)) {
061                mStatus.setText(Bundle.getMessage("StateOK"));
062            } else {
063                mStatus.setText(java.text.MessageFormat.format(
064                SymbolicProgBundle.getMessage("MenuImportError"),
065                new Object[]{file}));
066            }
067        } else {
068            mStatus.setText(Bundle.getMessage("StateCancelled"));
069        }
070    }
071
072    boolean launchImporter(File file, CvTableModel tableModel) {
073        return false;
074    }
075    
076    private final static Logger log = LoggerFactory.getLogger(GenericImportAction.class);
077}