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());
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations