001package jmri.jmrit.symbolicprog;
002
003import java.awt.event.ActionEvent;
004import java.util.ResourceBundle;
005
006import javax.swing.AbstractAction;
007import javax.swing.JFrame;
008
009import jmri.util.swing.JmriJOptionPane;
010
011/**
012 * Action to create a dialog so that the user can select a factory reset to
013 * execute. The user can cancel this dialog skipping any resets
014 *
015 * @author Howard G. Penny Copyright (C) 2005
016 */
017public class FactoryResetAction extends AbstractAction {
018
019    ExtraMenuTableModel rModel;
020    JFrame mParent;
021
022    public FactoryResetAction(String actionName, ExtraMenuTableModel rpModel, JFrame pParent) {
023        super(actionName);
024        rModel = rpModel;
025        mParent = pParent;
026    }
027
028    @Override
029    public void actionPerformed(ActionEvent e) {
030
031        log.debug("start to display Factory Reset");
032        Object[] options;
033        options = new String[rModel.getRowCount()];
034        for (int i = 0; i < rModel.getRowCount(); i++) {
035            options[i] = (rModel.getValueAt(i, 0));
036        }
037        String s = (String) JmriJOptionPane.showInputDialog(
038                mParent,
039                "Factory Reset" + (options.length > 1 ? "s" : ""),
040                ResourceBundle.getBundle("jmri.jmrit.symbolicprog.SymbolicProgBundle").getString("FactoryResetTitle"),
041                JmriJOptionPane.WARNING_MESSAGE,
042                null,
043                options,
044                null);
045
046        //If a string was returned, a reset has been requested.
047        if ((s != null) && (s.length() > 0)) {
048            int i = 0;
049            while (!options[i].equals(s)) {
050                i++;
051            }
052            rModel.performReset(i);
053            return;
054        }
055
056    }
057    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FactoryResetAction.class);
058}