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 } 101 102 public void addToFrame(RosterGroupTableFrame f) { 103 } 104 105 void setTitle() { 106 f.setTitle(Bundle.getMessage("RosterGroupTable")); 107 } 108 109 String helpTarget() { 110 return "package.jmri.jmrit.roster.swing.RosterGroupTable"; // NOI18N 111 } 112 113 void comboSelected(ActionEvent e, String group) { 114 m.setGroup(Roster.ROSTER_GROUP_PREFIX + group); 115 m.fireTableDataChanged(); 116 117 } 118 119 @Override 120 public jmri.util.swing.JmriPanel makePanel() { 121 throw new IllegalArgumentException("Should not be invoked"); 122 } 123 124 private final static Logger log = LoggerFactory.getLogger(RosterGroupTableAction.class); 125}