Search in sources :

Example 6 with Frame

use of org.eclipse.smarthome.model.sitemap.Frame in project smarthome by eclipse.

the class PageChangeListener method constructSitemapEvents.

private Set<SitemapEvent> constructSitemapEvents(Item item, List<Widget> widgets) {
    Set<SitemapEvent> events = new HashSet<>();
    for (Widget w : widgets) {
        if (w instanceof Frame) {
            events.addAll(constructSitemapEvents(item, itemUIRegistry.getChildren((Frame) w)));
        }
        if ((w.getItem() != null && w.getItem().equals(item.getName())) || definesVisibility(w, item.getName())) {
            SitemapWidgetEvent event = new SitemapWidgetEvent();
            event.sitemapName = sitemapName;
            event.pageId = pageId;
            event.label = itemUIRegistry.getLabel(w);
            event.labelcolor = itemUIRegistry.getLabelColor(w);
            event.valuecolor = itemUIRegistry.getValueColor(w);
            event.widgetId = itemUIRegistry.getWidgetId(w);
            event.visibility = itemUIRegistry.getVisiblity(w);
            // event.item contains data from the item including its state (in event.item.state)
            String widgetTypeName = w.eClass().getInstanceTypeName().substring(w.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
            boolean drillDown = "mapview".equalsIgnoreCase(widgetTypeName);
            Predicate<Item> itemFilter = (i -> i.getType().equals(CoreItemFactory.LOCATION));
            event.item = EnrichedItemDTOMapper.map(item, drillDown, itemFilter, null, null);
            // event.state is an adjustment of the item state to the widget type.
            event.state = itemUIRegistry.getState(w).toFullString();
            // In case this state is identical to the item state, its value is set to null.
            if (event.state != null && event.state.equals(event.item.state)) {
                event.state = null;
            }
            events.add(event);
        }
    }
    return events;
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) Frame(org.eclipse.smarthome.model.sitemap.Frame) Widget(org.eclipse.smarthome.model.sitemap.Widget) HashSet(java.util.HashSet)

Aggregations

Frame (org.eclipse.smarthome.model.sitemap.Frame)6 Widget (org.eclipse.smarthome.model.sitemap.Widget)6 EObject (org.eclipse.emf.ecore.EObject)3 GenericItem (org.eclipse.smarthome.core.items.GenericItem)3 Item (org.eclipse.smarthome.core.items.Item)3 LinkableWidget (org.eclipse.smarthome.model.sitemap.LinkableWidget)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EList (org.eclipse.emf.common.util.EList)2 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)2 Sitemap (org.eclipse.smarthome.model.sitemap.Sitemap)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 GroupItem (org.eclipse.smarthome.core.items.GroupItem)1 Chart (org.eclipse.smarthome.model.sitemap.Chart)1 Image (org.eclipse.smarthome.model.sitemap.Image)1 List (org.eclipse.smarthome.model.sitemap.List)1 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)1 Mapview (org.eclipse.smarthome.model.sitemap.Mapview)1