001package jmri.jmrix.can.cbus.logixng; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import jmri.jmrit.logixng.Category; 007import jmri.jmrix.can.CanSystemConnectionMemo; 008 009/** 010 * Defines the category Cbus 011 * 012 * @author Daniel Bergqvist Copyright 2025 013 */ 014public final class CategoryMergCbus extends Category { 015 016 /** 017 * A item on the layout, for example turnout, sensor and signal mast. 018 */ 019 public static final CategoryMergCbus CBUS = new CategoryMergCbus(); 020 021 022 public CategoryMergCbus() { 023 super("CBUS", Bundle.getMessage("MenuCbus"), 300); 024 } 025 026 public static void registerCategory() { 027 // We don't want to add these classes if we don't have a Cbus connection 028 if (hasCbus() && !Category.values().contains(CBUS)) { 029 Category.registerCategory(CBUS); 030 } 031 } 032 033 public static List<CanSystemConnectionMemo> getMergConnections() { 034 List<CanSystemConnectionMemo> list = jmri.InstanceManager.getList(CanSystemConnectionMemo.class); 035 List<CanSystemConnectionMemo> mergConnections = new ArrayList<>(); 036 037 for (CanSystemConnectionMemo memo : list) { 038 if (memo.provides(jmri.jmrix.can.cbus.CbusPreferences.class)) { 039 // This is a MERG CBUS connection 040 mergConnections.add(memo); 041 } 042 } 043 044 return mergConnections; 045 } 046 047 /** 048 * Do we have a Cbus connection? 049 * @return true if we have Cbus, false otherwise 050 */ 051 public static boolean hasCbus() { 052 List<CanSystemConnectionMemo> list = getMergConnections(); 053 054 // We have at least one MERG CBUS connection if the list is not empty 055 return !list.isEmpty(); 056 } 057 058}