Search in sources :

Example 6 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class LRouteTableAction method setupEdit.

/**
     * Interprets the conditionals from the Logix that was selected for editing
     * and attempts to reconstruct the window entries.
     *
     * @param e the action event
     */
void setupEdit(ActionEvent e) {
    makeEditWindow();
    Logix logix = checkNamesOK();
    if (logix == null) {
        return;
    }
    logix.deActivateLogix();
    // get information for this route
    _systemName.setEnabled(false);
    _userName.setEnabled(false);
    _systemName.setText(logix.getSystemName());
    _userName.setText(logix.getUserName());
    String logixSysName = logix.getSystemName();
    int numConditionals = logix.getNumConditionals();
    if (log.isDebugEnabled()) {
        log.debug("setupEdit: logixSysName= " + logixSysName + ", numConditionals= " + numConditionals);
    }
    for (int i = 0; i < numConditionals; i++) {
        String cSysName = logix.getConditionalByNumberOrder(i);
        switch(getRouteConditionalType(logixSysName, cSysName)) {
            case 'T':
                getControlsAndActions(cSysName);
                break;
            case 'A':
                getAlignmentSensors(cSysName);
                break;
            case 'L':
                getLockConditions(cSysName);
                break;
            default:
                log.warn("Unexpected getRouteConditionalType {}", getRouteConditionalType(logixSysName, cSysName));
                break;
        }
    }
    // set up buttons and notes
    deleteButton.setVisible(true);
    cancelButton.setVisible(true);
    updateButton.setVisible(true);
    _typePanel.setVisible(false);
    _initialize = LOGIX_INITIALIZER.equals(logixSysName);
    if (_initialize) {
        _initializeButton.doClick();
    } else {
        _newRouteButton.doClick();
    }
    createButton.setVisible(false);
}
Also used : Logix(jmri.Logix)

Example 7 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class LRouteTableAction method editPressed.

/**
     * Edit button in Logix Route table pressed.
     *
     * @param sName system name of Logix to edit
     */
void editPressed(String sName) {
    // Logix was found, initialize for edit
    Logix logix = _logixManager.getBySystemName(sName);
    if (logix == null) {
        log.error("Logix \"" + sName + "\" not Found.");
        return;
    }
    // deactivate this Logix
    _systemName.setText(sName);
    // create the Edit Logix Window
    // Use separate Runnable so window is created on top
    Runnable t = () -> {
        setupEdit(null);
        _addFrame.setVisible(true);
    };
    javax.swing.SwingUtilities.invokeLater(t);
}
Also used : Logix(jmri.Logix)

Example 8 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class SensorGroupFrame method addPressed.

void addPressed() {
    deleteGroup(false);
    String group = _nameField.getText();
    if (group == null || group.length() == 0) {
        javax.swing.JOptionPane.showMessageDialog(this, "Please enter a name for this group.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    Logix logix = getSystemLogix();
    logix.deActivateLogix();
    String cSystemName = ConditionalSystemPrefix + group.toUpperCase();
    String cUserName = ConditionalUserPrefix + group;
    // add new Conditional
    ArrayList<ConditionalVariable> variableList = new ArrayList<ConditionalVariable>();
    ArrayList<ConditionalAction> actionList = new ArrayList<ConditionalAction>();
    int count = 0;
    for (int i = 0; i < _sensorModel.getRowCount(); i++) {
        if ((Boolean) _sensorModel.getValueAt(i, BeanTableModel.INCLUDE_COLUMN)) {
            String sensor = (String) _sensorModel.getValueAt(i, BeanTableModel.SNAME_COLUMN);
            variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_OR, Conditional.TYPE_SENSOR_ACTIVE, sensor, true));
            actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, sensor, Sensor.INACTIVE, ""));
            count++;
        }
    }
    if (count < 2) {
        javax.swing.JOptionPane.showMessageDialog(this, "A Sensor Group needs to have at least 2 sensors to be useful.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
    }
    Conditional c = new SensorGroupConditional(cSystemName, cUserName);
    //        InstanceManager.getDefault(jmri.ConditionalManager.class).register(c);
    c.setStateVariables(variableList);
    c.setLogicType(Conditional.ALL_OR, "");
    c.setAction(actionList);
    // Update the Logix Conditional names list
    logix.addConditional(cSystemName, 0);
    // Update the Logix Conditional hash map
    logix.addConditional(cSystemName, c);
    logix.setEnabled(true);
    logix.activateLogix();
    ((DefaultListModel<String>) _sensorGroupList.getModel()).addElement(cUserName.substring(ConditionalUserPrefix.length()));
    clear();
}
Also used : DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) ArrayList(java.util.ArrayList) SensorGroupConditional(jmri.implementation.SensorGroupConditional) DefaultListModel(javax.swing.DefaultListModel) Conditional(jmri.Conditional) SensorGroupConditional(jmri.implementation.SensorGroupConditional) ConditionalVariable(jmri.ConditionalVariable) Logix(jmri.Logix) ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction)

Example 9 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class SensorGroupFrame method deleteGroup.

void deleteGroup(boolean showMsg) {
    String group = _nameField.getText();
    if (group == null || group.equals("")) {
        if (showMsg) {
            javax.swing.JOptionPane.showMessageDialog(this, "'View' the group or enter the group name in the 'Group Name' field before selecting 'Undo Group'", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        return;
    }
    String prefix = (namePrefix + group + nameDivider).toUpperCase();
    // remove the old routes
    RouteManager rm = InstanceManager.getDefault(jmri.RouteManager.class);
    List<String> l = rm.getSystemNameList();
    for (int i = 0; i < l.size(); i++) {
        String name = l.get(i);
        if (name.startsWith(prefix)) {
            // OK, kill this one
            Route r = rm.getBySystemName(l.get(i));
            r.deActivateRoute();
            rm.deleteRoute(r);
        }
    }
    String cSystemName = (ConditionalSystemPrefix + group).toUpperCase();
    String cUserName = ConditionalUserPrefix + group;
    Logix logix = getSystemLogix();
    for (int i = 0; i < logix.getNumConditionals(); i++) {
        String name = logix.getConditionalByNumberOrder(i);
        if (cSystemName.equals(name) || cUserName.equals(name)) {
            Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(name);
            if (c == null) {
                log.error("Conditional \"" + name + "\" expected but NOT found in Logix " + logix.getSystemName());
            } else {
                logix.deleteConditional(cSystemName);
                break;
            }
        }
    }
    DefaultListModel<String> model = (DefaultListModel<String>) _sensorGroupList.getModel();
    int index = model.indexOf(group);
    if (index > -1) {
        model.remove(index);
    }
    index = _sensorGroupList.getSelectedIndex();
    if (index > -1) {
        String sysName = ConditionalSystemPrefix + model.elementAt(index);
        String[] msgs = logix.deleteConditional(sysName);
        if (msgs != null) {
            if (showMsg) {
                javax.swing.JOptionPane.showMessageDialog(this, "Conditional " + msgs[0] + " (" + msgs[1] + ") is a Conditional Variable in the Conditional,\n" + msgs[2] + " (" + msgs[3] + "), of Logix, " + msgs[4] + " (" + msgs[5] + ").\nPlease remove that variable first.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
            }
        } else {
            model.remove(index);
        }
    }
}
Also used : Logix(jmri.Logix) DefaultListModel(javax.swing.DefaultListModel) Conditional(jmri.Conditional) SensorGroupConditional(jmri.implementation.SensorGroupConditional) Route(jmri.Route) RouteManager(jmri.RouteManager)

Example 10 with Logix

use of jmri.Logix 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)

Aggregations

Logix (jmri.Logix)39 Conditional (jmri.Conditional)15 ConditionalVariable (jmri.ConditionalVariable)8 ConditionalAction (jmri.ConditionalAction)7 ArrayList (java.util.ArrayList)6 LogixManager (jmri.LogixManager)6 ConditionalManager (jmri.ConditionalManager)5 DefaultConditionalAction (jmri.implementation.DefaultConditionalAction)5 SensorGroupConditional (jmri.implementation.SensorGroupConditional)5 DefaultListModel (javax.swing.DefaultListModel)4 DefaultConditional (jmri.implementation.DefaultConditional)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JButton (javax.swing.JButton)3 Route (jmri.Route)3 Sensor (jmri.Sensor)3 UserPreferencesManager (jmri.UserPreferencesManager)3 Element (org.jdom2.Element)3 BoxLayout (javax.swing.BoxLayout)2 JLabel (javax.swing.JLabel)2