Search in sources :

Example 1 with LinkableWidget

use of org.eclipse.smarthome.model.sitemap.LinkableWidget 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);
    }
}
Also used : LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) Sitemap(org.eclipse.smarthome.model.sitemap.Sitemap) Frame(org.eclipse.smarthome.model.sitemap.Frame) WebApplicationException(javax.ws.rs.WebApplicationException) EObject(org.eclipse.emf.ecore.EObject) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 2 with LinkableWidget

use of org.eclipse.smarthome.model.sitemap.LinkableWidget 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;
}
Also used : LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) Sitemap(org.eclipse.smarthome.model.sitemap.Sitemap) BasicEList(org.eclipse.emf.common.util.BasicEList) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 3 with LinkableWidget

use of org.eclipse.smarthome.model.sitemap.LinkableWidget 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;
}
Also used : Group(org.eclipse.smarthome.model.sitemap.Group) BasicEList(org.eclipse.emf.common.util.BasicEList) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 4 with LinkableWidget

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

the class ItemUIRegistryImpl method getWidgetId.

@Override
public String getWidgetId(Widget widget) {
    Widget w2 = defaultWidgets.get(widget);
    if (w2 != null) {
        return getWidgetId(w2);
    }
    String id = "";
    Widget w = widget;
    while (w.eContainer() instanceof Widget) {
        Widget parent = (Widget) w.eContainer();
        String index = String.valueOf(((LinkableWidget) parent).getChildren().indexOf(w));
        if (index.length() == 1) {
            // make it two digits
            index = "0" + index;
        }
        id = index + id;
        w = parent;
    }
    if (w.eContainer() instanceof Sitemap) {
        Sitemap sitemap = (Sitemap) w.eContainer();
        String index = String.valueOf(sitemap.getChildren().indexOf(w));
        if (index.length() == 1) {
            // make it two digits
            index = "0" + index;
        }
        id = index + id;
    }
    // use the item name as the id
    if (w.eContainer() == null) {
        String itemName = w.getItem();
        id = itemName;
    }
    return id;
}
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 5 with LinkableWidget

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

the class WebAppServlet method service.

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    logger.debug("Servlet request received!");
    // read request parameters
    String sitemapName = req.getParameter("sitemap");
    String widgetId = req.getParameter("w");
    String subscriptionId = req.getParameter("subscriptionId");
    boolean async = "true".equalsIgnoreCase(req.getParameter("__async"));
    if (sitemapName == null) {
        sitemapName = config.getDefaultSitemap();
    }
    StringBuilder result = new StringBuilder();
    Sitemap sitemap = null;
    for (SitemapProvider sitemapProvider : sitemapProviders) {
        sitemap = sitemapProvider.getSitemap(sitemapName);
        if (sitemap != null) {
            break;
        }
    }
    try {
        if (sitemap == null) {
            showSitemapList(res);
            return;
        }
        logger.debug("reading sitemap {}", sitemap.getName());
        if (widgetId == null || widgetId.isEmpty() || widgetId.equals(sitemapName)) {
            // we are at the homepage, so we render the children of the sitemap root node
            if (subscriptionId != null) {
                if (subscriptions.exists(subscriptionId)) {
                    subscriptions.setPageId(subscriptionId, sitemap.getName(), sitemapName);
                } else {
                    logger.debug("Basic UI requested a non-existing event subscription id ({})", subscriptionId);
                }
            }
            String label = sitemap.getLabel() != null ? sitemap.getLabel() : sitemapName;
            EList<Widget> children = renderer.getItemUIRegistry().getChildren(sitemap);
            result.append(renderer.processPage(sitemapName, sitemapName, label, children, async));
        } else if (!widgetId.equals("Colorpicker")) {
            // we are on some subpage, so we have to render the children of the widget that has been selected
            if (subscriptionId != null) {
                if (subscriptions.exists(subscriptionId)) {
                    subscriptions.setPageId(subscriptionId, sitemap.getName(), widgetId);
                } else {
                    logger.debug("Basic UI requested a non-existing event subscription id ({})", subscriptionId);
                }
            }
            Widget w = renderer.getItemUIRegistry().getWidget(sitemap, widgetId);
            if (w != null) {
                String label = renderer.getItemUIRegistry().getLabel(w);
                if (label == null) {
                    label = "undefined";
                }
                if (!(w instanceof LinkableWidget)) {
                    throw new RenderException("Widget '" + w + "' can not have any content");
                }
                EList<Widget> children = renderer.getItemUIRegistry().getChildren((LinkableWidget) w);
                result.append(renderer.processPage(renderer.getItemUIRegistry().getWidgetId(w), sitemapName, label, children, async));
            }
        }
    } catch (RenderException e) {
        throw new ServletException(e.getMessage(), e);
    }
    if (async) {
        res.setContentType(CONTENT_TYPE_ASYNC);
    } else {
        res.setContentType(CONTENT_TYPE);
    }
    res.getWriter().append(result);
    res.getWriter().close();
}
Also used : LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) ServletException(javax.servlet.ServletException) Sitemap(org.eclipse.smarthome.model.sitemap.Sitemap) RenderException(org.eclipse.smarthome.ui.basic.render.RenderException) EList(org.eclipse.emf.common.util.EList) SitemapProvider(org.eclipse.smarthome.model.sitemap.SitemapProvider) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Aggregations

LinkableWidget (org.eclipse.smarthome.model.sitemap.LinkableWidget)8 Widget (org.eclipse.smarthome.model.sitemap.Widget)8 Sitemap (org.eclipse.smarthome.model.sitemap.Sitemap)6 BasicEList (org.eclipse.emf.common.util.BasicEList)3 EList (org.eclipse.emf.common.util.EList)3 ServletException (javax.servlet.ServletException)2 Frame (org.eclipse.smarthome.model.sitemap.Frame)2 SitemapProvider (org.eclipse.smarthome.model.sitemap.SitemapProvider)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 EObject (org.eclipse.emf.ecore.EObject)1 GenericItem (org.eclipse.smarthome.core.items.GenericItem)1 Item (org.eclipse.smarthome.core.items.Item)1 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)1 Chart (org.eclipse.smarthome.model.sitemap.Chart)1 Group (org.eclipse.smarthome.model.sitemap.Group)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