Skip to content

Commit

Permalink
[Sitemap] Accept an optional icon for each value/label mapping (#3809)
Browse files Browse the repository at this point in the history
* [Sitemap] Accept an optional icon for each value/label mapping

When set by the user, the icon can be used by UIs for switch element with mappings to render a button with the icon rather than the label.

Related to #3441

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Oct 2, 2023
1 parent fffa968 commit f7d1765
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
* @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
* @author Laurent Garnier - Added icon field for mappings used for switch element
*/
@Component(service = { RESTResource.class, EventSubscriber.class })
@JaxrsResource
Expand Down Expand Up @@ -558,6 +559,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.label = mapping.getLabel();
mappingBean.icon = mapping.getIcon();
bean.mappings.add(mappingBean);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Button:
position=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;

Mapping:
cmd=Command '=' label=(ID | STRING);
cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;

VisibilityRule:
(item=ID) (condition=('==' | '>' | '<' | '>=' | '<=' | '!=')) (sign=('-' | '+'))? (state=XState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
* @author Yannick Schaus - Initial contribution
* @author Laurent Garnier - icon color support for all widgets
* @author Laurent Garnier - Added support for new element Buttongrid
* @author Laurent Garnier - Added icon field for mappings
*/
@NonNullByDefault
@Component(service = SitemapProvider.class)
Expand Down Expand Up @@ -331,11 +332,14 @@ private void addWidgetMappings(EList<Mapping> mappings, UIComponent component) {
if (component.getConfig().get("mappings") instanceof Collection<?>) {
for (Object sourceMapping : (Collection<?>) component.getConfig().get("mappings")) {
if (sourceMapping instanceof String) {
String cmd = sourceMapping.toString().split("=")[0].trim();
String label = sourceMapping.toString().split("=")[1].trim();
String[] splitMapping = sourceMapping.toString().split("=");
String cmd = splitMapping[0].trim();
String label = splitMapping[1].trim();
String icon = splitMapping.length < 3 ? null : splitMapping[2].trim();
MappingImpl mapping = (MappingImpl) SitemapFactory.eINSTANCE.createMapping();
mapping.setCmd(cmd);
mapping.setLabel(label);
mapping.setIcon(icon);
mappings.add(mapping);
}
}
Expand Down

0 comments on commit f7d1765

Please sign in to comment.