diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/MappingDTO.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/MappingDTO.java index e5a3f15c197..585f2c5ce24 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/MappingDTO.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/MappingDTO.java @@ -14,13 +14,16 @@ /** * This is a data transfer object that is used to serialize command mappings. - * + * * @author Kai Kreuzer - Initial contribution + * @author Laurent Garnier - New fields position and icon */ public class MappingDTO { + public Integer position; public String command; public String label; + public String icon; public MappingDTO() { } diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java index 2874f5a7654..0fc96d3cc94 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java @@ -76,6 +76,8 @@ import org.openhab.core.library.CoreItemFactory; import org.openhab.core.library.types.HSBType; import org.openhab.core.model.sitemap.SitemapProvider; +import org.openhab.core.model.sitemap.sitemap.Button; +import org.openhab.core.model.sitemap.sitemap.Buttongrid; import org.openhab.core.model.sitemap.sitemap.Chart; import org.openhab.core.model.sitemap.sitemap.ColorArray; import org.openhab.core.model.sitemap.sitemap.Frame; @@ -131,6 +133,7 @@ * @author Wouter Born - Migrated to OpenAPI annotations * @author Laurent Garnier - Added support for icon color * @author Mark Herwege - Added pattern and unit fields + * @author Laurent Garnier - Added support for new sitemap element Buttongrid */ @Component(service = { RESTResource.class, EventSubscriber.class }) @JaxrsResource @@ -614,6 +617,17 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null bean.maxValue = setpointWidget.getMaxValue(); bean.step = setpointWidget.getStep(); } + if (widget instanceof Buttongrid buttonGridWidget) { + bean.columns = buttonGridWidget.getColumns(); + for (Button button : buttonGridWidget.getButtons()) { + MappingDTO mappingBean = new MappingDTO(); + mappingBean.position = button.getPosition(); + mappingBean.command = button.getCmd(); + mappingBean.label = button.getLabel(); + mappingBean.icon = button.getIcon(); + bean.mappings.add(mappingBean); + } + } return bean; } diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java index ce947faadba..b5fe7d2f0c5 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java @@ -25,6 +25,7 @@ * @author Chris Jackson - Initial contribution * @author Laurent Garnier - New field iconcolor * @author Mark herwege - New fields pattern, unit + * @author Laurent Garnier - New field columns */ public class WidgetDTO { @@ -60,6 +61,7 @@ public class WidgetDTO { public String yAxisDecimalPattern; public Boolean legend; public Boolean forceAsItem; + public Integer columns; public String state; public EnrichedItemDTO item; diff --git a/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext b/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext index 2a3088db948..3e00af631c1 100644 --- a/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext +++ b/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext @@ -15,7 +15,7 @@ Widget: (LinkableWidget | NonLinkableWidget); NonLinkableWidget: - Switch | Selection | Slider | Setpoint | Video | Chart | Webview | Colorpicker | Mapview | Input | Default; + Switch | Selection | Slider | Setpoint | Video | Chart | Webview | Colorpicker | Mapview | Input | Buttongrid | Default; LinkableWidget: (Text | Group | Image | Frame) @@ -149,6 +149,16 @@ Input: ('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); +Buttongrid: + 'Buttongrid' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & + ('columns=' columns=INT) & + ('buttons=[' buttons+=Button (',' buttons+=Button)* ']') & + ('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) | ('staticIcon=' staticIcon=Icon))? & @@ -158,6 +168,9 @@ Default: ('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); +Button: + position=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?; + Mapping: cmd=Command '=' label=(ID | STRING); 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 39c0f47dce5..41322c71655 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 @@ -30,6 +30,7 @@ import org.openhab.core.model.core.EventType; import org.openhab.core.model.core.ModelRepositoryChangeListener; 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.LinkableWidget; import org.openhab.core.model.sitemap.sitemap.Mapping; @@ -38,6 +39,8 @@ import org.openhab.core.model.sitemap.sitemap.SitemapPackage; import org.openhab.core.model.sitemap.sitemap.VisibilityRule; import org.openhab.core.model.sitemap.sitemap.Widget; +import org.openhab.core.model.sitemap.sitemap.impl.ButtonImpl; +import org.openhab.core.model.sitemap.sitemap.impl.ButtongridImpl; import org.openhab.core.model.sitemap.sitemap.impl.ChartImpl; import org.openhab.core.model.sitemap.sitemap.impl.ColorArrayImpl; import org.openhab.core.model.sitemap.sitemap.impl.ColorpickerImpl; @@ -75,6 +78,7 @@ * * @author Yannick Schaus - Initial contribution * @author Laurent Garnier - icon color support for all widgets + * @author Laurent Garnier - Added support for new element Buttongrid */ @NonNullByDefault @Component(service = SitemapProvider.class) @@ -254,6 +258,12 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) { setWidgetPropertyFromComponentConfig(widget, component, "frequency", SitemapPackage.COLORPICKER__FREQUENCY); break; + case "Buttongrid": + ButtongridImpl buttongridWidget = (ButtongridImpl) SitemapFactory.eINSTANCE.createButtongrid(); + addWidgetButtons(buttongridWidget.getButtons(), component); + widget = buttongridWidget; + setWidgetPropertyFromComponentConfig(widget, component, "columns", SitemapPackage.BUTTONGRID__COLUMNS); + break; case "Default": DefaultImpl defaultWidget = (DefaultImpl) SitemapFactory.eINSTANCE.createDefault(); widget = defaultWidget; @@ -333,6 +343,29 @@ private void addWidgetMappings(EList mappings, UIComponent component) { } } + private void addWidgetButtons(EList