From a0ca19775c1eec0d3eb430e7fedf6696804debc9 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 20 Oct 2023 17:24:17 +0200 Subject: [PATCH] allow AND conditions Signed-off-by: Mark Herwege --- .../UIComponentSitemapProvider.java | 153 ++++++++++++------ 1 file changed, 105 insertions(+), 48 deletions(-) diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java index 588c4b77c4a..5a9917b20e7 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java @@ -13,6 +13,7 @@ package org.openhab.core.ui.internal.components; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -32,6 +33,7 @@ import org.openhab.core.model.sitemap.SitemapProvider; import org.openhab.core.model.sitemap.sitemap.Button; import org.openhab.core.model.sitemap.sitemap.ColorArray; +import org.openhab.core.model.sitemap.sitemap.IconRule; import org.openhab.core.model.sitemap.sitemap.LinkableWidget; import org.openhab.core.model.sitemap.sitemap.Mapping; import org.openhab.core.model.sitemap.sitemap.Sitemap; @@ -48,6 +50,7 @@ import org.openhab.core.model.sitemap.sitemap.impl.DefaultImpl; import org.openhab.core.model.sitemap.sitemap.impl.FrameImpl; import org.openhab.core.model.sitemap.sitemap.impl.GroupImpl; +import org.openhab.core.model.sitemap.sitemap.impl.IconRuleImpl; import org.openhab.core.model.sitemap.sitemap.impl.ImageImpl; import org.openhab.core.model.sitemap.sitemap.impl.InputImpl; import org.openhab.core.model.sitemap.sitemap.impl.MappingImpl; @@ -94,10 +97,8 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan private static final String SITEMAP_PREFIX = "uicomponents_"; private static final String SITEMAP_SUFFIX = ".sitemap"; - private static final Pattern VISIBILITY_PATTERN = Pattern - .compile("(?[A-Za-z]\\w*)\\s*(?==|!=|<=|>=|<|>)\\s*(?\\+|-)?(?.+)"); - private static final Pattern COLOR_PATTERN = Pattern.compile( - "((?[A-Za-z]\\w*)?\\s*((?==|!=|<=|>=|<|>)\\s*(?\\+|-)?(?[^=]*[^= ]+))?\\s*=)?\\s*(?\\S+)"); + private static final Pattern CONDITION_PATTERN = Pattern + .compile("(?[A-Za-z]\\w*)?\\s*(?==|!=|<=|>=|<|>)?\\s*(?\\+|-)?(?.+)"); private Map sitemaps = new HashMap<>(); private @Nullable UIComponentRegistryFactory componentRegistryFactory; @@ -160,7 +161,11 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) { SitemapImpl sitemap = (SitemapImpl) SitemapFactory.eINSTANCE.createSitemap(); sitemap.setName(SITEMAP_PREFIX + rootComponent.getUID()); - sitemap.setLabel(rootComponent.getConfig().get("label").toString()); + Object label = rootComponent.getConfig().get("label"); + if (label == null) { + return sitemap; + } + sitemap.setLabel(label.toString()); if (rootComponent.getSlots() != null && rootComponent.getSlots().containsKey("widgets")) { for (UIComponent component : rootComponent.getSlot("widgets")) { @@ -298,24 +303,12 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) { addLabelColor(widget.getLabelColor(), component); addValueColor(widget.getValueColor(), component); addIconColor(widget.getIconColor(), component); + addIconRules(widget.getIconRules(), component); } return widget; } - private void setWidgetIconPropertyFromComponentConfig(Widget widget, @Nullable UIComponent component) { - if (component == null || component.getConfig() == null) { - return; - } - Object value = component.getConfig().get("staticIcon"); - if (value == null) { - return; - } - boolean staticIcon = Boolean.valueOf(ConfigUtil.normalizeType(value).toString()); - setWidgetPropertyFromComponentConfig(widget, component, "icon", - staticIcon ? SitemapPackage.WIDGET__STATIC_ICON : SitemapPackage.WIDGET__ICON); - } - private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UIComponent component, String configParamName, int feature) { if (component == null || component.getConfig() == null) { @@ -342,10 +335,28 @@ private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UICom } } + private void setWidgetIconPropertyFromComponentConfig(Widget widget, @Nullable UIComponent component) { + if (component == null || component.getConfig() == null) { + return; + } + Object staticIcon = component.getConfig().get("staticIcon"); + if (staticIcon != null && Boolean.valueOf(ConfigUtil.normalizeType(staticIcon).toString())) { + setWidgetPropertyFromComponentConfig(widget, component, "icon", SitemapPackage.WIDGET__STATIC_ICON); + return; + } + + Object icon = component.getConfig().get("icon"); + if (icon == null) { + return; + } + setWidgetPropertyFromComponentConfig(widget, component, "icon", SitemapPackage.WIDGET__ICON); + } + private void addWidgetMappings(EList mappings, UIComponent component) { if (component.getConfig() != null && component.getConfig().containsKey("mappings")) { - if (component.getConfig().get("mappings") instanceof Collection) { - for (Object sourceMapping : (Collection) component.getConfig().get("mappings")) { + Object sourceMappings = component.getConfig().get("mappings"); + if (sourceMappings instanceof Collection) { + for (Object sourceMapping : (Collection) sourceMappings) { if (sourceMapping instanceof String) { String[] splitMapping = sourceMapping.toString().split("="); String cmd = splitMapping[0].trim(); @@ -364,8 +375,9 @@ private void addWidgetMappings(EList mappings, UIComponent component) { private void addWidgetButtons(EList