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