001package jmri.jmrix.loconet.logixng;
002
003import java.util.List;
004
005import jmri.jmrit.logixng.Category;
006import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
007
008/**
009 * Defines the category LocoNet
010 * 
011 * @author Daniel Bergqvist Copyright 2020
012 */
013public final class CategoryLocoNet extends Category {
014    
015    /**
016     * A item on the layout, for example turnout, sensor and signal mast.
017     */
018    public static final CategoryLocoNet LOCONET = new CategoryLocoNet();
019    
020    
021    public CategoryLocoNet() {
022        super("LOCONET", Bundle.getMessage("MenuLocoNet"), 300);
023    }
024    
025    public static void registerCategory() {
026        // We don't want to add these classes if we don't have a LocoNet connection
027        if (hasLocoNet() && !Category.values().contains(LOCONET)) {
028            Category.registerCategory(LOCONET);
029        }
030    }
031    
032    /**
033     * Do we have a LocoNet connection?
034     * @return true if we have LocoNet, false otherwise
035     */
036    public static boolean hasLocoNet() {
037        List<LocoNetSystemConnectionMemo> list = jmri.InstanceManager.getList(LocoNetSystemConnectionMemo.class);
038        
039        // We have at least one LocoNet connection if the list is not empty
040        return !list.isEmpty();
041    }
042    
043}