001package jmri.jmrix.can.cbus.swing.nodeconfig;
002
003import java.awt.BorderLayout;
004
005import javax.swing.*;
006import javax.swing.event.TableModelEvent;
007
008import jmri.jmrix.can.cbus.node.CbusNode;
009import jmri.jmrix.can.cbus.node.CbusNodeNVTableDataModel;
010import jmri.jmrix.can.cbus.swing.modules.CbusConfigPaneProvider;
011
012
013/**
014 * Pane providing a Cbus NV editing gui
015 *
016 * @author Andrew Crosland Copyright (C) 2021
017 */
018public class CbusNodeNVEditGuiPane extends jmri.jmrix.can.swing.CanPanel {
019
020    private final CbusNodeNVTableDataModel nodeNVModel;
021    private JScrollPane nvVarScroll;
022    private JPanel pane1;
023    private JPanel editGui;
024    private CbusNode _node;
025    private CbusConfigPaneProvider _provider;
026
027    protected CbusNodeNVEditGuiPane(CbusNodeNVTableDataModel nVModel) {
028        super();
029        nodeNVModel = nVModel;
030        _node = null;
031        _provider = null;
032    }
033    
034    /**
035     * Set the current node, keeping existing gui provider
036     * 
037     * @param node node to display
038     */
039    protected void setNode(CbusNode node) {
040        _node = node;
041        
042        if (pane1 != null) {
043            this.removeAll();
044            this.initComponents();
045        }
046        
047        editGui = _provider.getEditNVFrame(nodeNVModel, _node);
048        showGui(editGui);
049        
050        this.setVisible(!(_node == null));
051    }
052    
053    /**
054     * Set the current node and associated gui provider
055     * 
056     * @param node node to display
057     * @param provider edit gui provider for the node
058     */
059    protected void setNode(CbusNode node, CbusConfigPaneProvider provider) {
060        _provider = provider;
061        setNode(node);
062    }
063    
064    protected void showGui(JPanel editGui){
065        
066        this.setLayout(new BorderLayout());
067        
068        pane1 = new JPanel();
069        pane1.setLayout(new BoxLayout(pane1, BoxLayout.Y_AXIS));
070   
071        nvVarScroll = new JScrollPane(editGui);
072
073        pane1.add(nvVarScroll, BorderLayout.CENTER);
074        
075        add(pane1);
076    }
077    
078    protected void tableChanged(TableModelEvent e) {
079        if (_provider != null) {
080            _provider.getEditNVFrameInstance().tableChanged(e);
081        }
082    }
083
084//    private final static Logger log = LoggerFactory.getLogger(CbusNodeNVEditGuiPane.class);
085
086}