Search in sources :

Example 1 with Widget

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);
    }
}
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 Widget

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;
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) Frame(org.eclipse.smarthome.model.sitemap.Frame) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) HashSet(java.util.HashSet) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 3 with Widget

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) VisibilityRule(org.eclipse.smarthome.model.sitemap.VisibilityRule) BasicEList(org.eclipse.emf.common.util.BasicEList) Widget(org.eclipse.smarthome.model.sitemap.Widget) ColorArray(org.eclipse.smarthome.model.sitemap.ColorArray)

Example 4 with Widget

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;
}
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 5 with Widget

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;
}
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)

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