use of org.eclipse.smarthome.model.sitemap.Widget in project smarthome by eclipse.
the class SitemapResource method getPageBean.
private PageDTO getPageBean(String sitemapName, String pageId, URI uri, Locale locale, boolean timeout) {
Sitemap sitemap = getSitemap(sitemapName);
if (sitemap != null) {
if (pageId.equals(sitemap.getName())) {
EList<Widget> children = itemUIRegistry.getChildren(sitemap);
return createPageBean(sitemapName, sitemap.getLabel(), sitemap.getIcon(), sitemap.getName(), children, false, isLeaf(children), uri, locale, timeout);
} else {
Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
if (pageWidget instanceof LinkableWidget) {
EList<Widget> children = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
PageDTO pageBean = createPageBean(sitemapName, itemUIRegistry.getLabel(pageWidget), itemUIRegistry.getCategory(pageWidget), pageId, children, false, isLeaf(children), uri, locale, timeout);
EObject parentPage = pageWidget.eContainer();
while (parentPage instanceof Frame) {
parentPage = parentPage.eContainer();
}
if (parentPage instanceof Widget) {
String parentId = itemUIRegistry.getWidgetId((Widget) parentPage);
pageBean.parent = getPageBean(sitemapName, parentId, uri, locale, timeout);
pageBean.parent.widgets = null;
pageBean.parent.parent = null;
} else if (parentPage instanceof Sitemap) {
pageBean.parent = getPageBean(sitemapName, sitemap.getName(), uri, locale, timeout);
pageBean.parent.widgets = null;
}
return pageBean;
} else {
if (logger.isDebugEnabled()) {
if (pageWidget == null) {
logger.debug("Received HTTP GET request at '{}' for the unknown page id '{}'.", uri, pageId);
} else {
logger.debug("Received HTTP GET request at '{}' for the page id '{}'. " + "This id refers to a non-linkable widget and is therefore no valid page id.", uri, pageId);
}
}
throw new WebApplicationException(404);
}
}
} else {
logger.info("Received HTTP GET request at '{}' for the unknown sitemap '{}'.", uri, sitemapName);
throw new WebApplicationException(404);
}
}
use of org.eclipse.smarthome.model.sitemap.Widget in project smarthome by eclipse.
the class SitemapResource method getAllItems.
/**
* Collects all items that are represented by a given list of widgets
*
* @param widgets
* the widget list to get the items for added to all bundles containing REST resources
* @return all items that are represented by the list of widgets
*/
private Set<GenericItem> getAllItems(EList<Widget> widgets) {
Set<GenericItem> items = new HashSet<GenericItem>();
if (itemUIRegistry != null) {
for (Widget widget : widgets) {
String itemName = widget.getItem();
if (itemName != null) {
try {
Item item = itemUIRegistry.getItem(itemName);
if (item instanceof GenericItem) {
items.add((GenericItem) item);
}
} catch (ItemNotFoundException e) {
// ignore
}
}
// Consider all items inside the frame
if (widget instanceof Frame) {
items.addAll(getAllItems(((Frame) widget).getChildren()));
}
// Consider items involved in any visibility, labelcolor and valuecolor condition
items.addAll(getItemsInVisibilityCond(widget.getVisibility()));
items.addAll(getItemsInColorCond(widget.getLabelColor()));
items.addAll(getItemsInColorCond(widget.getValueColor()));
}
}
return items;
}
use of org.eclipse.smarthome.model.sitemap.Widget in project smarthome by eclipse.
the class SitemapResourceTest method initSitemapWidgets.
private EList<Widget> initSitemapWidgets() {
// Initialize a sitemap containing 2 widgets linked to the same number item,
// one slider and one switch
Widget w1 = mock(Widget.class);
EClass sliderEClass = mock(EClass.class);
when(sliderEClass.getName()).thenReturn("slider");
when(sliderEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Slider");
when(w1.eClass()).thenReturn(sliderEClass);
when(w1.getLabel()).thenReturn(WIDGET1_LABEL);
when(w1.getItem()).thenReturn(ITEM_NAME);
// add visibility rules to the mock widget:
VisibilityRule visibilityRule = mock(VisibilityRule.class);
when(visibilityRule.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
BasicEList<VisibilityRule> visibilityRules = new BasicEList<>(1);
visibilityRules.add(visibilityRule);
when(w1.getVisibility()).thenReturn(visibilityRules);
// add label color conditions to the item:
ColorArray labelColor = mock(ColorArray.class);
when(labelColor.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
EList<ColorArray> labelColors = new BasicEList<>();
labelColors.add(labelColor);
when(w1.getLabelColor()).thenReturn(labelColors);
// add value color conditions to the item:
ColorArray valueColor = mock(ColorArray.class);
when(valueColor.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
EList<ColorArray> valueColors = new BasicEList<>();
valueColors.add(valueColor);
when(w1.getValueColor()).thenReturn(valueColors);
visibilityRules = new BasicEList<>();
labelColors = new BasicEList<>();
valueColors = new BasicEList<>();
Widget w2 = mock(Widget.class);
EClass switchEClass = mock(EClass.class);
when(switchEClass.getName()).thenReturn("switch");
when(switchEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Switch");
when(w2.eClass()).thenReturn(switchEClass);
when(w2.getLabel()).thenReturn(WIDGET2_LABEL);
when(w2.getItem()).thenReturn(ITEM_NAME);
when(w2.getVisibility()).thenReturn(visibilityRules);
when(w2.getLabelColor()).thenReturn(labelColors);
when(w2.getValueColor()).thenReturn(valueColors);
BasicEList<Widget> widgets = new BasicEList<>(2);
widgets.add(w1);
widgets.add(w2);
return widgets;
}
use of org.eclipse.smarthome.model.sitemap.Widget in project smarthome by eclipse.
the class SitemapSubscriptionService method collectWidgets.
private EList<Widget> collectWidgets(String sitemapName, String pageId) {
EList<Widget> widgets = new BasicEList<Widget>();
Sitemap sitemap = getSitemap(sitemapName);
if (sitemap != null) {
if (pageId.equals(sitemap.getName())) {
widgets = itemUIRegistry.getChildren(sitemap);
} else {
Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
if (pageWidget instanceof LinkableWidget) {
widgets = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
// We add the page widget. It will help any UI to update the page title.
widgets.add(pageWidget);
}
}
}
return widgets;
}
use of org.eclipse.smarthome.model.sitemap.Widget in project smarthome by eclipse.
the class ItemUIRegistryImpl method getChildren.
@Override
public EList<Widget> getChildren(LinkableWidget w) {
EList<Widget> widgets = null;
if (w instanceof Group && w.getChildren().isEmpty()) {
widgets = getDynamicGroupChildren((Group) w);
} else {
widgets = w.getChildren();
}
EList<Widget> result = new BasicEList<Widget>();
for (Widget widget : widgets) {
Widget resolvedWidget = resolveDefault(widget);
if (resolvedWidget != null) {
result.add(resolvedWidget);
}
}
return result;
}
Aggregations