Skip to content

Commit

Permalink
[Sitemap] Change syntax for Buttongrid sitemap element (#3898)
Browse files Browse the repository at this point in the history
Follow-up #3810

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

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Dec 5, 2023
1 parent cc9b705 commit 76b10ac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*
* @author Kai Kreuzer - Initial contribution
* @author Laurent Garnier - New fields position and icon
* @author Laurent Garnier - Replace field position by fields row and column
*/
public class MappingDTO {

public Integer position;
public Integer row;
public Integer column;
public String command;
public String label;
public String icon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,10 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
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.row = button.getRow();
mappingBean.column = button.getColumn();
mappingBean.command = button.getCmd();
mappingBean.label = button.getLabel();
mappingBean.icon = button.getIcon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Mark herwege - New fields pattern, unit
* @author Laurent Garnier - New field columns
* @author Danny Baumann - New field labelSource
* @author Laurent Garnier - Remove field columns
*/
public class WidgetDTO {

Expand Down Expand Up @@ -68,7 +69,6 @@ public class WidgetDTO {
public String yAxisDecimalPattern;
public Boolean legend;
public Boolean forceAsItem;
public Integer columns;
public String state;

public EnrichedItemDTO item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ Buttongrid:
(('icon=' icon=Icon) |
('icon=[' (IconRules+=IconRule (',' IconRules+=IconRule)*) ']') |
('staticIcon=' staticIcon=Icon))? &
('columns=' columns=INT) &
('buttons=[' buttons+=Button (',' buttons+=Button)* ']') &
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
Expand All @@ -201,7 +200,7 @@ Default:
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);

Button:
position=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
row=INT ':' column=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;

Mapping:
cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) {
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();
Expand Down Expand Up @@ -378,13 +377,16 @@ private void addWidgetButtons(EList<Button> buttons, UIComponent component) {
for (Object sourceButton : (Collection<?>) sourceButtons) {
if (sourceButton instanceof String) {
String[] splitted1 = sourceButton.toString().split(":");
int idx = Integer.parseInt(splitted1[0].trim());
String[] splitted2 = splitted1[1].trim().split("=");
String cmd = splitted2[0].trim();
String label = splitted2[1].trim();
String icon = splitted2.length < 3 ? null : splitted2[2].trim();
String[] splitted2 = splitted1[0].split(",");
int row = Integer.parseInt(splitted2[0].trim());
int column = Integer.parseInt(splitted2[1].trim());
String[] splitted3 = splitted1[1].trim().split("=");
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();
button.setPosition(idx);
button.setRow(row);
button.setColumn(column);
button.setCmd(cmd);
button.setLabel(label);
button.setIcon(icon);
Expand Down

0 comments on commit 76b10ac

Please sign in to comment.