001package jmri.jmrix.ecos.swing.locodatabase;
002
003import javax.swing.JTabbedPane;
004import javax.swing.event.ChangeEvent;
005
006import jmri.*;
007import jmri.jmrit.beantable.AbstractTableAction;
008import jmri.jmrit.beantable.AbstractTableTabAction;
009import jmri.jmrix.ecos.EcosSystemConnectionMemo;
010
011/**
012 * There is no specific subtype of NamedBean here, see EcosLocoAddressManager.
013 */
014public class EcosLocoTableTabAction extends AbstractTableTabAction<NamedBean> {
015
016    public EcosLocoTableTabAction(String s) {
017        super(s);
018    }
019
020    public EcosLocoTableTabAction() {
021        this("Multiple Tabbed");
022    }
023
024    @Override
025    protected void createModel() {
026        dataTabs = new JTabbedPane();
027        java.util.List<EcosSystemConnectionMemo> list = InstanceManager.getList(EcosSystemConnectionMemo.class);
028        for (EcosSystemConnectionMemo eMemo : list) {
029            //We only want to add connections that have an active loco address manager
030            if (eMemo.getLocoAddressManager() != null) {
031                TabbedTableItem<NamedBean> itemModel = new TabbedTableItem<>(
032                    eMemo.getUserName(), true, eMemo.getLocoAddressManager(),
033                    getNewTableAction(eMemo.getUserName(), eMemo));
034                tabbedTableArray.add(itemModel);
035            }
036        }
037
038        for (int x = 0; x < tabbedTableArray.size(); x++) {
039            EcosLocoTableAction table = (EcosLocoTableAction) tabbedTableArray.get(x).getAAClass();
040            table.addToPanel(this);
041            dataTabs.addTab(tabbedTableArray.get(x).getItemString(), tabbedTableArray.get(x).getPanel());
042        }
043        dataTabs.addChangeListener((ChangeEvent evt) -> setMenuBar(f));
044        init = true;
045    }
046
047    @Override
048    protected AbstractTableAction<NamedBean> getNewTableAction(String choice) {
049        return null;
050    }
051
052    protected AbstractTableAction<NamedBean> getNewTableAction(String choice, EcosSystemConnectionMemo eMemo) {
053        return new EcosLocoTableAction(choice, eMemo);
054    }
055
056    @Override
057    protected Manager<NamedBean> getManager() {
058        return null;
059    }
060
061    @Override
062    public void addToFrame(jmri.jmrit.beantable.BeanTableFrame<NamedBean> f) {
063        if (tabbedTableArray.size() > 1) {
064            super.addToFrame(f);
065        }
066    }
067
068    @Override
069    public void setMenuBar(jmri.jmrit.beantable.BeanTableFrame<NamedBean> f) {
070        if (tabbedTableArray.size() > 1) {
071            super.setMenuBar(f);
072        }
073    }
074
075    @Override
076    protected void setTitle() {
077        //atf.setTitle("multiple turnouts");
078    }
079
080    @Override
081    protected String helpTarget() {
082        return "package.jmri.jmrix.ecos.swing.locodatabase.EcosLocoTable"; // very simple help page
083    }
084
085    @Override
086    protected String getClassName() {
087        return EcosLocoTableAction.class.getName();
088    }
089
090    @Override
091    public String getClassDescription() {
092        return Bundle.getMessage("EcosLocoTableTitle");
093    }
094
095}