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.ActionCreateBeansFromTable; 009import jmri.jmrit.logixng.NamedBeanType; 010import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectNamedBeanXml; 011 012import org.jdom2.Attribute; 013import org.jdom2.Element; 014 015/** 016 * Handle XML configuration for ActionCreateBeansFromTable objects. 017 * 018 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 019 * @author Daniel Bergqvist Copyright (C) 2022 020 */ 021public class ActionCreateBeansFromTableXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 022 023 public ActionCreateBeansFromTableXml() { 024 } 025 026 /** 027 * Default implementation for storing the contents of a SE8cSignalHead 028 * 029 * @param o Object to store, of type TripleTurnoutSignalHead 030 * @return Element containing the complete info 031 */ 032 @Override 033 public Element store(Object o) { 034 ActionCreateBeansFromTable p = (ActionCreateBeansFromTable) o; 035 036 Element element = new Element("ActionCreateBeansFromTable"); 037 element.setAttribute("class", this.getClass().getName()); 038 element.addContent(new Element("systemName").addContent(p.getSystemName())); 039 040 storeCommon(p, element); 041 042 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<NamedTable>(); 043 element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean")); 044 045 element.addContent(new Element("rowOrColumnSystemName").addContent(p.getRowOrColumnSystemName())); 046 047 if (p.getRowOrColumnUserName() != null && !p.getRowOrColumnUserName().isBlank()) { 048 element.addContent(new Element("rowOrColumnUserName").addContent(p.getRowOrColumnUserName())); 049 } 050 element.addContent(new Element("tableRowOrColumn").addContent(p.getTableRowOrColumn().name())); 051 052 element.setAttribute("onlyCreatableTypes", 053 p.isOnlyCreatableTypes()? "yes" : "no"); // NOI18N 054 055 element.setAttribute("includeCellsWithoutHeader", 056 p.isIncludeCellsWithoutHeader() ? "yes" : "no"); // NOI18N 057 058 element.setAttribute("moveUserName", 059 p.isMoveUserName()? "yes" : "no"); // NOI18N 060 061 element.setAttribute("updateToUserName", 062 p.isUpdateToUserName()? "yes" : "no"); // NOI18N 063 064 element.setAttribute("removeOldBean", 065 p.isRemoveOldBean()? "yes" : "no"); // NOI18N 066 067 element.addContent(new Element("namedBeanType").addContent(p.getNamedBeanType().name())); 068 069 return element; 070 } 071 072 @Override 073 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 074 075 String sys = getSystemName(shared); 076 String uname = getUserName(shared); 077 ActionCreateBeansFromTable h = new ActionCreateBeansFromTable(sys, uname); 078 079 loadCommon(h, shared); 080 081 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<NamedTable>(); 082 selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean()); 083 selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "table", null, null, null, null); 084 085 Element tableRowOrColumnElement = shared.getChild("tableRowOrColumn"); 086 TableRowOrColumn tableRowOrColumn = 087 TableRowOrColumn.valueOf(tableRowOrColumnElement.getTextTrim()); 088 h.setTableRowOrColumn(tableRowOrColumn); 089 090 Element rowOrColumnSystemName = shared.getChild("rowOrColumnSystemName"); 091 if (rowOrColumnSystemName != null) { 092 h.setRowOrColumnSystemName(rowOrColumnSystemName.getTextTrim()); 093 } 094 095 Element rowOrColumnUserName = shared.getChild("rowOrColumnUserName"); 096 if (rowOrColumnUserName != null) { 097 h.setRowOrColumnUserName(rowOrColumnUserName.getTextTrim()); 098 } 099 100 String onlyCreatableTypes = "yes"; 101 Attribute attribute = shared.getAttribute("onlyCreatableTypes"); 102 if (attribute != null) { // NOI18N 103 onlyCreatableTypes = attribute.getValue(); // NOI18N 104 } 105 h.setOnlyCreatableTypes("yes".equals(onlyCreatableTypes)); 106 107 String includeCellsWithoutHeader = "no"; 108 attribute = shared.getAttribute("includeCellsWithoutHeader"); 109 if (attribute != null) { // NOI18N 110 includeCellsWithoutHeader = attribute.getValue(); // NOI18N 111 } 112 h.setIncludeCellsWithoutHeader("yes".equals(includeCellsWithoutHeader)); 113 114 String moveUserName = "no"; 115 attribute = shared.getAttribute("moveUserName"); 116 if (attribute != null) { // NOI18N 117 moveUserName = attribute.getValue(); // NOI18N 118 } 119 h.setMoveUserName("yes".equals(moveUserName)); 120 121 String updateToUserName = "no"; 122 attribute = shared.getAttribute("updateToUserName"); 123 if (attribute != null) { // NOI18N 124 updateToUserName = attribute.getValue(); // NOI18N 125 } 126 h.setUpdateToUserName("yes".equals(updateToUserName)); 127 128 String removeOldBean = "no"; 129 attribute = shared.getAttribute("removeOldBean"); 130 if (attribute != null) { // NOI18N 131 removeOldBean = attribute.getValue(); // NOI18N 132 } 133 h.setRemoveOldBean("yes".equals(removeOldBean)); 134 135 Element namedBeanTypeElement = shared.getChild("namedBeanType"); 136 NamedBeanType namedBeanType = 137 NamedBeanType.valueOf(namedBeanTypeElement.getTextTrim()); 138 h.setNamedBeanType(namedBeanType); 139 140 InstanceManager.getDefault(DigitalActionManager.class).registerAction(h); 141 return true; 142 } 143 144// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionCreateBeansFromTableXml.class); 145}