diff --git a/bundles/model/org.eclipse.smarthome.model.sitemap/src/org/eclipse/smarthome/model/Sitemap.xtext b/bundles/model/org.eclipse.smarthome.model.sitemap/src/org/eclipse/smarthome/model/Sitemap.xtext index 99ad3736d44..95c526ab80c 100644 --- a/bundles/model/org.eclipse.smarthome.model.sitemap/src/org/eclipse/smarthome/model/Sitemap.xtext +++ b/bundles/model/org.eclipse.smarthome.model.sitemap/src/org/eclipse/smarthome/model/Sitemap.xtext @@ -15,7 +15,7 @@ Widget: (LinkableWidget | NonLinkableWidget); NonLinkableWidget: - Switch | Selection | Slider | List | Setpoint | Video | Chart | Webview | Colorpicker | Mapview; + Switch | Selection | Slider | List | Setpoint | Video | Chart | Webview | Colorpicker | Mapview | Default; LinkableWidget: (Text | Group | Image | Frame) @@ -116,6 +116,13 @@ Colorpicker: ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); +Default: + 'Default' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + ('height=' height=INT)? & + ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & + ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & + ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); + Mapping: cmd=Command '=' label=(ID | STRING); diff --git a/bundles/ui/org.eclipse.smarthome.ui/META-INF/MANIFEST.MF b/bundles/ui/org.eclipse.smarthome.ui/META-INF/MANIFEST.MF index 0aa8b69d78c..5c9545f6344 100644 --- a/bundles/ui/org.eclipse.smarthome.ui/META-INF/MANIFEST.MF +++ b/bundles/ui/org.eclipse.smarthome.ui/META-INF/MANIFEST.MF @@ -29,6 +29,7 @@ Import-Package: javax.imageio, org.eclipse.smarthome.model.core, org.eclipse.smarthome.model.items, org.eclipse.smarthome.model.sitemap, + org.eclipse.smarthome.model.sitemap.impl, org.osgi.framework, org.osgi.service.cm, org.osgi.service.http, diff --git a/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java b/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java index be70b5c2672..985807187e6 100644 --- a/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java +++ b/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java @@ -47,6 +47,7 @@ import org.eclipse.smarthome.core.types.Type; import org.eclipse.smarthome.core.types.UnDefType; import org.eclipse.smarthome.model.sitemap.ColorArray; +import org.eclipse.smarthome.model.sitemap.Default; import org.eclipse.smarthome.model.sitemap.Group; import org.eclipse.smarthome.model.sitemap.LinkableWidget; import org.eclipse.smarthome.model.sitemap.Mapping; @@ -173,6 +174,9 @@ public Widget getWidget(String itemName) { for (ItemUIProvider provider : itemUIProviders) { Widget currentWidget = provider.getWidget(itemName); if (currentWidget != null) { + if (currentWidget instanceof Default) { + currentWidget = resolveDefault(currentWidget); + } return currentWidget; } } @@ -479,18 +483,20 @@ public Widget getWidget(Sitemap sitemap, String id) { } if (w != null) { w.setItem(id); - return w; } else { try { w = sitemap.getChildren().get(Integer.valueOf(id.substring(0, 2))); for (int i = 2; i < id.length(); i += 2) { w = ((LinkableWidget) w).getChildren().get(Integer.valueOf(id.substring(i, i + 2))); } - return w; } catch (NumberFormatException e) { // no valid number, so the requested page id does not exist } } + if (w instanceof Default) { + w = resolveDefault(w); + } + return w; } logger.warn("Cannot find page for id '{}'.", id); return null; @@ -501,11 +507,39 @@ public Widget getWidget(Sitemap sitemap, String id) { */ @Override public EList getChildren(LinkableWidget w) { + EList widgets = null; if (w instanceof Group && w.getChildren().isEmpty()) { - return getDynamicGroupChildren((Group) w); + widgets = getDynamicGroupChildren((Group) w); } else { - return w.getChildren(); + widgets = w.getChildren(); } + + EList result = new BasicEList(); + for (Widget widget : widgets) { + Widget resolvedWidget = resolveDefault(widget); + if (resolvedWidget != null) { + result.add(resolvedWidget); + } else { + result.add(widget); + } + } + return result; + } + + private Widget resolveDefault(Widget widget) { + if (widget instanceof Default) { + if (widget.getItem() != null) { + Item item = itemRegistry.get(widget.getItem()); + if (item != null) { + Widget defaultWidget = getDefaultWidget(item.getClass(), item.getName()); + if (defaultWidget != null) { + defaultWidget.setItem(item.getName()); + return defaultWidget; + } + } + } + } + return null; } /** diff --git a/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/FrameRenderer.java b/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/FrameRenderer.java index ab5ef722e0c..b699de19688 100644 --- a/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/FrameRenderer.java +++ b/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/FrameRenderer.java @@ -53,6 +53,6 @@ public EList renderWidget(Widget w, StringBuilder sb) throws RenderExcep snippet = processColor(w, snippet); sb.append(snippet); - return ((Frame) w).getChildren(); + return itemUIRegistry.getChildren((Frame) w); } } diff --git a/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/PageRenderer.java b/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/PageRenderer.java index f59ba0fc8aa..fd3dc916499 100644 --- a/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/PageRenderer.java +++ b/extensions/ui/org.eclipse.smarthome.ui.basic/src/main/java/org/eclipse/smarthome/ui/basic/internal/render/PageRenderer.java @@ -105,7 +105,7 @@ private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList< EObject firstChild = children.get(0); EObject parent = firstChild.eContainer(); if (!(firstChild instanceof Frame || parent instanceof Frame || parent instanceof Sitemap - || parent instanceof List)) { + || parent instanceof org.eclipse.smarthome.model.sitemap.List)) { String frameSnippet = getSnippet("frame"); frameSnippet = StringUtils.replace(frameSnippet, "%label%", ""); frameSnippet = StringUtils.replace(frameSnippet, "%frame_class%", "mdl-form--no-label"); diff --git a/extensions/ui/org.eclipse.smarthome.ui.classic/src/main/java/org/eclipse/smarthome/ui/classic/internal/render/FrameRenderer.java b/extensions/ui/org.eclipse.smarthome.ui.classic/src/main/java/org/eclipse/smarthome/ui/classic/internal/render/FrameRenderer.java index 62033aabcbf..201de27c58e 100644 --- a/extensions/ui/org.eclipse.smarthome.ui.classic/src/main/java/org/eclipse/smarthome/ui/classic/internal/render/FrameRenderer.java +++ b/extensions/ui/org.eclipse.smarthome.ui.classic/src/main/java/org/eclipse/smarthome/ui/classic/internal/render/FrameRenderer.java @@ -45,6 +45,6 @@ public EList renderWidget(Widget w, StringBuilder sb) throws RenderExcep snippet = processColor(w, snippet); sb.append(snippet); - return ((Frame) w).getChildren(); + return itemUIRegistry.getChildren((Frame) w); } }