Search in sources :

Example 6 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class DefaultLogix method setGuiNames.

/**
     * ConditionalVariables only have a single name field.  For user interface purposes
     * a gui name is used for the referenced conditional user name.  This is not used
     * for other object types.
     * <p>
     * In addition to setting the GUI name, any state variable references are changed to
     * conditional system names.  This converts the XML system/user name field to the system name
     * for conditional references.  It does not affect other objects such as sensors, turnouts, etc.
     * Called by {@link jmri.managers.DefaultLogixManager#activateAllLogixs}
     * @since 4.7.4
     */
@Override
public void setGuiNames() {
    if (_isGuiSet) {
        return;
    }
    if (getSystemName().equals("SYS")) {
        _isGuiSet = true;
        return;
    }
    for (int i = 0; i < _conditionalSystemNames.size(); i++) {
        String cName = _conditionalSystemNames.get(i);
        Conditional conditional = getConditional(cName);
        if (conditional == null) {
            // A Logix index entry exists without a corresponding conditional.  This
            // should never happen.
            log.error("setGuiNames: Missing conditional for Logix index entry,  Logix name = '{}', Conditional index name = '{}'", getSystemName(), cName);
            continue;
        }
        ArrayList<ConditionalVariable> varList = conditional.getCopyOfStateVariables();
        boolean isDirty = false;
        for (ConditionalVariable var : varList) {
            // Find any Conditional State Variables
            if (var.getType() == Conditional.TYPE_CONDITIONAL_TRUE || var.getType() == Conditional.TYPE_CONDITIONAL_FALSE) {
                // Get the referenced (target) conditonal -- The name can be either a system name or a user name
                Conditional cRef = InstanceManager.getDefault(jmri.ConditionalManager.class).getConditional(var.getName());
                if (cRef != null) {
                    // re-arrange names as needed
                    // The state variable reference is now a conditional system name
                    var.setName(cRef.getSystemName());
                    if (cRef.getUserName() == null || cRef.getUserName().length() < 1) {
                        var.setGuiName(cRef.getSystemName());
                    } else {
                        var.setGuiName(cRef.getUserName());
                    }
                    // Add the conditional reference to the where used map
                    InstanceManager.getDefault(jmri.ConditionalManager.class).addWhereUsed(var.getName(), cName);
                    isDirty = true;
                } else {
                    log.error("setGuiNames: For conditional '{}' in logix '{}', the referenced conditional, '{}',  does not exist", cName, getSystemName(), var.getName());
                }
            }
        }
        if (isDirty) {
            conditional.setStateVariables(varList);
        }
    }
    _isGuiSet = true;
}
Also used : ConditionalManager(jmri.ConditionalManager) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Example 7 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class Maintenance method search.

/**
     * Search if a given string is used as the name of a NamedBean.
     *
     * @param name the string to look for
     * @param text body of the message to be displayed reporting the result
     * @return true if name is found at least once as a bean name
     */
static boolean search(String name, JTextArea text) {
    String[] names = getTypeAndNames(name);
    if (log.isDebugEnabled()) {
        log.debug("search for " + name + " as " + names[0] + " \"" + names[1] + "\" (" + names[2] + ")");
    }
    if (names[0].length() == 0) {
        if (text != null) {
            text.append(MessageFormat.format(rbm.getString("ElementNotFound"), (Object[]) names));
            return false;
        }
    }
    if (text != null) {
        text.append(MessageFormat.format(rbm.getString("ReferenceFollows"), (Object[]) names));
    }
    String sysName = names[2];
    String userName = names[1];
    int referenceCount = 0;
    StringBuilder tempText = new StringBuilder();
    boolean found = false;
    boolean empty = true;
    // search for references among each class known to be listeners
    Iterator<String> iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
        if (x == null) {
            log.error("Error getting Logix  - " + sName);
            break;
        }
        tempText = new StringBuilder();
        String uName = x.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "", Bundle.getMessage("BeanNameLogix"), uName, sName });
        for (int i = 0; i < x.getNumConditionals(); i++) {
            sName = x.getConditionalByNumberOrder(i);
            if (sName == null) {
                log.error("Null conditional system name");
                break;
            }
            Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(sName);
            if (c == null) {
                log.error("Invalid conditional system name - " + sName);
                break;
            }
            uName = c.getUserName();
            String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameConditional"), uName, sName });
            String line = MessageFormat.format(rbm.getString("ConditionalReference"), "\t");
            if (sysName.equals(sName) || (userName != null && userName.length() > 0 && userName.equals(uName))) {
                if (testName(sysName, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
            ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
            for (int k = 0; k < variableList.size(); k++) {
                ConditionalVariable v = variableList.get(k);
                line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
                if (testName(v.getName(), found, names, line1, line2, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
            ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
            for (int k = 0; k < actionList.size(); k++) {
                ConditionalAction a = actionList.get(k);
                line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
                if (testName(a.getDeviceName(), found, names, line1, line2, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
            if (text != null && found) {
                text.append(tempText.toString());
                tempText = new StringBuilder();
                found = false;
                empty = false;
                line1 = null;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append("\t" + MessageFormat.format(rbm.getString("NoReference"), "Logix"));
        // cannot put escaped tab char at start of getString
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.jmrit.logix.OBlockManager oBlockManager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    iter1 = oBlockManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.jmrit.logix.OBlock block = oBlockManager.getBySystemName(sName);
        String uName = block.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameOBlock"), uName, sName });
        Sensor sensor = block.getSensor();
        if (sensor != null) {
            String line = MessageFormat.format(rbm.getString("OBlockSensor"), "\t");
            if (testName(sensor.getSystemName(), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "OBlock"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.RouteManager routeManager = InstanceManager.getDefault(jmri.RouteManager.class);
    iter1 = routeManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Route r = routeManager.getBySystemName(sName);
        if (r == null) {
            log.error("Error getting Route  - " + sName);
            break;
        }
        String uName = r.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameRoute"), uName, sName });
        for (int i = 0; i < jmri.Route.MAX_CONTROL_SENSORS; i++) {
            String line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameSensor"));
            if (testName(r.getRouteSensorName(i), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        String line = MessageFormat.format("TurnoutsAlignedSensor", Bundle.getMessage("BeanNameSensor"));
        if (testName(r.getTurnoutsAlignedSensor(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameTurnout"));
        if (testName(r.getControlTurnout(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format("LockControlTurnout", Bundle.getMessage("BeanNameTurnout"));
        if (testName(r.getLockControlTurnout(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        for (int i = 0; i < r.getNumOutputTurnouts(); i++) {
            line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameTurnout"));
            if (testName(r.getOutputTurnoutByIndex(i), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        for (int i = 0; i < r.getNumOutputSensors(); i++) {
            line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameSensor"));
            if (testName(r.getOutputSensorByIndex(i), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Route"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.TransitManager transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
    iter1 = transitManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Transit transit = transitManager.getBySystemName(sName);
        if (transit == null) {
            log.error("Error getting Transit - " + sName);
            break;
        }
        String uName = transit.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameTransit"), uName, sName });
        ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
        for (int i = 0; i < sectionList.size(); i++) {
            jmri.TransitSection transitSection = sectionList.get(i);
            jmri.Section section = transitSection.getSection();
            uName = section.getUserName();
            sName = section.getSystemName();
            String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", rbm.getString("TransitSection"), uName, sName });
            if (sName.equals(sysName) || uName.equals(userName)) {
                tempText.append(line1);
                tempText.append(line2);
                tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t\t"));
                found = true;
                referenceCount++;
            }
            String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t\t");
            if (testName(section.getForwardBlockingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t\t");
            if (testName(section.getForwardStoppingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t\t");
            if (testName(section.getReverseBlockingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t\t");
            if (testName(section.getReverseStoppingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            ArrayList<jmri.Block> blockList = section.getBlockList();
            for (int k = 0; k < blockList.size(); k++) {
                jmri.Block block = blockList.get(k);
                sName = block.getSystemName();
                uName = block.getUserName();
                tempText.append(MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t\t", Bundle.getMessage("BeanNameBlock"), uName, sName }));
                if (sName.equals(sysName) || uName.equals(userName)) {
                    tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t\t"));
                    found = true;
                    referenceCount++;
                }
                Sensor sensor = block.getSensor();
                if (sensor != null) {
                    line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
                    if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
            }
            if (text != null && found) {
                text.append(tempText.toString());
                tempText = new StringBuilder();
                found = false;
                empty = false;
                line1 = null;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Transit"));
        } else {
            text.append("\n");
        }
    }
    // if (text != null) {
    //   text.append(rbm.getString("NestMessage"));
    // }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.SectionManager sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
    java.util.List<String> sysNameList = sectionManager.getSystemNameList();
    transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
    iter1 = transitManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Transit transit = transitManager.getBySystemName(sName);
        if (transit != null) {
            ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
            for (int i = 0; i < sectionList.size(); i++) {
                jmri.TransitSection transitSection = sectionList.get(i);
                jmri.Section section = transitSection.getSection();
                sysNameList.remove(section.getSystemName());
            }
        }
    }
    iter1 = sysNameList.iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Section section = sectionManager.getBySystemName(sName);
        if (section == null) {
            log.error("Error getting Section - " + sName);
            break;
        }
        String uName = section.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameSection"), uName, sName });
        if (sName.equals(sysName) || uName.equals(userName)) {
            tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t"));
            found = true;
            referenceCount++;
        }
        String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t");
        if (testName(section.getForwardBlockingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t");
        if (testName(section.getForwardStoppingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t");
        if (testName(section.getReverseBlockingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t");
        if (testName(section.getReverseStoppingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        ArrayList<jmri.Block> blockList = section.getBlockList();
        for (int k = 0; k < blockList.size(); k++) {
            jmri.Block block = blockList.get(k);
            sName = block.getSystemName();
            uName = block.getUserName();
            String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameBlock"), uName, sName });
            if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
                tempText.append(line2);
                tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
                found = true;
                referenceCount++;
            }
            Sensor sensor = block.getSensor();
            if (sensor != null) {
                line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
                if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Section"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.BlockManager blockManager = InstanceManager.getDefault(jmri.BlockManager.class);
    sysNameList = blockManager.getSystemNameList();
    sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
    iter1 = sectionManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        String sName = iter1.next();
        jmri.Section section = sectionManager.getBySystemName(sName);
        if (section != null) {
            for (Block block : section.getBlockList()) {
                sysNameList.remove(block.getSystemName());
            }
        }
    }
    iter1 = sysNameList.iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Block b = blockManager.getBySystemName(sName);
        String uName = b.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameBlock"), uName, sName });
        if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
            tempText.append(line1);
            tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
            found = true;
            referenceCount++;
        }
        jmri.Sensor s = b.getSensor();
        if (s != null) {
            String line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
            if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Block"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
    iter1 = lbm.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.jmrit.display.layoutEditor.LayoutBlock lb = lbm.getBySystemName(sName);
        if (lb == null) {
            log.error("Error getting LayoutBlock - " + sName);
            break;
        }
        String uName = lb.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("LayoutBlock"), uName, sName });
        jmri.Sensor s = lb.getOccupancySensor();
        if (s != null) {
            String line = MessageFormat.format(rbm.getString("OccupancySensor"), "\t\t");
            if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "LayoutBlock"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    java.util.Enumeration<BlockBossLogic> enumeration = BlockBossLogic.entries();
    while (enumeration.hasMoreElements()) {
        // get the next Logix
        BlockBossLogic bbl = enumeration.nextElement();
        String sName = bbl.getName();
        String uName = bbl.getDrivenSignal();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("BlockBossLogic"), uName, sName });
        if (uName.equals(sysName) || uName.equals(userName) || sName.equals(sysName) || sName.equals(userName)) {
            tempText.append(line1);
            tempText.append(MessageFormat.format(rbm.getString("SignalReference"), "\t"));
            found = true;
            referenceCount++;
        }
        String line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
        if (testName(bbl.getSensor1(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
        if (testName(bbl.getSensor2(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "3\t");
        if (testName(bbl.getSensor3(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "4\t");
        if (testName(bbl.getSensor4(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "5\t");
        if (testName(bbl.getSensor5(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "\t");
        if (testName(bbl.getTurnout(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSignalReference"), "1\t");
        if (testName(bbl.getWatchedSignal1(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "1Alt\t");
        if (testName(bbl.getWatchedSignal1Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2\t");
        if (testName(bbl.getWatchedSignal2(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2Alt\t");
        if (testName(bbl.getWatchedSignal2Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
        if (testName(bbl.getWatchedSensor1(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1Alt\t");
        if (testName(bbl.getWatchedSensor1Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
        if (testName(bbl.getWatchedSensor2(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2Alt\t");
        if (testName(bbl.getWatchedSensor2Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "BlockBossLogic"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.ConditionalManager conditionalManager = InstanceManager.getDefault(jmri.ConditionalManager.class);
    sysNameList = conditionalManager.getSystemNameList();
    iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
    while (iter1.hasNext()) {
        String sName = iter1.next();
        Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
        for (int i = 0; i < x.getNumConditionals(); i++) {
            sName = x.getConditionalByNumberOrder(i);
            sysNameList.remove(sName);
        }
    }
    iter1 = sysNameList.iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Conditional c = conditionalManager.getBySystemName(sName);
        if (c == null) {
            log.error("Error getting Condition - " + sName);
            break;
        }
        String uName = c.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameConditional"), uName, sName });
        if (sName.equals(sysName) || uName.equals(userName)) {
            tempText.append(line1);
            tempText.append(MessageFormat.format(rbm.getString("ConditionalReference"), "\t"));
            found = true;
        //referenceCount++; Don't count, this conditional is orphaned by logix(es)
        }
        ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
        for (int k = 0; k < variableList.size(); k++) {
            ConditionalVariable v = variableList.get(k);
            String line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
            if (testName(v.getName(), found, names, line1, null, line, tempText)) {
                found = true;
            //referenceCount++; Don't count, this conditional is orphaned by logix(es)
            }
        }
        ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
        for (int k = 0; k < actionList.size(); k++) {
            ConditionalAction a = actionList.get(k);
            String line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
            if (testName(a.getDeviceName(), found, names, line1, null, line, tempText)) {
                found = true;
            //referenceCount++; Don't count, this conditional is orphaned by logix(es)
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
            line1 = null;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Conditional"));
        }
        text.append("\n");
    }
    found = false;
    empty = true;
    ArrayList<jmri.jmrit.display.Editor> panelList = jmri.jmrit.display.PanelMenu.instance().getEditorPanelList();
    for (int i = 0; i < panelList.size(); i++) {
        jmri.jmrit.display.Editor panelEditor = panelList.get(i);
        name = panelEditor.getTitle();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("Panel"), name, name });
        List<Positionable> contents = panelEditor.getContents();
        for (int k = 0; k < contents.size(); k++) {
            Positionable o = contents.get(k);
            if (o.getClass().getName().equals("jmri.jmrit.display.SensorIcon")) {
                name = ((jmri.jmrit.display.SensorIcon) o).getSensor().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSensor") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.TurnoutIcon")) {
                name = ((jmri.jmrit.display.TurnoutIcon) o).getTurnout().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameTurnout") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.SignalHeadIcon")) {
                name = ((jmri.jmrit.display.SignalHeadIcon) o).getSignalHead().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSignalHead") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.MultiSensorIcon")) {
                jmri.jmrit.display.MultiSensorIcon msi = (jmri.jmrit.display.MultiSensorIcon) o;
                for (int j = 0; j < msi.getNumEntries(); j++) {
                    name = msi.getSensorName(j);
                    String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("MultiSensor") });
                    if (testName(name, found, names, line1, null, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTurnoutIcon")) {
                jmri.jmrit.display.IndicatorTurnoutIcon ito = (jmri.jmrit.display.IndicatorTurnoutIcon) o;
                name = ito.getTurnout().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
                Sensor sensor = ito.getOccSensor();
                if (sensor != null) {
                    name = sensor.getSystemName();
                    line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
                    if (testName(name, found, names, line1, null, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
                jmri.jmrit.logix.OBlock block = ito.getOccBlock();
                if (block != null) {
                    sensor = block.getSensor();
                    if (sensor != null) {
                        name = sensor.getSystemName();
                        line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
                        if (testName(name, found, names, line1, null, line, tempText)) {
                            found = true;
                            referenceCount++;
                        }
                    }
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTrackIcon")) {
                jmri.jmrit.display.IndicatorTrackIcon track = (jmri.jmrit.display.IndicatorTrackIcon) o;
                Sensor sensor = track.getOccSensor();
                if (sensor != null) {
                    name = sensor.getSystemName();
                    String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
                    if (testName(name, found, names, line1, null, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
                jmri.jmrit.logix.OBlock block = track.getOccBlock();
                if (block != null) {
                    sensor = block.getSensor();
                    if (sensor != null) {
                        name = sensor.getSystemName();
                        String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
                        if (testName(name, found, names, line1, null, line, tempText)) {
                            found = true;
                            referenceCount++;
                        }
                    }
                }
            }
            if (text != null && found) {
                text.append(tempText.toString());
                tempText = new StringBuilder();
                found = false;
                empty = false;
                line1 = null;
            }
        }
        if (text != null) {
            if (empty) {
                text.append(MessageFormat.format(rbm.getString("NoReference"), "Panel"));
            }
        }
    }
    if (text != null) {
        if (referenceCount == 0) {
            text.append(MessageFormat.format(rbm.getString("Orphan"), (Object[]) names));
        } else {
            text.append(MessageFormat.format(rbm.getString("ReferenceFound"), new Object[] { Integer.valueOf(referenceCount), userName, sysName }));
        }
    }
    if (names[0] != null) {
        // The manager is always a listener
        int numListeners = Integer.parseInt(names[3]) - 1;
        // PickLists are also listeners
        numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances(names[0]);
        if (names[0].equals("Sensor")) {
            // NOI18N
            numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances("MultiSensor");
        }
        if (numListeners > referenceCount) {
            if (names[0].length() == 0) {
                names[0] = "Unknown Type?";
            }
            /*
                 JOptionPane.showMessageDialog(null,
                 MessageFormat.format(rbm.getString("OrphanName"), (Object[])names)+" has "+numListeners+
                 " listeners installed and only "+referenceCount+
                 " references found.\n"+names[0]+
                 " Tables are listeneners.  Check that the table is closed.",
                 rbm.getString("infoTitle"), JOptionPane.INFORMATION_MESSAGE);
                 */
            if (text != null) {
                text.append(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) names) + " has " + numListeners + " listeners installed and only " + referenceCount + " references found.\n" + names[0] + " Tables are listeneners.  Check that the table is closed.");
            }
        }
    }
    return (referenceCount > 0);
}
Also used : Sensor(jmri.Sensor) Conditional(jmri.Conditional) Conditional(jmri.Conditional) Block(jmri.Block) Logix(jmri.Logix) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) Sensor(jmri.Sensor) ConditionalAction(jmri.ConditionalAction) ConditionalVariable(jmri.ConditionalVariable) BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Positionable(jmri.jmrit.display.Positionable)

Example 8 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class LogixTableAction method addVariablePressed.

/* makeEditConditionalWindow */
/**
     * Respond to the Add State Variable Button in the Edit Conditional window.
     *
     * @param e The event heard
     */
void addVariablePressed(ActionEvent e) {
    if (alreadyEditingActionOrVariable()) {
        return;
    }
    if (LRouteTableAction.LOGIX_INITIALIZER.equals(_curLogix.getSystemName())) {
        javax.swing.JOptionPane.showMessageDialog(editConditionalFrame, rbx.getString("Error49"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    _showReminder = true;
    ConditionalVariable variable = new ConditionalVariable();
    _variableList.add(variable);
    _newItem = true;
    int size = _variableList.size();
    // default of operator for postion 0 (row 1) is Conditional.OPERATOR_NONE
    if (size > 1) {
        if (_logicType == Conditional.ALL_OR) {
            variable.setOpern(Conditional.OPERATOR_OR);
        } else {
            variable.setOpern(Conditional.OPERATOR_AND);
        }
    }
    size--;
    _variableTableModel.fireTableRowsInserted(size, size);
    makeEditVariableWindow(size);
    appendToAntecedent(variable);
}
Also used : ConditionalVariable(jmri.ConditionalVariable)

Example 9 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class LogixTableAction method buildConditionalListing.

/**
     * Builds the text representing the current conditionals for the selected
     * Logix statement
     */
void buildConditionalListing() {
    String showSystemName, showCondName, condName, operand, tStr;
    ConditionalVariable variable;
    ConditionalAction action;
    numConditionals = _curLogix.getNumConditionals();
    showSystemName = _curLogix.getSystemName();
    condText.setText(null);
    for (int rx = 0; rx < numConditionals; rx++) {
        conditionalRowNumber = rx;
        _curConditional = _conditionalManager.getBySystemName(_curLogix.getConditionalByNumberOrder(rx));
        _variableList = _curConditional.getCopyOfStateVariables();
        _logixSysName = _curConditional.getSystemName();
        _actionList = _curConditional.getCopyOfActions();
        showCondName = _curConditional.getUserName();
        if (showCondName == null) {
            showCondName = "";
        }
        showSystemName = _curConditional.getSystemName();
        // If no user name for a conditional, create one using C + row number
        if (showCondName.equals("")) {
            showCondName = "C" + (rx + 1);
        }
        condText.append("\n   " + showSystemName + "  " + showCondName + "\n");
        if (_curConditional.getLogicType() == Conditional.MIXED) {
            _antecedent = _curConditional.getAntecedentExpression();
            condText.append("   " + rbx.getString("BrowserAntecedent") + " " + _antecedent + "\n");
        }
        for (int i = 0; i < _variableList.size(); i++) {
            variable = _variableList.get(i);
            tStr = "        ";
            // Makes {Rx}bb or {Rxx}b
            tStr = tStr + " R" + (i + 1) + (i > 9 ? "" : "  ");
            condText.append(tStr);
            operand = variable.getOpernString();
            if (i == 0) {
                // add the IF to the first conditional
                condText.append(rbx.getString("BrowserIF") + " " + operand + " ");
            } else {
                condText.append(" " + operand + " ");
            }
            if (variable.isNegated()) {
                condText.append(rbx.getString("LogicNOT") + " ");
            }
            condText.append(variable.toString() + "\n");
        }
        if (_actionList.size() > 0) {
            condText.append("              " + rbx.getString("BrowserTHEN") + "\n");
            for (int i = 0; i < _actionList.size(); i++) {
                action = _actionList.get(i);
                condName = action.description(false);
                condText.append("                 " + condName + "\n");
            }
        // for _actionList
        } else {
            condText.append("            " + rbx.getString("BrowserNoAction") + "\n");
        }
    }
    // for numConditionals
    condText.setCaretPosition(0);
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) ConditionalVariable(jmri.ConditionalVariable)

Example 10 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class LogixTableAction method variableNegationChanged.

/**
     * Respond to the Negation column in the Edit Conditional window.
     *
     * @param row index of the Conditional to change the setting on
     * @param oper NOT (i18n) as negation of condition
     */
void variableNegationChanged(int row, String oper) {
    ConditionalVariable variable = _variableList.get(row);
    boolean state = variable.isNegated();
    if (oper == null) {
        variable.setNegation(false);
    } else {
        variable.setNegation(oper.equals(Bundle.getMessage("LogicNOT")));
    }
    if (variable.isNegated() != state) {
        makeAntecedent();
    }
}
Also used : ConditionalVariable(jmri.ConditionalVariable)

Aggregations

ConditionalVariable (jmri.ConditionalVariable)23 Conditional (jmri.Conditional)16 ConditionalAction (jmri.ConditionalAction)10 DefaultConditionalAction (jmri.implementation.DefaultConditionalAction)9 ArrayList (java.util.ArrayList)8 Logix (jmri.Logix)8 ConditionalManager (jmri.ConditionalManager)3 DefaultListModel (javax.swing.DefaultListModel)2 DefaultConditional (jmri.implementation.DefaultConditional)2 SensorGroupConditional (jmri.implementation.SensorGroupConditional)2 DefaultConditionalManager (jmri.managers.DefaultConditionalManager)2 Element (org.jdom2.Element)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Vector (java.util.Vector)1 JButton (javax.swing.JButton)1 JList (javax.swing.JList)1 JScrollPane (javax.swing.JScrollPane)1 Block (jmri.Block)1 Memory (jmri.Memory)1