mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
Support press and release buttons in sitemap generator (#4204)
* handle quoted arguments * press and release mapping Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
parent
b40e6db514
commit
d083a5379c
@ -99,6 +99,7 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
||||
|
||||
private static final Pattern CONDITION_PATTERN = Pattern
|
||||
.compile("(?<item>[A-Za-z]\\w*)?\\s*(?<condition>==|!=|<=|>=|<|>)?\\s*(?<sign>\\+|-)?(?<state>.+)");
|
||||
private static final Pattern COMMANDS_PATTERN = Pattern.compile("^(?<cmd1>\"[^\"]*\"|[^\": ]*):(?<cmd2>.*)$");
|
||||
|
||||
private Map<String, Sitemap> sitemaps = new HashMap<>();
|
||||
private @Nullable UIComponentRegistryFactory componentRegistryFactory;
|
||||
@ -352,6 +353,15 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
||||
setWidgetPropertyFromComponentConfig(widget, component, "icon", SitemapPackage.WIDGET__ICON);
|
||||
}
|
||||
|
||||
private @Nullable String stripQuotes(@Nullable String input) {
|
||||
if ((input != null) && (input.length() >= 2) && (input.charAt(0) == '\"')
|
||||
&& (input.charAt(input.length() - 1) == '\"')) {
|
||||
return input.substring(1, input.length() - 1);
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
private void addWidgetMappings(EList<Mapping> mappings, UIComponent component) {
|
||||
if (component.getConfig() != null && component.getConfig().containsKey("mappings")) {
|
||||
Object sourceMappings = component.getConfig().get("mappings");
|
||||
@ -360,10 +370,19 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
||||
if (sourceMapping instanceof String) {
|
||||
String[] splitMapping = sourceMapping.toString().split("=");
|
||||
String cmd = splitMapping[0].trim();
|
||||
String label = splitMapping[1].trim();
|
||||
String icon = splitMapping.length < 3 ? null : splitMapping[2].trim();
|
||||
String releaseCmd = null;
|
||||
Matcher matcher = COMMANDS_PATTERN.matcher(cmd);
|
||||
if (matcher.matches()) {
|
||||
cmd = matcher.group("cmd1");
|
||||
releaseCmd = matcher.group("cmd2");
|
||||
}
|
||||
cmd = stripQuotes(cmd);
|
||||
releaseCmd = stripQuotes(releaseCmd);
|
||||
String label = stripQuotes(splitMapping[1].trim());
|
||||
String icon = splitMapping.length < 3 ? null : stripQuotes(splitMapping[2].trim());
|
||||
MappingImpl mapping = (MappingImpl) SitemapFactory.eINSTANCE.createMapping();
|
||||
mapping.setCmd(cmd);
|
||||
mapping.setReleaseCmd(releaseCmd);
|
||||
mapping.setLabel(label);
|
||||
mapping.setIcon(icon);
|
||||
mappings.add(mapping);
|
||||
@ -383,9 +402,9 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
||||
int row = Integer.parseInt(splitted1[0].trim());
|
||||
int column = Integer.parseInt(splitted1[1].trim());
|
||||
String[] splitted2 = splitted1[2].trim().split("=");
|
||||
String cmd = splitted2[0].trim();
|
||||
String label = splitted2[1].trim();
|
||||
String icon = splitted2.length < 3 ? null : splitted2[2].trim();
|
||||
String cmd = stripQuotes(splitted2[0].trim());
|
||||
String label = stripQuotes(splitted2[1].trim());
|
||||
String icon = splitted2.length < 3 ? null : stripQuotes(splitted2[2].trim());
|
||||
ButtonImpl button = (ButtonImpl) SitemapFactory.eINSTANCE.createButton();
|
||||
button.setRow(row);
|
||||
button.setColumn(column);
|
||||
@ -476,7 +495,7 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
||||
condition.setItem(matcher.group("item"));
|
||||
condition.setCondition(matcher.group("condition"));
|
||||
condition.setSign(matcher.group("sign"));
|
||||
condition.setState(matcher.group("state"));
|
||||
condition.setState(stripQuotes(matcher.group("state")));
|
||||
conditions.add(condition);
|
||||
} else {
|
||||
logger.warn("Syntax error in {} rule condition '{}' for widget {}", key, conditionString,
|
||||
@ -488,7 +507,8 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
||||
|
||||
private String getRuleArgument(String rule) {
|
||||
int argIndex = rule.lastIndexOf("=") + 1;
|
||||
return rule.substring(argIndex).trim();
|
||||
String strippedRule = stripQuotes(rule.substring(argIndex).trim());
|
||||
return strippedRule != null ? strippedRule : "";
|
||||
}
|
||||
|
||||
private List<String> getRuleConditions(String rule, @Nullable String argument) {
|
||||
|
Loading…
Reference in New Issue
Block a user