Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
introduced "Default" widget type for sitemaps that is dynamically res…
Browse files Browse the repository at this point in the history
…olved

Signed-off-by: Kai Kreuzer <[email protected]>
  • Loading branch information
kaikreuzer committed May 18, 2016
1 parent f61cf44 commit dbe8c54
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions bundles/ui/org.eclipse.smarthome.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -501,11 +507,39 @@ public Widget getWidget(Sitemap sitemap, String id) {
*/
@Override
public EList<Widget> getChildren(LinkableWidget w) {
EList<Widget> 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<Widget> result = new BasicEList<Widget>();
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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippet = processColor(w, snippet);

sb.append(snippet);
return ((Frame) w).getChildren();
return itemUIRegistry.getChildren((Frame) w);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippet = processColor(w, snippet);

sb.append(snippet);
return ((Frame) w).getChildren();
return itemUIRegistry.getChildren((Frame) w);
}
}

0 comments on commit dbe8c54

Please sign in to comment.