From a373b6c65b35326b244a22a46573dfb4a407e437 Mon Sep 17 00:00:00 2001 From: Stefan Triller Date: Mon, 17 Jul 2017 16:47:52 +0200 Subject: [PATCH] Reload BasicUI if sitemap has been changed Signed-off-by: Stefan Triller --- .../sitemap/SitemapSubscriptionService.java | 6 +----- .../sitemap/internal/PageChangeListener.java | 9 +++++++-- .../sitemap/internal/SitemapChangedEvent.java | 18 ++++++++++++++++++ .../ui/internal/items/ItemUIRegistryImpl.java | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/SitemapChangedEvent.java diff --git a/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/SitemapSubscriptionService.java b/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/SitemapSubscriptionService.java index e8a9744621e..bf0effe930a 100644 --- a/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/SitemapSubscriptionService.java +++ b/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/SitemapSubscriptionService.java @@ -267,14 +267,10 @@ public void modelChanged(String modelName, EventType type) { for (Entry listenerEntry : pageChangeListeners.entrySet()) { String sitemapWithPage = listenerEntry.getKey(); String sitemapName = extractSitemapName(sitemapWithPage); - String pageId = extractPageId(sitemapWithPage); if (sitemapName.equals(changedSitemapName)) { - EList widgets = collectWidgets(sitemapName, pageId); - listenerEntry.getValue().sitemapContentChanged(widgets); + listenerEntry.getValue().sitemapContentChanged(); } } - } - } diff --git a/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java b/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java index 86e550ae1ab..361632847a0 100644 --- a/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java +++ b/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java @@ -213,8 +213,13 @@ private boolean definesVisibility(Widget w, String name) { return false; } - public void sitemapContentChanged(EList widgets) { - updateItemsAndWidgets(widgets); + public void sitemapContentChanged() { + for (SitemapSubscriptionCallback callback : distinctCallbacks) { + SitemapChangedEvent changeEvent = new SitemapChangedEvent(); + changeEvent.pageId = pageId; + changeEvent.sitemapName = sitemapName; + callback.onEvent(changeEvent); + } } } diff --git a/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/SitemapChangedEvent.java b/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/SitemapChangedEvent.java new file mode 100644 index 00000000000..dc75a697a22 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/SitemapChangedEvent.java @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2014-2017 by the respective copyright holders. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.rest.sitemap.internal; + +/** + * Event to notify the browser that the sitemap has been changed + * + * @author Stefan Triller - Initial Contribution + * + */ +public class SitemapChangedEvent extends SitemapEvent { + public final String TYPE = "SITEMAP_CHANGED"; +} diff --git a/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java b/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java index 3956ae716c3..257eb33dddf 100644 --- a/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java +++ b/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java @@ -515,7 +515,7 @@ public Widget getWidget(Sitemap sitemap, String id) { for (int i = 2; i < id.length(); i += 2) { w = ((LinkableWidget) w).getChildren().get(Integer.valueOf(id.substring(i, i + 2))); } - } catch (NumberFormatException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { // no valid number, so the requested page id does not exist } }