001package jmri.jmrit.display.layoutEditor.configurexml;
002
003import jmri.InstanceManager;
004import jmri.configurexml.AbstractXmlAdapter;
005import jmri.jmrit.display.layoutEditor.LayoutTrackView;
006import jmri.jmrit.logixng.LogixNG_Manager;
007
008import org.jdom2.Element;
009
010/**
011 * Base class for Xml classes for classes that inherits LayoutTrackView.
012 * @author Daniel Bergqvist (C) 2022
013 */
014public abstract class LayoutTrackViewXml extends AbstractXmlAdapter {
015
016    public void storeLogixNG_Data(LayoutTrackView ltv, Element element) {
017        if (ltv.getLogixNG() == null) return;
018
019        // Don't save LogixNG data if we don't have any ConditionalNGs
020        if (ltv.getLogixNG().getNumConditionalNGs() == 0) return;
021        Element logixNG_Element = new Element("LogixNG");
022        logixNG_Element.addContent(new Element("InlineLogixNG_SystemName").addContent(ltv.getLogixNG().getSystemName()));
023        element.addContent(logixNG_Element);
024    }
025
026    public void loadLogixNG_Data(LayoutTrackView ltv, Element element) {
027        Element logixNG_Element = element.getChild("LogixNG");
028        if (logixNG_Element == null) return;
029        Element inlineLogixNG = logixNG_Element.getChild("InlineLogixNG_SystemName");
030        if (inlineLogixNG != null) {
031            String systemName = inlineLogixNG.getTextTrim();
032            ltv.setLogixNG_SystemName(systemName);
033            InstanceManager.getDefault(LogixNG_Manager.class).registerSetupTask(() -> {
034                ltv.setupLogixNG();
035            });
036        }
037    }
038
039}