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