[Sitemap] Change syntax for Buttongrid sitemap element ()

Follow-up 

Location in the grid is now defined by a row number and a column number.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
pull/3899/head
lolodomo 2023-12-05 21:50:58 +01:00 committed by GitHub
parent cc9b70516a
commit 76b10ac1c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 13 deletions
bundles
org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal
org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap
org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components

View File

@ -17,10 +17,12 @@ package org.openhab.core.io.rest.sitemap.internal;
* *
* @author Kai Kreuzer - Initial contribution * @author Kai Kreuzer - Initial contribution
* @author Laurent Garnier - New fields position and icon * @author Laurent Garnier - New fields position and icon
* @author Laurent Garnier - Replace field position by fields row and column
*/ */
public class MappingDTO { public class MappingDTO {
public Integer position; public Integer row;
public Integer column;
public String command; public String command;
public String label; public String label;
public String icon; public String icon;

View File

@ -625,10 +625,10 @@ public class SitemapResource
bean.step = setpointWidget.getStep(); bean.step = setpointWidget.getStep();
} }
if (widget instanceof Buttongrid buttonGridWidget) { if (widget instanceof Buttongrid buttonGridWidget) {
bean.columns = buttonGridWidget.getColumns();
for (Button button : buttonGridWidget.getButtons()) { for (Button button : buttonGridWidget.getButtons()) {
MappingDTO mappingBean = new MappingDTO(); MappingDTO mappingBean = new MappingDTO();
mappingBean.position = button.getPosition(); mappingBean.row = button.getRow();
mappingBean.column = button.getColumn();
mappingBean.command = button.getCmd(); mappingBean.command = button.getCmd();
mappingBean.label = button.getLabel(); mappingBean.label = button.getLabel();
mappingBean.icon = button.getIcon(); mappingBean.icon = button.getIcon();

View File

@ -27,6 +27,7 @@ import org.openhab.core.io.rest.core.item.EnrichedItemDTO;
* @author Mark herwege - New fields pattern, unit * @author Mark herwege - New fields pattern, unit
* @author Laurent Garnier - New field columns * @author Laurent Garnier - New field columns
* @author Danny Baumann - New field labelSource * @author Danny Baumann - New field labelSource
* @author Laurent Garnier - Remove field columns
*/ */
public class WidgetDTO { public class WidgetDTO {
@ -68,7 +69,6 @@ public class WidgetDTO {
public String yAxisDecimalPattern; public String yAxisDecimalPattern;
public Boolean legend; public Boolean legend;
public Boolean forceAsItem; public Boolean forceAsItem;
public Integer columns;
public String state; public String state;
public EnrichedItemDTO item; public EnrichedItemDTO item;

View File

@ -182,7 +182,6 @@ Buttongrid:
(('icon=' icon=Icon) | (('icon=' icon=Icon) |
('icon=[' (IconRules+=IconRule (',' IconRules+=IconRule)*) ']') | ('icon=[' (IconRules+=IconRule (',' IconRules+=IconRule)*) ']') |
('staticIcon=' staticIcon=Icon))? & ('staticIcon=' staticIcon=Icon))? &
('columns=' columns=INT) &
('buttons=[' buttons+=Button (',' buttons+=Button)* ']') & ('buttons=[' buttons+=Button (',' buttons+=Button)* ']') &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
@ -201,7 +200,7 @@ Default:
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?); ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
Button: Button:
position=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?; row=INT ':' column=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
Mapping: Mapping:
cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?; cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;

View File

@ -269,7 +269,6 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
ButtongridImpl buttongridWidget = (ButtongridImpl) SitemapFactory.eINSTANCE.createButtongrid(); ButtongridImpl buttongridWidget = (ButtongridImpl) SitemapFactory.eINSTANCE.createButtongrid();
addWidgetButtons(buttongridWidget.getButtons(), component); addWidgetButtons(buttongridWidget.getButtons(), component);
widget = buttongridWidget; widget = buttongridWidget;
setWidgetPropertyFromComponentConfig(widget, component, "columns", SitemapPackage.BUTTONGRID__COLUMNS);
break; break;
case "Default": case "Default":
DefaultImpl defaultWidget = (DefaultImpl) SitemapFactory.eINSTANCE.createDefault(); DefaultImpl defaultWidget = (DefaultImpl) SitemapFactory.eINSTANCE.createDefault();
@ -378,13 +377,16 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
for (Object sourceButton : (Collection<?>) sourceButtons) { for (Object sourceButton : (Collection<?>) sourceButtons) {
if (sourceButton instanceof String) { if (sourceButton instanceof String) {
String[] splitted1 = sourceButton.toString().split(":"); String[] splitted1 = sourceButton.toString().split(":");
int idx = Integer.parseInt(splitted1[0].trim()); String[] splitted2 = splitted1[0].split(",");
String[] splitted2 = splitted1[1].trim().split("="); int row = Integer.parseInt(splitted2[0].trim());
String cmd = splitted2[0].trim(); int column = Integer.parseInt(splitted2[1].trim());
String label = splitted2[1].trim(); String[] splitted3 = splitted1[1].trim().split("=");
String icon = splitted2.length < 3 ? null : splitted2[2].trim(); String cmd = splitted3[0].trim();
String label = splitted3[1].trim();
String icon = splitted3.length < 3 ? null : splitted3[2].trim();
ButtonImpl button = (ButtonImpl) SitemapFactory.eINSTANCE.createButton(); ButtonImpl button = (ButtonImpl) SitemapFactory.eINSTANCE.createButton();
button.setPosition(idx); button.setRow(row);
button.setColumn(column);
button.setCmd(cmd); button.setCmd(cmd);
button.setLabel(label); button.setLabel(label);
button.setIcon(icon); button.setIcon(icon);