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