Search in sources :

Example 41 with ItemNotFoundException

use of org.eclipse.smarthome.core.items.ItemNotFoundException in project smarthome by eclipse.

the class ChartRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Chart chart = (Chart) w;
    try {
        String itemParam = null;
        Item item = itemUIRegistry.getItem(chart.getItem());
        if (item instanceof GroupItem) {
            itemParam = "groups=" + chart.getItem();
        } else {
            itemParam = "items=" + chart.getItem();
        }
        String chartUrl = "/chart?" + itemParam + "&period=" + chart.getPeriod();
        if (chart.getService() != null) {
            chartUrl += "&service=" + chart.getService();
        }
        // if legend parameter is given, add corresponding GET parameter
        if (chart.getLegend() != null) {
            if (chart.getLegend()) {
                chartUrl += "&legend=true";
            } else {
                chartUrl += "&legend=false";
            }
        }
        // add theme GET parameter
        String chartTheme = null;
        switch(config.getTheme()) {
            case WebAppConfig.THEME_NAME_DEFAULT:
                chartTheme = "bright";
                break;
            case WebAppConfig.THEME_NAME_DARK:
                chartTheme = "dark";
                break;
        }
        if (chartTheme != null) {
            chartUrl += "&theme=" + chartTheme;
        }
        String url;
        boolean ignoreRefresh;
        if (!itemUIRegistry.getVisiblity(w)) {
            url = URL_NONE_ICON;
            ignoreRefresh = true;
        } else {
            // add timestamp to circumvent browser cache
            url = chartUrl + "&t=" + (new Date()).getTime();
            ignoreRefresh = false;
        }
        String snippet = getSnippet("chart");
        snippet = preprocessSnippet(snippet, w);
        if (chart.getRefresh() > 0) {
            snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(chart.getRefresh()));
        } else {
            snippet = StringUtils.replace(snippet, "%update_interval%", "0");
        }
        snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
        snippet = StringUtils.replace(snippet, "%proxied_url%", chartUrl);
        snippet = StringUtils.replace(snippet, "%valid_url%", "true");
        snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false");
        snippet = StringUtils.replace(snippet, "%url%", url);
        sb.append(snippet);
    } catch (ItemNotFoundException e) {
        logger.warn("Chart cannot be rendered as item '{}' does not exist.", chart.getItem());
    }
    return null;
}
Also used : Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) Chart(org.eclipse.smarthome.model.sitemap.Chart) Date(java.util.Date) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Aggregations

ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)41 Item (org.eclipse.smarthome.core.items.Item)36 GroupItem (org.eclipse.smarthome.core.items.GroupItem)22 GenericItem (org.eclipse.smarthome.core.items.GenericItem)17 State (org.eclipse.smarthome.core.types.State)15 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)8 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)8 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)8 Command (org.eclipse.smarthome.core.types.Command)7 ItemNotUniqueException (org.eclipse.smarthome.core.items.ItemNotUniqueException)5 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)5 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)5 Date (java.util.Date)4 CallItem (org.eclipse.smarthome.core.library.items.CallItem)4 DateTimeItem (org.eclipse.smarthome.core.library.items.DateTimeItem)4 StringItem (org.eclipse.smarthome.core.library.items.StringItem)4 Widget (org.eclipse.smarthome.model.sitemap.Widget)4 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)3 ContactItem (org.eclipse.smarthome.core.library.items.ContactItem)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3