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

Extend "iconcolor" attribute to all sitemap elements #3403

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -43,6 +43,7 @@
* This is a class that listens on item state change events and creates sitemap events for a dedicated sitemap page.
*
* @author Kai Kreuzer - Initial contribution
* @author Laurent Garnier - Added support for icon color
*/
public class PageChangeListener implements StateChangeListener {

Expand Down Expand Up @@ -152,6 +153,10 @@ private Set<Item> getAllItems(EList<Widget> widgets) {
for (ColorArray rule : widget.getValueColor()) {
addItemWithName(items, rule.getItem());
}
// now scan value icon rules
for (ColorArray rule : widget.getIconColor()) {
addItemWithName(items, rule.getItem());
}
}
}
return items;
Expand Down Expand Up @@ -236,6 +241,7 @@ private SitemapWidgetEvent constructSitemapEventForWidget(Item item, State state
event.label = itemUIRegistry.getLabel(widget);
event.labelcolor = itemUIRegistry.getLabelColor(widget);
event.valuecolor = itemUIRegistry.getValueColor(widget);
event.iconcolor = itemUIRegistry.getIconColor(widget);
event.widgetId = itemUIRegistry.getWidgetId(widget);
event.visibility = itemUIRegistry.getVisiblity(widget);
event.descriptionChanged = false;
Expand Down Expand Up @@ -289,6 +295,11 @@ private boolean definesVisibilityOrColor(Widget w, String name) {
return true;
}
}
for (ColorArray rule : w.getIconColor()) {
lolodomo marked this conversation as resolved.
Show resolved Hide resolved
if (name.equals(rule.getItem())) {
return true;
}
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
* @author Yordan Zhelev - Added Swagger annotations
* @author Markus Rathgeb - Migrated to JAX-RS Whiteboard Specification
* @author Wouter Born - Migrated to OpenAPI annotations
* @author Laurent Garnier - Added support for icon color
*/
@Component(service = RESTResource.class)
@JaxrsResource
Expand Down Expand Up @@ -514,6 +515,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
bean.icon = itemUIRegistry.getCategory(widget);
bean.labelcolor = itemUIRegistry.getLabelColor(widget);
bean.valuecolor = itemUIRegistry.getValueColor(widget);
bean.iconcolor = itemUIRegistry.getIconColor(widget);
bean.label = itemUIRegistry.getLabel(widget);
bean.type = widget.eClass().getName();
bean.visibility = itemUIRegistry.getVisiblity(widget);
Expand Down Expand Up @@ -732,10 +734,11 @@ private Set<GenericItem> getAllItems(EList<Widget> widgets) {
if (widget instanceof Frame) {
items.addAll(getAllItems(((Frame) widget).getChildren()));
}
// Consider items involved in any visibility, labelcolor and valuecolor condition
// Consider items involved in any visibility, labelcolor, valuecolor and iconcolor condition
items.addAll(getItemsInVisibilityCond(widget.getVisibility()));
items.addAll(getItemsInColorCond(widget.getLabelColor()));
items.addAll(getItemsInColorCond(widget.getValueColor()));
items.addAll(getItemsInColorCond(widget.getIconColor()));
}
return items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* A sitemap event, which provides details about a widget that has changed.
*
* @author Kai Kreuzer - Initial contribution
* @author Laurent Garnier - New field iconcolor
*/
public class SitemapWidgetEvent extends SitemapEvent {

Expand All @@ -27,6 +28,7 @@ public class SitemapWidgetEvent extends SitemapEvent {
public String icon;
public String labelcolor;
public String valuecolor;
public String iconcolor;
public boolean visibility;
public String state;
public EnrichedItemDTO item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* @author Kai Kreuzer - Initial contribution
* @author Chris Jackson - Initial contribution
* @author Laurent Garnier - New field iconcolor
*/
public class WidgetDTO {

Expand All @@ -35,6 +36,7 @@ public class WidgetDTO {
public String icon;
public String labelcolor;
public String valuecolor;
public String iconcolor;

// widget-specific attributes
public final List<MappingDTO> mappings = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class SitemapResourceTest extends JavaTest {
private static final String VISIBILITY_RULE_ITEM_NAME = "visibilityRuleItem";
private static final String LABEL_COLOR_ITEM_NAME = "labelColorItemName";
private static final String VALUE_COLOR_ITEM_NAME = "valueColorItemName";
private static final String ICON_COLOR_ITEM_NAME = "iconColorItemName";
private static final String WIDGET1_LABEL = "widget 1";
private static final String WIDGET2_LABEL = "widget 2";
private static final String WIDGET1_ID = "00";
Expand All @@ -91,6 +92,7 @@ public class SitemapResourceTest extends JavaTest {
private @NonNullByDefault({}) GenericItem visibilityRuleItem;
private @NonNullByDefault({}) GenericItem labelColorItem;
private @NonNullByDefault({}) GenericItem valueColorItem;
private @NonNullByDefault({}) GenericItem iconColorItem;

private @Mock @NonNullByDefault({}) HttpHeaders headersMock;
private @Mock @NonNullByDefault({}) Sitemap defaultSitemapMock;
Expand Down Expand Up @@ -118,6 +120,7 @@ public void setup() throws Exception {
visibilityRuleItem = new TestItem(VISIBILITY_RULE_ITEM_NAME);
labelColorItem = new TestItem(LABEL_COLOR_ITEM_NAME);
valueColorItem = new TestItem(VALUE_COLOR_ITEM_NAME);
iconColorItem = new TestItem(ICON_COLOR_ITEM_NAME);

when(localeServiceMock.getLocale(null)).thenReturn(Locale.US);

Expand Down Expand Up @@ -265,6 +268,7 @@ public void whenGetPageDataShouldReturnPageBean() throws ItemNotFoundException {
assertThat(pageDTO.widgets.get(0).label, is(WIDGET1_LABEL));
assertThat(pageDTO.widgets.get(0).labelcolor, is("GREEN"));
assertThat(pageDTO.widgets.get(0).valuecolor, is("BLUE"));
assertThat(pageDTO.widgets.get(0).iconcolor, is("ORANGE"));
assertThat(pageDTO.widgets.get(0).state, nullValue());
assertThat(pageDTO.widgets.get(0).item, notNullValue());
assertThat(pageDTO.widgets.get(0).item.name, is(ITEM_NAME));
Expand All @@ -274,6 +278,7 @@ public void whenGetPageDataShouldReturnPageBean() throws ItemNotFoundException {
assertThat(pageDTO.widgets.get(1).label, is(WIDGET2_LABEL));
assertThat(pageDTO.widgets.get(1).labelcolor, nullValue());
assertThat(pageDTO.widgets.get(1).valuecolor, nullValue());
assertThat(pageDTO.widgets.get(1).iconcolor, nullValue());
assertThat(pageDTO.widgets.get(1).state, is("ON"));
assertThat(pageDTO.widgets.get(1).item, notNullValue());
assertThat(pageDTO.widgets.get(1).item.name, is(ITEM_NAME));
Expand All @@ -286,13 +291,15 @@ private void configureItemUIRegistry(State state1, State state2) throws ItemNotF
when(itemUIRegistryMock.getItem(VISIBILITY_RULE_ITEM_NAME)).thenReturn(visibilityRuleItem);
when(itemUIRegistryMock.getItem(LABEL_COLOR_ITEM_NAME)).thenReturn(labelColorItem);
when(itemUIRegistryMock.getItem(VALUE_COLOR_ITEM_NAME)).thenReturn(valueColorItem);
when(itemUIRegistryMock.getItem(ICON_COLOR_ITEM_NAME)).thenReturn(iconColorItem);

when(itemUIRegistryMock.getWidgetId(widgets.get(0))).thenReturn(WIDGET1_ID);
when(itemUIRegistryMock.getCategory(widgets.get(0))).thenReturn("");
when(itemUIRegistryMock.getLabel(widgets.get(0))).thenReturn(WIDGET1_LABEL);
when(itemUIRegistryMock.getVisiblity(widgets.get(0))).thenReturn(true);
when(itemUIRegistryMock.getLabelColor(widgets.get(0))).thenReturn("GREEN");
when(itemUIRegistryMock.getValueColor(widgets.get(0))).thenReturn("BLUE");
when(itemUIRegistryMock.getIconColor(widgets.get(0))).thenReturn("ORANGE");
when(itemUIRegistryMock.getState(widgets.get(0))).thenReturn(state1);

when(itemUIRegistryMock.getWidgetId(widgets.get(1))).thenReturn(WIDGET2_ID);
Expand All @@ -301,6 +308,7 @@ private void configureItemUIRegistry(State state1, State state2) throws ItemNotF
when(itemUIRegistryMock.getVisiblity(widgets.get(1))).thenReturn(true);
when(itemUIRegistryMock.getLabelColor(widgets.get(1))).thenReturn(null);
when(itemUIRegistryMock.getValueColor(widgets.get(1))).thenReturn(null);
when(itemUIRegistryMock.getIconColor(widgets.get(1))).thenReturn(null);
when(itemUIRegistryMock.getState(widgets.get(1))).thenReturn(state2);
}

Expand Down Expand Up @@ -337,9 +345,17 @@ private EList<Widget> initSitemapWidgets() {
valueColors.add(valueColor);
when(w1.getValueColor()).thenReturn(valueColors);

// add icon color conditions to the item:
ColorArray iconColor = mock(ColorArray.class);
when(iconColor.getItem()).thenReturn(ICON_COLOR_ITEM_NAME);
EList<ColorArray> iconColors = new BasicEList<>();
iconColors.add(iconColor);
when(w1.getIconColor()).thenReturn(iconColors);

visibilityRules = new BasicEList<>();
labelColors = new BasicEList<>();
valueColors = new BasicEList<>();
iconColors = new BasicEList<>();

Widget w2 = mock(Widget.class);
EClass switchEClass = mock(EClass.class);
Expand All @@ -351,6 +367,7 @@ private EList<Widget> initSitemapWidgets() {
when(w2.getVisibility()).thenReturn(visibilityRules);
when(w2.getLabelColor()).thenReturn(labelColors);
when(w2.getValueColor()).thenReturn(valueColors);
when(w2.getIconColor()).thenReturn(iconColors);

BasicEList<Widget> widgets = new BasicEList<>(2);
widgets.add(w1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ Frame:
{Frame} 'Frame' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Text:
{Text} 'Text' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Group:
'Group' (('item=' item=GroupItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Image:
Expand All @@ -54,6 +57,7 @@ Video:
('url=' url=(STRING)) & ('encoding=' encoding=(STRING))? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Chart:
Expand All @@ -62,6 +66,7 @@ Chart:
('legend=' legend=BOOLEAN_OBJECT)? & ('forceasitem=' forceAsItem=BOOLEAN_OBJECT)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))? &
('yAxisDecimalPattern=' yAxisDecimalPattern=(STRING))?);

Expand All @@ -70,20 +75,23 @@ Webview:
('height=' height=INT)? & ('url=' url=(STRING)) &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Switch:
'Switch' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('mappings=[' mappings+=Mapping (',' mappings+=Mapping)* ']')? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Mapview:
'Mapview' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('height=' height=INT)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Slider:
Expand All @@ -92,47 +100,54 @@ Slider:
('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? & ('step=' step=Number)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Selection:
'Selection' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('mappings=[' mappings+=Mapping (',' mappings+=Mapping)* ']')? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

List:
'List' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)?
('separator=' separator=STRING) &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Setpoint:
'Setpoint' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? & ('step=' step=Number)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Colorpicker:
'Colorpicker' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & ('sendFrequency='
frequency=INT)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Input:
'Input' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Default:
'Default' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? &
('height=' height=INT)? &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);

Mapping:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
* "system:sitemap" namespace.
*
* @author Yannick Schaus - Initial contribution
* @author Laurent Garnier - icon color support for all widgets
*/
@NonNullByDefault
@Component(service = SitemapProvider.class)
Expand Down Expand Up @@ -186,7 +187,6 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) {
widget = imageWidget;
setWidgetPropertyFromComponentConfig(widget, component, "url", SitemapPackage.IMAGE__URL);
setWidgetPropertyFromComponentConfig(widget, component, "refresh", SitemapPackage.IMAGE__REFRESH);
addIconColor(imageWidget.getIconColor(), component);
break;
case "Video":
VideoImpl videoWidget = (VideoImpl) SitemapFactory.eINSTANCE.createVideo();
Expand Down Expand Up @@ -284,6 +284,7 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) {
addWidgetVisibility(widget.getVisibility(), component);
addLabelColor(widget.getLabelColor(), component);
addValueColor(widget.getValueColor(), component);
addIconColor(widget.getIconColor(), component);
}

return widget;
Expand Down Expand Up @@ -363,7 +364,7 @@ private void addValueColor(EList<ColorArray> valueColor, UIComponent component)
}

private void addIconColor(EList<ColorArray> iconColor, UIComponent component) {
addColor(iconColor, component, "valuecolor");
addColor(iconColor, component, "iconcolor");
}

private void addColor(EList<ColorArray> color, UIComponent component, String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
* @author Chris Jackson - Initial contribution
* @author Stefan Triller - Method to convert a state into something a sitemap entity can understand
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
* @author Laurent Garnier - new method getIconColor
*/
@NonNullByDefault
@Component(immediate = true, configurationPid = "org.openhab.sitemap", //
Expand Down Expand Up @@ -743,6 +744,7 @@ private void copyProperties(Widget source, Widget target) {
target.getVisibility().addAll(EcoreUtil.copyAll(source.getVisibility()));
target.getLabelColor().addAll(EcoreUtil.copyAll(source.getLabelColor()));
target.getValueColor().addAll(EcoreUtil.copyAll(source.getValueColor()));
target.getIconColor().addAll(EcoreUtil.copyAll(source.getIconColor()));
}

/**
Expand Down Expand Up @@ -1176,6 +1178,11 @@ private boolean matchStateToValue(State state, String value, @Nullable String ma
return processColorDefinition(getState(w), w.getValueColor());
}

@Override
public @Nullable String getIconColor(Widget w) {
return processColorDefinition(getState(w), w.getIconColor());
}

@Override
public boolean getVisiblity(Widget w) {
// Default to visible if parameters not set
Expand Down
Loading