Search in sources :

Example 21 with Widget

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

the class SitemapResource method createWidgetBean.

private WidgetDTO createWidgetBean(String sitemapName, Widget widget, boolean drillDown, URI uri, String widgetId, Locale locale) {
    // Test visibility
    if (itemUIRegistry.getVisiblity(widget) == false) {
        return null;
    }
    WidgetDTO bean = new WidgetDTO();
    if (widget.getItem() != null) {
        try {
            Item item = itemUIRegistry.getItem(widget.getItem());
            String widgetTypeName = widget.eClass().getInstanceTypeName().substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
            boolean isMapview = "mapview".equalsIgnoreCase(widgetTypeName);
            Predicate<Item> itemFilter = (i -> i.getType().equals(CoreItemFactory.LOCATION));
            bean.item = EnrichedItemDTOMapper.map(item, isMapview, itemFilter, UriBuilder.fromUri(uri).build(), locale);
            bean.state = itemUIRegistry.getState(widget).toFullString();
            // In case the widget state is identical to the item state, its value is set to null.
            if (bean.state != null && bean.state.equals(bean.item.state)) {
                bean.state = null;
            }
        } catch (ItemNotFoundException e) {
            logger.debug("{}", e.getMessage());
        }
    }
    bean.widgetId = widgetId;
    bean.icon = itemUIRegistry.getCategory(widget);
    bean.labelcolor = itemUIRegistry.getLabelColor(widget);
    bean.valuecolor = itemUIRegistry.getValueColor(widget);
    bean.label = itemUIRegistry.getLabel(widget);
    bean.type = widget.eClass().getName();
    if (widget instanceof LinkableWidget) {
        LinkableWidget linkableWidget = (LinkableWidget) widget;
        EList<Widget> children = itemUIRegistry.getChildren(linkableWidget);
        if (widget instanceof Frame) {
            for (Widget child : children) {
                String wID = itemUIRegistry.getWidgetId(child);
                WidgetDTO subWidget = createWidgetBean(sitemapName, child, drillDown, uri, wID, locale);
                if (subWidget != null) {
                    bean.widgets.add(subWidget);
                }
            }
        } else if (children.size() > 0) {
            String pageName = itemUIRegistry.getWidgetId(linkableWidget);
            bean.linkedPage = createPageBean(sitemapName, itemUIRegistry.getLabel(widget), itemUIRegistry.getCategory(widget), pageName, drillDown ? children : null, drillDown, isLeaf(children), uri, locale, false);
        }
    }
    if (widget instanceof Switch) {
        Switch switchWidget = (Switch) widget;
        for (Mapping mapping : switchWidget.getMappings()) {
            MappingDTO mappingBean = new MappingDTO();
            mappingBean.command = mapping.getCmd();
            mappingBean.label = mapping.getLabel();
            bean.mappings.add(mappingBean);
        }
    }
    if (widget instanceof Selection) {
        Selection selectionWidget = (Selection) widget;
        for (Mapping mapping : selectionWidget.getMappings()) {
            MappingDTO mappingBean = new MappingDTO();
            mappingBean.command = mapping.getCmd();
            mappingBean.label = mapping.getLabel();
            bean.mappings.add(mappingBean);
        }
    }
    if (widget instanceof Slider) {
        Slider sliderWidget = (Slider) widget;
        bean.sendFrequency = sliderWidget.getFrequency();
        bean.switchSupport = sliderWidget.isSwitchEnabled();
    }
    if (widget instanceof List) {
        List listWidget = (List) widget;
        bean.separator = listWidget.getSeparator();
    }
    if (widget instanceof Image) {
        bean.url = buildProxyUrl(sitemapName, widget, uri);
        Image imageWidget = (Image) widget;
        if (imageWidget.getRefresh() > 0) {
            bean.refresh = imageWidget.getRefresh();
        }
    }
    if (widget instanceof Video) {
        Video videoWidget = (Video) widget;
        if (videoWidget.getEncoding() != null) {
            bean.encoding = videoWidget.getEncoding();
        }
        if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) {
            bean.url = videoWidget.getUrl();
        } else {
            bean.url = buildProxyUrl(sitemapName, videoWidget, uri);
        }
    }
    if (widget instanceof Webview) {
        Webview webViewWidget = (Webview) widget;
        bean.url = webViewWidget.getUrl();
        bean.height = webViewWidget.getHeight();
    }
    if (widget instanceof Mapview) {
        Mapview mapViewWidget = (Mapview) widget;
        bean.height = mapViewWidget.getHeight();
    }
    if (widget instanceof Chart) {
        Chart chartWidget = (Chart) widget;
        bean.service = chartWidget.getService();
        bean.period = chartWidget.getPeriod();
        bean.legend = chartWidget.getLegend();
        if (chartWidget.getRefresh() > 0) {
            bean.refresh = chartWidget.getRefresh();
        }
    }
    if (widget instanceof Setpoint) {
        Setpoint setpointWidget = (Setpoint) widget;
        bean.minValue = setpointWidget.getMinValue();
        bean.maxValue = setpointWidget.getMaxValue();
        bean.step = setpointWidget.getStep();
    }
    return bean;
}
Also used : Frame(org.eclipse.smarthome.model.sitemap.Frame) Slider(org.eclipse.smarthome.model.sitemap.Slider) Selection(org.eclipse.smarthome.model.sitemap.Selection) Mapview(org.eclipse.smarthome.model.sitemap.Mapview) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) Setpoint(org.eclipse.smarthome.model.sitemap.Setpoint) Mapping(org.eclipse.smarthome.model.sitemap.Mapping) Webview(org.eclipse.smarthome.model.sitemap.Webview) Image(org.eclipse.smarthome.model.sitemap.Image) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) Switch(org.eclipse.smarthome.model.sitemap.Switch) Video(org.eclipse.smarthome.model.sitemap.Video) List(org.eclipse.smarthome.model.sitemap.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) Chart(org.eclipse.smarthome.model.sitemap.Chart) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 22 with Widget

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

the class SitemapResource method blockUnlessChangeOccurs.

private boolean blockUnlessChangeOccurs(String sitemapname, String pageId) {
    boolean timeout = false;
    Sitemap sitemap = getSitemap(sitemapname);
    if (sitemap != null) {
        if (pageId.equals(sitemap.getName())) {
            EList<Widget> children = itemUIRegistry.getChildren(sitemap);
            timeout = waitForChanges(children);
        } else {
            Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
            if (pageWidget instanceof LinkableWidget) {
                EList<Widget> children = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
                timeout = waitForChanges(children);
            }
        }
    }
    return timeout;
}
Also used : LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) Sitemap(org.eclipse.smarthome.model.sitemap.Sitemap) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 23 with Widget

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

the class SitemapResource method createPageBean.

private PageDTO createPageBean(String sitemapName, String title, String icon, String pageId, EList<Widget> children, boolean drillDown, boolean isLeaf, URI uri, Locale locale, boolean timeout) {
    PageDTO bean = new PageDTO();
    bean.timeout = timeout;
    bean.id = pageId;
    bean.title = title;
    bean.icon = icon;
    bean.leaf = isLeaf;
    bean.link = UriBuilder.fromUri(uri).path(PATH_SITEMAPS).path(sitemapName).path(pageId).build().toASCIIString();
    if (children != null) {
        for (Widget widget : children) {
            String widgetId = itemUIRegistry.getWidgetId(widget);
            WidgetDTO subWidget = createWidgetBean(sitemapName, widget, drillDown, uri, widgetId, locale);
            if (subWidget != null) {
                bean.widgets.add(subWidget);
            }
        }
    } else {
        bean.widgets = null;
    }
    return bean;
}
Also used : Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 24 with Widget

use of org.eclipse.smarthome.model.sitemap.Widget 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

Widget (org.eclipse.smarthome.model.sitemap.Widget)24 LinkableWidget (org.eclipse.smarthome.model.sitemap.LinkableWidget)14 Sitemap (org.eclipse.smarthome.model.sitemap.Sitemap)9 Item (org.eclipse.smarthome.core.items.Item)8 BasicEList (org.eclipse.emf.common.util.BasicEList)6 Frame (org.eclipse.smarthome.model.sitemap.Frame)6 GenericItem (org.eclipse.smarthome.core.items.GenericItem)5 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)5 Test (org.junit.Test)5 EList (org.eclipse.emf.common.util.EList)4 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)4 EObject (org.eclipse.emf.ecore.EObject)3 GroupItem (org.eclipse.smarthome.core.items.GroupItem)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ServletException (javax.servlet.ServletException)2 CallItem (org.eclipse.smarthome.core.library.items.CallItem)2 ContactItem (org.eclipse.smarthome.core.library.items.ContactItem)2 DateTimeItem (org.eclipse.smarthome.core.library.items.DateTimeItem)2