Fix selected position labels when editing on/off/on type switches (#1091)

This commit is contained in:
Cem Yuksel
2026-10-27 09:39:22 -06:00
committed by GitHub
parent 47b3bb2804
commit 6d4820e2c4
@@ -35,4 +35,43 @@ public class ToggleSwitchPositionPropertyValueSource extends AbstractDynamicProp
}
return res;
}
@Override
public String getDisplayValue(Object value) {
if (value == null) {
return "None";
}
if (properties == null) {
return super.getDisplayValue(value);
}
Optional<PropertyWrapper> typeProperty = properties.stream()
.filter(p -> {
try {
return p.getGetter().getName().equals("getValue");
} catch (NoSuchMethodException e) {
return false;
}
})
.findFirst();
if (typeProperty.isEmpty()) {
return super.getDisplayValue(value);
}
ToggleSwitchType switchType =
(ToggleSwitchType) typeProperty.get().getValue();
int position = (Integer) value;
if (switchType.name().endsWith("_off")) {
if (position == 1) {
return "OFF";
}
return "ON" + (position == 0 ? 1 : 2);
}
return "ON" + (position + 1);
}
}