001package jmri.jmrit.catalog;
002
003import java.util.HashMap;
004import jmri.CatalogTreeNode;
005
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * TreeModel used by CatalogPanel to create a tree of resources. This model is
011 * for trees that can be permanently stored to and reloaded from an XML file.
012 * <p>
013 * Source of the tree content is an XML file.
014 *
015 * @author Pete Cressman Copyright 2009
016 *
017 */
018public class CatalogTreeIndex extends AbstractCatalogTree {
019
020    public CatalogTreeIndex(String sysName, String userName) {
021
022        super(sysName, userName);
023    }
024
025    /**
026     * Recursively add nodes to the tree
027     *
028     * @param pName   Name of the resource to be scanned; this is only used for
029     *                the human-readable tree
030     * @param pPath   Path to this resource, including the pName part
031     * @param pParent Node for the parent of the resource to be scanned, e.g.
032     *                where in the tree to insert it.
033     */
034    @Override
035    public void insertNodes(String pName, String pPath, CatalogTreeNode pParent) {
036        CatalogTreeNode newNode;
037        if (pPath == null) {
038            newNode = new CatalogTreeNode("Image Index");
039        } else {
040            newNode = new CatalogTreeNode(pName);
041        }
042        if (log.isDebugEnabled()) {
043            log.debug("insertNodeInto: newNode= {}, into parent= {}", newNode.getUserObject(), pParent.getUserObject());
044        }
045        insertNodeInto(newNode, pParent, pParent.getChildCount());
046    }
047
048    @Override
049    public void setProperty(String key, Object value) {
050        if (parameters == null) {
051            parameters = new HashMap<>();
052        }
053        parameters.put(key, value);
054    }
055
056    @Override
057    public Object getProperty(String key) {
058        if (parameters == null) {
059            parameters = new HashMap<>();
060        }
061        return parameters.get(key);
062    }
063
064    @Override
065    public java.util.Set<String> getPropertyKeys() {
066        if (parameters == null) {
067            parameters = new HashMap<>();
068        }
069        return parameters.keySet();
070    }
071
072    @Override
073    public void removeProperty(String key) {
074        if (parameters == null || key == null) {
075            return;
076        }
077        parameters.remove(key);
078    }
079
080    HashMap<String, Object> parameters = null;
081
082    private final static Logger log = LoggerFactory.getLogger(CatalogTreeIndex.class);
083}