001package jmri.jmrit.beantable;
002
003import java.awt.event.ActionEvent;
004
005import jmri.InstanceManager;
006import jmri.SignalHead;
007import jmri.SignalHeadManager;
008
009/**
010 * Swing action to create and register a SignalHeadTable GUI.
011 *
012 * @author Bob Jacobsen Copyright (C) 2003,2006,2007, 2008, 2009
013 * @author Petr Koud'a Copyright (C) 2007
014 * @author Egbert Broerse Copyright (C) 2016
015 */
016public class SignalHeadTableAction extends AbstractTableAction<SignalHead> {
017
018    /**
019     * Create an action with a specific title.
020     * <p>
021     * Note that the argument is the Action title, not the title of the
022     * resulting frame. Perhaps this should be changed?
023     *
024     * @param s title of the action
025     */
026    public SignalHeadTableAction(String s) {
027        super(s);
028        // disable ourself if there is no primary Signal Head manager available
029        if (InstanceManager.getNullableDefault(SignalHeadManager.class) == null) {
030            super.setEnabled(false);
031        }
032    }
033
034    public SignalHeadTableAction() {
035        this(Bundle.getMessage("TitleSignalTable"));
036    }
037
038    /**
039     * Create the JTable DataModel, along with the changes for the specific case
040     * of SignalHeads.
041     */
042    @Override
043    protected void createModel() {
044        m = new SignalHeadTableModel();
045    }
046
047    @Override
048    protected void setTitle() {
049        f.setTitle(Bundle.getMessage("TitleSignalTable"));
050    }
051
052    @Override
053    protected String helpTarget() {
054        return "package.jmri.jmrit.beantable.SignalHeadTable";
055    }
056
057    private SignalHeadAddEditFrame addFrame = null;
058
059    /**
060     * Provide GUI for adding a new SignalHead.
061     * <p>
062     * Creates a new SignalHeadAddEditFrame, or makes an existing frame visible
063     * and clearing the SystemName and UserName fields.
064     * @param e name of the event heard
065     */
066    @Override
067    protected void addPressed(ActionEvent e) {
068        if (addFrame == null) {
069            addFrame = new SignalHeadAddEditFrame(null){
070                @Override
071                public void dispose() {
072                    addFrame = null;
073                    super.dispose();
074                }
075            };
076            addFrame.initComponents();
077        } else {
078            // clear older entries
079            addFrame.setVisible(true);
080            addFrame.resetAddressFields();
081        }
082    }
083
084    @Override
085    public void dispose() {
086        if (addFrame !=null){
087            addFrame.setVisible(false);
088            addFrame.dispose();
089            addFrame = null;
090        }
091        super.dispose();
092    }
093
094    @Override
095    protected String getClassName() {
096        return SignalHeadTableAction.class.getName();
097    }
098
099    @Override
100    public String getClassDescription() {
101        return Bundle.getMessage("TitleSignalTable");
102    }
103
104    // private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SignalHeadTableAction.class);
105
106}