Search in sources :

Example 1 with DojoMemoryStoreListItem

use of com.serotonin.m2m2.web.dojo.DojoMemoryStoreListItem in project ma-core-public by infiniteautomation.

the class DataPointDwr method getUnitsList.

@DwrPermission(user = true)
public ProcessResult getUnitsList() {
    ProcessResult result = new ProcessResult();
    List<DojoMemoryStoreListItem> pairs = new ArrayList<>();
    // Get SI Units
    int id = 0;
    for (Unit<?> unit : SI.getInstance().getUnits()) {
        pairs.add(new DojoMemoryStoreListItem(unit.toString(), id++));
    }
    // Get US Units
    for (Unit<?> unit : NonSI.getInstance().getUnits()) {
        pairs.add(new DojoMemoryStoreListItem(unit.toString(), id++));
    }
    List<String> addedUnits = UnitUtil.getAddedUnitLabels();
    for (String unit : addedUnits) {
        pairs.add(new DojoMemoryStoreListItem(unit, id++));
    }
    Collections.sort(pairs, new Comparator<DojoMemoryStoreListItem>() {

        @Override
        public int compare(DojoMemoryStoreListItem arg0, DojoMemoryStoreListItem arg1) {
            return arg0.getName().compareToIgnoreCase(arg1.getName());
        }
    });
    result.addData("units", pairs);
    return result;
}
Also used : DojoMemoryStoreListItem(com.serotonin.m2m2.web.dojo.DojoMemoryStoreListItem) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 DojoMemoryStoreListItem (com.serotonin.m2m2.web.dojo.DojoMemoryStoreListItem)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 ArrayList (java.util.ArrayList)1