Search in sources :

Example 1 with AlphanumComparator

use of jmri.util.AlphanumComparator in project JMRI by JMRI.

the class JmriBeanComboBox method getDisplayList.

/**
     * Get the display list used by this combo box
     *
     * @return the display list used by this combo box
     */
public String[] getDisplayList() {
    ArrayList<String> nameList = new ArrayList<>(Arrays.asList(_manager.getSystemNameArray()));
    for (NamedBean bean : exclude) {
        if (bean != null) {
            nameList.remove(bean.getSystemName());
        }
    }
    String[] displayList = new String[nameList.size()];
    if (_displayOrder == DisplayOptions.SYSTEMNAME) {
        displayList = nameList.toArray(displayList);
    } else {
        for (int i = 0; i < nameList.size(); i++) {
            String name = nameList.get(i);
            NamedBean nBean = _manager.getBeanBySystemName(name);
            if (nBean != null) {
                String uname = nBean.getUserName();
                switch(_displayOrder) {
                    case DISPLAYNAME:
                        displayList[i] = nBean.getDisplayName();
                        break;
                    case USERNAME:
                        if (uname != null && !uname.equals("")) {
                            displayList[i] = uname;
                        } else {
                            displayList[i] = name;
                        }
                        break;
                    case USERNAMESYSTEMNAME:
                        if (uname != null && !uname.equals("")) {
                            displayList[i] = nBean.getUserName() + " - " + name;
                        } else {
                            displayList[i] = name;
                        }
                        break;
                    case SYSTEMNAMEUSERNAME:
                        if (uname != null && !uname.equals("")) {
                            displayList[i] = name + " - " + nBean.getUserName();
                        } else {
                            displayList[i] = name;
                        }
                        break;
                    default:
                        displayList[i] = nBean.getDisplayName();
                }
                displayToBean.put(displayList[i], nBean);
            }
        }
    }
    java.util.Arrays.sort(displayList, new AlphanumComparator());
    return displayList;
}
Also used : NamedBean(jmri.NamedBean) AlphanumComparator(jmri.util.AlphanumComparator) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 NamedBean (jmri.NamedBean)1 AlphanumComparator (jmri.util.AlphanumComparator)1