Search in sources :

Example 1 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class AbstractNamedBeanManagerConfigXML method checkNameNormalization.

/**
     * Common service routine to check for and report on
     * normalization (errors) in the incoming NamedBean's 
     * name(s)
     * <p>
     * If NamedBeam.normalizeUserName changes, this may want to be updated.
     * <p>
     * Right now, this just logs. Someday, perhaps it should notify
     * upward of found issues by throwing an exception.
     *
     * Package-level access to allow testing
     *
     * @param rawSystemName The proposed system name string, before normalization
     * @param rawUserName The proposed user name string, before normalization
     * @param manager The NamedBeanManager that will be storing this
     */
void checkNameNormalization(@Nonnull String rawSystemName, String rawUserName, @Nonnull jmri.Manager manager) {
    // just check and log
    if (rawUserName != null) {
        String normalizedUserName = NamedBean.normalizeUserName(rawUserName);
        if (!rawUserName.equals(normalizedUserName)) {
            log.warn("Requested user name \"{}\" for system name \"{}\" was normalized to \"{}\"", rawUserName, rawSystemName, normalizedUserName);
        }
        NamedBean bean = manager.getBeanByUserName(normalizedUserName);
        if (bean != null && !bean.getSystemName().equals(rawSystemName)) {
            log.warn("User name \"{}\" already exists as system name \"{}\"", normalizedUserName, bean.getSystemName());
        }
    }
}
Also used : NamedBean(jmri.NamedBean)

Example 2 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method setSelectedBeanByName.

public void setSelectedBeanByName(String name) {
    if (name == null) {
        return;
    }
    NamedBean nBean = _manager.getNamedBean(name);
    setSelectedBean(nBean);
}
Also used : NamedBean(jmri.NamedBean)

Example 3 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method getNamedBean.

//validateText
/**
     * Get the bean for ether the typed in text or selected item from this
     * ComboBox.
     *
     * @return the selected bean or null if no selection
     */
public NamedBean getNamedBean() {
    NamedBean result = null;
    jmri.Manager uDaManager = getManager();
    String comboBoxText = getEditor().getItem().toString();
    comboBoxText = (null != comboBoxText) ? NamedBean.normalizeUserName(comboBoxText) : "";
    //try user name
    result = uDaManager.getBeanByUserName(comboBoxText);
    if (null == result) {
        //try system name
        //note: don't use getBeanBySystemName here
        //throws an IllegalArgumentException if text is invalid
        result = uDaManager.getNamedBean(comboBoxText);
    }
    if (null == result) {
        //quick search to see if text matches anything in the drop down list
        String[] displayList = getDisplayList();
        //assume failure (pessimist!)
        boolean found = false;
        for (String item : displayList) {
            if (item.equals(comboBoxText)) {
                found = true;
                break;
            }
        }
        if (found) {
            //if we found it there then...
            //walk the namedBeanList...
            List<NamedBean> namedBeanList = uDaManager.getNamedBeanList();
            for (NamedBean namedBean : namedBeanList) {
                //checking to see if it matches "<sname> - <uname>" or "<uname> - <sname>"
                String uname = namedBean.getUserName();
                String sname = namedBean.getSystemName();
                if ((null != uname) && (null != sname)) {
                    String usname = uname + " - " + sname;
                    String suname = sname + " - " + uname;
                    if (comboBoxText.equals(usname) || comboBoxText.equals(suname)) {
                        result = namedBean;
                        break;
                    }
                }
            }
        }
    }
    return result;
}
Also used : NamedBean(jmri.NamedBean)

Example 4 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method getSelectedUserName.

/**
     * Get the User name of the selected namedBean
     *
     * @return the user name of the selected bean or null if there is no
     *         selection
     */
public String getSelectedUserName() {
    String result = null;
    NamedBean nBean = getSelectedBean();
    if (nBean != null) {
        result = nBean.getDisplayName();
    }
    return result;
}
Also used : NamedBean(jmri.NamedBean)

Example 5 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method getSelectedSystemName.

/**
     * Get the system name of the selected namedBean
     *
     * @return the system name of the selected bean or null if there is no
     *         selection
     */
public String getSelectedSystemName() {
    String result = null;
    NamedBean nBean = getSelectedBean();
    if (nBean != null) {
        result = nBean.getSystemName();
    }
    return result;
}
Also used : NamedBean(jmri.NamedBean)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4