Search in sources :

Example 1 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class ImageIndexEditor method makeCatalogPanel.

private JPanel makeCatalogPanel() {
    _catalog = new CatalogPanel("defaultCatalog", "selectNode");
    _catalog.init(false);
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    List<String> sysNames = manager.getSystemNameList();
    for (int i = 0; i < sysNames.size(); i++) {
        String systemName = sysNames.get(i);
        if (systemName.startsWith("IF")) {
            _catalog.addTree(manager.getBySystemName(systemName));
        }
    }
    _catalog.createNewBranch("IFJAR", "Program Directory", "resources");
    FileUtil.createDirectory(FileUtil.getUserFilesPath() + "resources");
    _catalog.createNewBranch("IFPREF", "Preferences Directory", FileUtil.getUserFilesPath() + "resources");
    return _catalog;
}
Also used : CatalogTreeManager(jmri.CatalogTreeManager)

Example 2 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class ItemPalette method storeIcons.

/**
     * Store palette icons in preferences file catalogTrees.xml
     */
public static void storeIcons() {
    if (_iconMaps == null) {
        // never loaded
        return;
    }
    if (!jmri.util.ThreadingUtil.isGUIThread())
        log.error("Not on GUI thread", new Exception("traceback"));
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    // unfiltered, xml-stored, item palate icon tree
    CatalogTree tree = manager.getBySystemName("NXPI");
    // discard old version
    if (tree != null) {
        manager.deregister(tree);
    }
    tree = manager.newCatalogTree("NXPI", "Item Palette");
    CatalogTreeNode root = tree.getRoot();
    Iterator<Entry<String, HashMap<String, HashMap<String, NamedIcon>>>> it = _iconMaps.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, HashMap<String, HashMap<String, NamedIcon>>> entry = it.next();
        root.add(store3levelMap(entry.getKey(), entry.getValue()));
        if (log.isDebugEnabled()) {
            log.debug("Add type node " + entry.getKey());
        }
    }
    Iterator<Entry<String, HashMap<String, HashMap<String, HashMap<String, NamedIcon>>>>> its = _indicatorTOMaps.entrySet().iterator();
    while (its.hasNext()) {
        Entry<String, HashMap<String, HashMap<String, HashMap<String, NamedIcon>>>> entry = its.next();
        CatalogTreeNode typeNode = new CatalogTreeNode(entry.getKey());
        Iterator<Entry<String, HashMap<String, HashMap<String, NamedIcon>>>> iter = entry.getValue().entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, HashMap<String, HashMap<String, NamedIcon>>> ent = iter.next();
            typeNode.add(store3levelMap(ent.getKey(), ent.getValue()));
            if (log.isDebugEnabled()) {
                log.debug("Add IndicatorTO node " + ent.getKey());
            }
        }
        root.add(typeNode);
        if (log.isDebugEnabled()) {
            log.debug("Add IndicatorTO node " + entry.getKey());
        }
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode) Entry(java.util.Map.Entry) CatalogTree(jmri.CatalogTree)

Example 3 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class CatalogPanel method createNewBranch.

/**
     * Create a new model and add it to the main root.
     * <p>
     * Can be called from off the GUI thread.
     *
     * @param systemName the system name for the catalog
     * @param userName   the user name for the catalog
     * @param path       the path on the new branch
     */
public void createNewBranch(String systemName, String userName, String path) {
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    CatalogTree tree = manager.getBySystemName(systemName);
    if (tree != null) {
        jmri.util.ThreadingUtil.runOnGUI(() -> {
            addTree(tree);
        });
    } else {
        final CatalogTree t = manager.newCatalogTree(systemName, userName);
        jmri.util.ThreadingUtil.runOnGUI(() -> {
            t.insertNodes(path);
            addTree(t);
        });
    }
}
Also used : CatalogTree(jmri.CatalogTree) CatalogTreeManager(jmri.CatalogTreeManager)

Example 4 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method writeCatalogTrees.

/*
     *  Writes out tree values to a file in the user's preferences directory
     */
public void writeCatalogTrees() throws java.io.IOException {
    if (log.isDebugEnabled()) {
        log.debug("entered writeCatalogTreeValues");
    }
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    List<String> trees = manager.getSystemNameList();
    boolean found = false;
    Iterator<String> iter = manager.getSystemNameList().iterator();
    while (iter.hasNext()) {
        String sname = iter.next();
        CatalogTree tree = manager.getBySystemName(sname);
        if (log.isDebugEnabled()) {
            log.debug("Tree: sysName= " + sname + ", userName= " + tree.getUserName());
            CatalogTreeNode root = tree.getRoot();
            log.debug("enumerateTree called for root= " + root.toString() + ", has " + root.getChildCount() + " children");
            // root.depthFirstEnumeration isn't fully typed in JDOM2
            @SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> e = root.depthFirstEnumeration();
            while (e.hasMoreElements()) {
                CatalogTreeNode n = e.nextElement();
                log.debug("nodeName= " + n.getUserObject() + " has " + n.getLeaves().size() + " leaves and " + n.getChildCount() + " subnodes.");
            }
        }
        if (sname != null && sname.charAt(1) == CatalogTree.XML) {
            found = true;
            break;
        }
    }
    if (found) {
        // there are trees defined, create root element
        Element root = new Element("catalogTrees");
        Document doc = newDocument(root, dtdLocation + "catalogTree.dtd");
        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/tree-values.xsl"?>
        java.util.Map<String, String> m = new java.util.HashMap<>();
        m.put("type", "text/xsl");
        m.put("href", xsltLocation + "panelfile.xsl");
        org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
        doc.addContent(0, p);
        store(root, trees);
        try {
            if (!checkFile(DEFAULT_FILE_NAME)) {
                // file does not exist, create it
                File file = new File(DEFAULT_FILE_NAME);
                if (!file.createNewFile()) {
                    log.error("createNewFile failed");
                }
            }
            // write content to file
            writeXML(findFile(DEFAULT_FILE_NAME), doc);
            // memory consistent with file
            jmri.jmrit.catalog.ImageIndexEditor.indexChanged(false);
        } catch (java.io.IOException ioe) {
            log.error("IO Exception " + ioe);
            throw (ioe);
        }
    }
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode) CatalogTree(jmri.CatalogTree) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 5 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class IconAdder method initDefaultIcons.

public void initDefaultIcons() {
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    CatalogTree tree = manager.getBySystemName("NXDI");
    if (tree != null) {
        CatalogTreeNode node = tree.getRoot();
        Enumeration<CatalogTreeNode> e = node.children();
        while (e.hasMoreElements()) {
            CatalogTreeNode nChild = e.nextElement();
            if (_type.equals(nChild.toString())) {
                _defaultIcons = nChild;
                _userDefaults = true;
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("initDefaultIcons: type= " + _type + ", defaultIcons= " + _defaultIcons);
    }
}
Also used : CatalogTree(jmri.CatalogTree) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Aggregations

CatalogTreeManager (jmri.CatalogTreeManager)11 CatalogTree (jmri.CatalogTree)7 CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)6 Element (org.jdom2.Element)3 HashMap (java.util.HashMap)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Point (java.awt.Point)1 File (java.io.File)1 Entry (java.util.Map.Entry)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 XmlFile (jmri.jmrit.XmlFile)1 Attribute (org.jdom2.Attribute)1 Document (org.jdom2.Document)1