Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] create Text widgets for read only Switch items #3877

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ private void applyConfig(@Nullable Map<String, Object> config) {
return createPlayerButtons();
} else if (RollershutterItem.class.equals(itemType) //
|| SwitchItem.class.equals(itemType)) {
return SitemapFactory.eINSTANCE.createSwitch();
if (isReadOnly(itemName)) {
return SitemapFactory.eINSTANCE.createText();
} else {
return SitemapFactory.eINSTANCE.createSwitch();
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,19 @@ public void getDefaultWidgetsForStringItem() {
assertThat(defaultWidget, is(instanceOf(Text.class)));
}

@Test
public void getDefaultWidgetsForSwitchItem() {
// SwitchItem without CommandOptions or StateOptions should return Switch element
Widget defaultWidget = uiRegistry.getDefaultWidget(SwitchItem.class, ITEM_NAME);
assertThat(defaultWidget, is(instanceOf(Switch.class)));

// Read-only SwitchItem should return Text element
when(itemMock.getStateDescription()).thenReturn(
StateDescriptionFragmentBuilder.create().withReadOnly(Boolean.TRUE).build().toStateDescription());
defaultWidget = uiRegistry.getDefaultWidget(SwitchItem.class, ITEM_NAME);
assertThat(defaultWidget, is(instanceOf(Text.class)));
}

@Test
public void getUnitForWidgetForNonNumberItem() throws Exception {
String unit = uiRegistry.getUnitForWidget(widgetMock);
Expand Down