001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.InstanceManager;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalActionManager;
006import jmri.jmrit.logixng.NamedTable;
007import jmri.jmrit.logixng.TableRowOrColumn;
008import jmri.jmrit.logixng.actions.ActionFindTableRowOrColumn;
009import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectNamedBeanXml;
010
011import org.jdom2.Attribute;
012import org.jdom2.Element;
013
014/**
015 * Handle XML configuration for ActionFindTableRowOrColumn objects.
016 *
017 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
018 * @author Daniel Bergqvist Copyright (C) 2022
019 */
020public class ActionFindTableRowOrColumnXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
021
022    public ActionFindTableRowOrColumnXml() {
023    }
024
025    /**
026     * Default implementation for storing the contents of a SE8cSignalHead
027     *
028     * @param o Object to store, of type TripleTurnoutSignalHead
029     * @return Element containing the complete info
030     */
031    @Override
032    public Element store(Object o) {
033        ActionFindTableRowOrColumn p = (ActionFindTableRowOrColumn) o;
034
035        Element element = new Element("ActionFindTableRowOrColumn");
036        element.setAttribute("class", this.getClass().getName());
037        element.addContent(new Element("systemName").addContent(p.getSystemName()));
038
039        storeCommon(p, element);
040
041        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<NamedTable>();
042        element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean"));
043
044        element.addContent(new Element("rowOrColumnName").addContent(p.getRowOrColumnName()));
045        element.addContent(new Element("tableRowOrColumn").addContent(p.getTableRowOrColumn().name()));
046
047        element.setAttribute("includeCellsWithoutHeader",
048                p.getIncludeCellsWithoutHeader() ? "yes" : "no");  // NOI18N
049
050        element.addContent(new Element("localVariableNamedBean").addContent(p.getLocalVariableNamedBean()));
051        element.addContent(new Element("localVariableRow").addContent(p.getLocalVariableRow()));
052
053        return element;
054    }
055
056    @Override
057    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {
058
059        String sys = getSystemName(shared);
060        String uname = getUserName(shared);
061        ActionFindTableRowOrColumn h = new ActionFindTableRowOrColumn(sys, uname);
062
063        loadCommon(h, shared);
064
065        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<NamedTable>();
066        selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean());
067        selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "table", null, null, null, null);
068
069        Element tableRowOrColumnElement = shared.getChild("tableRowOrColumn");
070        TableRowOrColumn tableRowOrColumn =
071                TableRowOrColumn.valueOf(tableRowOrColumnElement.getTextTrim());
072        h.setTableRowOrColumn(tableRowOrColumn);
073
074        Element rowOrColumnName = shared.getChild("rowOrColumnName");
075        if (rowOrColumnName != null) {
076            h.setRowOrColumnName(rowOrColumnName.getTextTrim());
077        }
078
079        String includeCellsWithoutHeader = "no";
080        Attribute attribute = shared.getAttribute("includeCellsWithoutHeader");
081        if (attribute != null) {  // NOI18N
082            includeCellsWithoutHeader = attribute.getValue();  // NOI18N
083        }
084        h.setIncludeCellsWithoutHeader("yes".equals(includeCellsWithoutHeader));
085
086        Element variableName = shared.getChild("localVariableNamedBean");
087        if (variableName != null) {
088            h.setLocalVariableNamedBean(variableName.getTextTrim());
089        }
090
091        variableName = shared.getChild("localVariableRow");
092        if (variableName != null) {
093            h.setLocalVariableRow(variableName.getTextTrim());
094        }
095
096        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
097        return true;
098    }
099
100//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionFindTableRowOrColumnXml.class);
101}