Search in sources :

Example 26 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class LogixTableAction method donePressed.

/**
     * Respond to the Done button in the Edit Logix window.
     * <p>
     * Note: We also get here
     * if the Edit Logix window is dismissed, or if the Add button is pressed in
     * the Logic Table with an active Edit Logix window.
     *
     * @param e The event heard
     */
void donePressed(ActionEvent e) {
    if (_curLogix == null) {
        log.error("null pointer to _curLogix in donePressed method");
        finishDone();
        return;
    }
    if (checkEditConditional()) {
        return;
    }
    if (_curLogix.getSystemName().equals(SensorGroupFrame.logixSysName)) {
        finishDone();
        return;
    }
    // Check if the User Name has been changed
    // N11N
    String uName = editUserName.getText().trim();
    if (!(uName.equals(_curLogix.getUserName()))) {
        // user name has changed - check if already in use
        if (uName.length() > 0) {
            Logix p = _logixManager.getByUserName(uName);
            if (p != null) {
                // Logix with this user name already exists
                log.error("Failure to update Logix with Duplicate User Name: " + uName);
                javax.swing.JOptionPane.showMessageDialog(editLogixFrame, rbx.getString("Error6"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        // user name is unique, change it
        _curLogix.setUserName(uName);
        m.fireTableDataChanged();
    }
    // complete update and activate Logix
    finishDone();
}
Also used : Logix(jmri.Logix)

Example 27 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class LogixTableAction method deletePressed.

/**
     * Respond to the Delete button in the Edit Logix window.
     *
     * @param e The event heard
     */
void deletePressed(ActionEvent e) {
    if (checkEditConditional()) {
        return;
    }
    if (!checkConditionalReferences(_curLogix.getSystemName())) {
        return;
    }
    _showReminder = true;
    Logix x = _curLogix;
    // delete this Logix
    _logixManager.deleteLogix(x);
    _curLogix = null;
    deleteSourceWhereUsed();
    finishDone();
}
Also used : Logix(jmri.Logix)

Example 28 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class Maintenance method findEmptyPressed.

/**
     * Find useless Conditionals in the various Manager Objects.
     *
     * @param parent Frame to check
     */
public static void findEmptyPressed(Frame parent) {
    Vector<String> display = new Vector<String>();
    Vector<String> names = new Vector<String>();
    log.debug("findEmptyPressed");
    Iterator<String> iter = InstanceManager.getDefault(jmri.ConditionalManager.class).getSystemNameList().iterator();
    jmri.ConditionalManager cm = InstanceManager.getDefault(jmri.ConditionalManager.class);
    while (iter.hasNext()) {
        String name = iter.next();
        Conditional c = cm.getBySystemName(name);
        if (c != null) {
            ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
            if (variableList.size() == 0) {
                String userName = c.getUserName();
                display.add(MessageFormat.format(rbm.getString("OrphanName"), new Object[] { "Conditional", userName, name }));
                names.add(name);
            }
        }
    }
    DefaultListModel<String> listModel = new DefaultListModel<String>();
    for (int i = 0; i < display.size(); i++) {
        listModel.addElement(display.get(i));
    }
    JList<String> list = new JList<String>(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JButton button = new JButton(Bundle.getMessage("ButtonDelete"));
    button.setToolTipText(rbm.getString("OrphanDeleteHint") + Bundle.getMessage("ButtonDelete"));
    class EmptyListener implements ActionListener {

        JList<String> list;

        Vector<String> name;

        EmptyListener(JList<String> list, Vector<String> name) {
            this.list = list;
            this.name = name;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            int index = list.getMaxSelectionIndex();
            if (index < 0) {
                javax.swing.JOptionPane.showMessageDialog(null, rbm.getString("OrphanDeleteHint"), rbm.getString("DeleteTitle"), javax.swing.JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            int min = list.getMinSelectionIndex();
            DefaultListModel<String> model = (DefaultListModel<String>) list.getModel();
            while (index >= min) {
                String[] names = getTypeAndNames(name.get(index));
                model.remove(index);
                Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(names[2]);
                if (c != null) {
                    Logix x = InstanceManager.getDefault(jmri.ConditionalManager.class).getParentLogix(names[2]);
                    if (x != null) {
                        x.deActivateLogix();
                        x.deleteConditional(names[2]);
                        x.activateLogix();
                    }
                    InstanceManager.getDefault(jmri.ConditionalManager.class).deregister(c);
                    name.remove(index);
                    index--;
                }
            }
            index++;
            if (index >= model.getSize()) {
                index = model.getSize() - 1;
            }
            if (index >= 0) {
                list.setSelectedIndex(index);
            }
        }
    }
    JScrollPane scrollPane = new JScrollPane(list);
    button.addActionListener(new EmptyListener(list, names));
    button.setMaximumSize(button.getPreferredSize());
    makeDialog(scrollPane, button, parent, rbm.getString("EmptyConditionalTitle"));
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable) Logix(jmri.Logix) ActionListener(java.awt.event.ActionListener) Vector(java.util.Vector) JList(javax.swing.JList)

Example 29 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class LogixTableAction method copyLogixPressed.

/**
     * Copy the Logix as configured in the Copy set up pane.
     *
     * @param e the event heard
     */
void copyLogixPressed(ActionEvent e) {
    // N11N
    String uName = _addUserName.getText().trim();
    if (uName.length() == 0) {
        uName = null;
    }
    Logix targetLogix;
    if (_autoSystemName.isSelected()) {
        if (!checkLogixUserName(uName)) {
            return;
        }
        targetLogix = _logixManager.createNewLogix(uName);
    } else {
        if (!checkLogixSysName()) {
            return;
        }
        // N11N
        String sName = _systemName.getText().trim();
        // check if a Logix with this name already exists
        boolean createLogix = true;
        targetLogix = _logixManager.getBySystemName(sName);
        if (targetLogix != null) {
            int result = JOptionPane.showConfirmDialog(f, java.text.MessageFormat.format(rbx.getString("ConfirmLogixDuplicate"), new Object[] { sName, _logixSysName }), rbx.getString("ConfirmTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (JOptionPane.NO_OPTION == result) {
                return;
            }
            createLogix = false;
            String userName = targetLogix.getUserName();
            if (userName != null && userName.length() > 0) {
                _addUserName.setText(userName);
                uName = userName;
            }
        } else if (!checkLogixUserName(uName)) {
            return;
        }
        if (createLogix) {
            // Create the new Logix
            targetLogix = _logixManager.createNewLogix(sName, uName);
            if (targetLogix == null) {
                // should never get here unless there is an assignment conflict
                log.error("Failure to create Logix with System Name: " + sName);
                return;
            }
        } else if (targetLogix == null) {
            log.error("Error targetLogix is null!");
            return;
        } else {
            targetLogix.setUserName(uName);
        }
    }
    Logix srcLogic = _logixManager.getBySystemName(_logixSysName);
    for (int i = 0; i < srcLogic.getNumConditionals(); i++) {
        String cSysName = srcLogic.getConditionalByNumberOrder(i);
        copyConditionalToLogix(cSysName, srcLogic, targetLogix);
    }
    cancelAddPressed(null);
}
Also used : Logix(jmri.Logix)

Example 30 with Logix

use of jmri.Logix in project JMRI by JMRI.

the class LogixTableAction method checkFlags.

/**
     * Check if another Logix editing session is currently open
     * or no system name is provided.
     *
     * @param sName system name of Logix to be copied
     * @return true if a new session may be started
     */
boolean checkFlags(String sName) {
    if (inEditMode) {
        // Already editing a Logix, ask for completion of that edit
        javax.swing.JOptionPane.showMessageDialog(editLogixFrame, java.text.MessageFormat.format(rbx.getString("Error32"), new Object[] { _curLogix.getSystemName() }), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (inCopyMode) {
        // Already editing a Logix, ask for completion of that edit
        javax.swing.JOptionPane.showMessageDialog(editLogixFrame, java.text.MessageFormat.format(rbx.getString("Error31"), new Object[] { _logixSysName }), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (sName != null) {
        // check if a Logix with this name exists
        Logix x = _logixManager.getBySystemName(sName);
        if (x == null) {
            // Logix does not exist, so cannot be edited
            log.error("No Logix with system name: " + sName);
            javax.swing.JOptionPane.showMessageDialog(editLogixFrame, rbx.getString("Error5"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
            if (editLogixFrame != null) {
                editLogixFrame.setVisible(false);
            }
            return false;
        }
    }
    return true;
}
Also used : Logix(jmri.Logix)

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