001package jmri.jmrit.roster.swing.rostergroup;
002
003import java.awt.event.ActionEvent;
004import java.awt.event.ActionListener;
005
006import javax.swing.Icon;
007import javax.swing.JComboBox;
008import javax.swing.JLabel;
009import javax.swing.JPanel;
010
011import org.slf4j.Logger;
012import org.slf4j.LoggerFactory;
013
014import jmri.jmrit.roster.Roster;
015import jmri.jmrit.roster.swing.RosterGroupComboBox;
016import jmri.util.swing.WindowInterface;
017
018/**
019 * Swing action to create and register a Roster Group Table.
020 *
021 * @author Bob Jacobsen Copyright (C) 2003
022 * @author Kevin Dickerson Copyright (C) 2009
023 */
024public class RosterGroupTableAction extends jmri.util.swing.JmriAbstractAction {
025
026    public RosterGroupTableAction(String s, WindowInterface wi) {
027        super(s, wi);
028    }
029
030    public RosterGroupTableAction(String s, Icon i, WindowInterface wi) {
031        super(s, i, wi);
032    }
033
034    /**
035     * Create an action with a specific title.
036     * <p>
037     * Note that the argument is the Action title, not the title of the
038     * resulting frame. Perhaps this should be changed?
039     * @param s action title though may be changed?
040     *
041     */
042    public RosterGroupTableAction(String s) {
043        super(s);
044
045    }
046
047    public RosterGroupTableAction() {
048        this(Bundle.getMessage("RosterGroupTable"));
049    }
050
051    RosterGroupTableModel m;
052    RosterGroupTableFrame f;
053
054    void createModel() {
055
056        m = new RosterGroupTableModel();
057    }
058
059    public void actionPerformed() {
060        // create the JTable model, with changes for specific NamedBean
061        createModel();
062
063        // create the frame
064        f = new RosterGroupTableFrame(m, helpTarget()) {
065            /**
066             * Include an "add" button
067             */
068            @Override
069            void extras() {
070                final JComboBox<String> selectCombo = new RosterGroupComboBox();
071                selectCombo.insertItemAt("", 0);
072                selectCombo.setSelectedIndex(-1);
073                JPanel p25 = new JPanel();
074                p25.add(new JLabel(Bundle.getMessage("SelectRosterGroup")));
075                p25.add(selectCombo);
076                addToTopBox(p25);
077                selectCombo.addActionListener(new ActionListener() {
078                    @Override
079                    public void actionPerformed(ActionEvent e) {
080                        try {
081                            comboSelected(e, selectCombo.getSelectedItem().toString());
082                        } catch (Exception ex) {
083                            log.debug("Null pointer exception");
084                        }
085                    }
086                });
087                selectCombo.setVisible(true);
088
089            }
090        };
091        setTitle();
092        addToFrame(f);
093        f.pack();
094        f.setVisible(true);
095    }
096
097    @Override
098    public void actionPerformed(ActionEvent e) {
099        actionPerformed();
100        // create the JTable model, with changes for specific NamedBean
101        //createModel();
102        //final Roster roster = Roster.getDefault();
103        // create the frame
104        //f = new RosterGroupTableFrame(m, helpTarget()){
105        /**
106         * Include an "save" button
107         */
108        /*    void extras() {
109                
110         final JComboBox<Object> selectCombo = roster.rosterGroupBox();
111         //addToTopBox(selectCombo);
112         selectCombo.insertItemAt("",0);
113         selectCombo.setSelectedIndex(-1);
114         JPanel p25 = new JPanel();
115         p25.add(new JLabel("Select Roster Group:"));
116         p25.add(selectCombo);
117         addToTopBox(p25);
118         selectCombo.addActionListener(new ActionListener() {
119         public void actionPerformed(ActionEvent e) {
120         comboSelected(e, selectCombo.getSelectedItem().toString());
121         }
122         });
123         }
124         };
125         setTitle();
126         addToFrame(f);
127         f.pack();
128         f.setVisible(true);*/
129    }
130
131    public void addToFrame(RosterGroupTableFrame f) {
132    }
133
134    void setTitle() {
135        f.setTitle(Bundle.getMessage("RosterGroupTable"));
136    }
137
138    String helpTarget() {
139        return "package.jmri.jmrit.roster.swing"; // NOI18N
140    }
141
142    void comboSelected(ActionEvent e, String group) {
143        m.setGroup(Roster.ROSTER_GROUP_PREFIX + group);
144        m.fireTableDataChanged();
145
146    }
147
148    @Override
149    public jmri.util.swing.JmriPanel makePanel() {
150        throw new IllegalArgumentException("Should not be invoked");
151    }
152
153    private final static Logger log = LoggerFactory.getLogger(RosterGroupTableAction.class);
154}