diff --git a/bundles/core/org.openhab.core/META-INF/MANIFEST.MF b/bundles/core/org.openhab.core/META-INF/MANIFEST.MF
index b3a95abf78514..4c713086c27cc 100644
--- a/bundles/core/org.openhab.core/META-INF/MANIFEST.MF
+++ b/bundles/core/org.openhab.core/META-INF/MANIFEST.MF
@@ -1,6 +1,5 @@
Manifest-Version: 1.0
-Service-Component: OSGI-INF/autoapprove.xml,OSGI-INF/thingitemprovider.xml,
- OSGI-INF/thinglinkprovider.xml,OSGI-INF/defaultsitemapprovider.xml
+Service-Component: OSGI-INF/*.xml
Private-Package: org.openhab.core.internal,org.openhab.core.internal.e
vents,org.openhab.core.internal.items
Ignore-Package: org.openhab.core.internal.items,org.openhab.core.inter
diff --git a/bundles/core/org.openhab.core/OSGI-INF/thingitemprovider.xml b/bundles/core/org.openhab.core/OSGI-INF/thingitemprovider.xml
index 51166816353b1..f44867c8854f0 100644
--- a/bundles/core/org.openhab.core/OSGI-INF/thingitemprovider.xml
+++ b/bundles/core/org.openhab.core/OSGI-INF/thingitemprovider.xml
@@ -10,14 +10,10 @@
-->
-
-
-
+
-
-
-
+
diff --git a/bundles/core/org.openhab.core/OSGI-INF/thinglinkprovider.xml b/bundles/core/org.openhab.core/OSGI-INF/thinglinkprovider.xml
deleted file mode 100644
index 760e47d89173c..0000000000000
--- a/bundles/core/org.openhab.core/OSGI-INF/thinglinkprovider.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/DefaultSitemapProvider.java b/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/DefaultSitemapProvider.java
index 1b73e98f5a7fc..e4bd3fc29f7a4 100644
--- a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/DefaultSitemapProvider.java
+++ b/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/DefaultSitemapProvider.java
@@ -48,14 +48,13 @@ public Sitemap getSitemap(String sitemapName) {
sitemap.getChildren().add(frame);
for(Item item : itemRegistry.getAll()) {
- if(item instanceof GroupItem && !item.getName().equals("Things")
- && (item.getGroupNames().isEmpty() || item.getGroupNames().contains("Things"))) {
+ if(item instanceof GroupItem && !item.getTags().contains("home-group")) {
GroupImpl group = (GroupImpl) SitemapFactory.eINSTANCE.createGroup();
group.setItem(item.getName());
+ group.setLabel(item.getLabel());
frame.getChildren().add(group);
}
}
-
return sitemap;
}
return null;
diff --git a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemChannelLinkProvider.java b/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemChannelLinkProvider.java
deleted file mode 100644
index 92cde341cbeee..0000000000000
--- a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemChannelLinkProvider.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
- *
- * 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.openhab.core.internal.item;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.smarthome.core.common.registry.Provider;
-import org.eclipse.smarthome.core.common.registry.ProviderChangeListener;
-import org.eclipse.smarthome.core.common.registry.RegistryChangeListener;
-import org.eclipse.smarthome.core.thing.Channel;
-import org.eclipse.smarthome.core.thing.Thing;
-import org.eclipse.smarthome.core.thing.ThingRegistry;
-import org.eclipse.smarthome.core.thing.link.ItemChannelLink;
-import org.eclipse.smarthome.core.thing.link.ItemChannelLinkProvider;
-
-/**
- * This class provides item channel links for all items that were created through
- * the {@link ThingItemUIProvider}.
- *
- * @author Kai Kreuzer
- *
- */
-public class ThingItemChannelLinkProvider implements ItemChannelLinkProvider, RegistryChangeListener {
-
- private Set> listeners = new HashSet<>();
- private ThingRegistry thingRegistry;
- private ThingItemUIProvider thingItemUIProvider;
-
- @Override
- public void addProviderChangeListener(
- ProviderChangeListener listener) {
- listeners.add(listener);
- }
-
- @Override
- public void removeProviderChangeListener(
- ProviderChangeListener listener) {
- listeners.remove(listener);
- }
-
- @Override
- public Set getAll() {
- Set links = new HashSet<>();
- if(thingItemUIProvider.isEnabled()) {
- for(Thing thing : thingRegistry.getAll()) {
- links.addAll(getLinks(thing));
- }
- }
- return links;
- }
-
- private Set getLinks(Thing element) {
- Set links = new HashSet<>();
- if(thingItemUIProvider.isEnabled()) {
- for(Channel channel : element.getChannels()) {
- links.add(new ItemChannelLink(channel.getUID().toString().replace(":", "_").replaceAll("#", "_"), channel.getUID()));
- }
- }
- return links;
- }
-
- protected void setThingItemUIProvider(ThingItemUIProvider thingItemUIProvider) {
- this.thingItemUIProvider = thingItemUIProvider;
- }
-
- protected void unsetThingItemUIProvider(ThingItemUIProvider thingItemUIProvider) {
- this.thingItemUIProvider = null;
- }
-
- protected void setThingRegistry(ThingRegistry thingRegistry) {
- this.thingRegistry = thingRegistry;
- this.thingRegistry.addRegistryChangeListener(this);
- }
-
- protected void unsetThingRegistry(ThingRegistry thingRegistry) {
- this.thingRegistry.addRegistryChangeListener(this);
- this.thingRegistry = null;
- }
-
- public void updated(Provider provider, Thing oldelement,
- Thing element) {
- for(ProviderChangeListener listener : listeners) {
- for(ItemChannelLink link : getLinks(oldelement)) {
- listener.removed(this, link);
- }
- for(ItemChannelLink link : getLinks(element)) {
- listener.added(this, link);
- }
- }
- }
-
- @Override
- public void added(Thing element) {
- for(ProviderChangeListener listener : listeners) {
- for(ItemChannelLink link : getLinks(element)) {
- listener.added(this, link);
- }
- }
- }
-
- @Override
- public void removed(Thing element) {
- for(ProviderChangeListener listener : listeners) {
- for(ItemChannelLink link : getLinks(element)) {
- listener.removed(this, link);
- }
- }
- }
-
- @Override
- public void updated(Thing oldElement, Thing element) {
- for(ProviderChangeListener listener : listeners) {
- for(ItemChannelLink link : getLinks(oldElement)) {
- listener.removed(this, link);
- }
- for(ItemChannelLink link : getLinks(element)) {
- listener.added(this, link);
- }
- }
- }
-
-}
diff --git a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemProvider.java b/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemProvider.java
new file mode 100644
index 0000000000000..33041a6fe0c51
--- /dev/null
+++ b/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemProvider.java
@@ -0,0 +1,159 @@
+/**
+ * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
+ *
+ * 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.openhab.core.internal.item;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.smarthome.core.common.registry.ProviderChangeListener;
+import org.eclipse.smarthome.core.common.registry.RegistryChangeListener;
+import org.eclipse.smarthome.core.events.EventPublisher;
+import org.eclipse.smarthome.core.items.ActiveItem;
+import org.eclipse.smarthome.core.items.GroupItem;
+import org.eclipse.smarthome.core.items.Item;
+import org.eclipse.smarthome.core.items.ItemProvider;
+import org.eclipse.smarthome.core.items.ItemRegistry;
+import org.eclipse.smarthome.core.thing.ManagedThingProvider;
+import org.eclipse.smarthome.core.types.UnDefType;
+import org.osgi.service.cm.ConfigurationException;
+
+/**
+ * This class dynamically provides items incl. labels from all things of the {@link ManagedThingProvider}.
+ * All items are hierarchically sorted with a root group item called "Things".
+ *
+ * @author Kai Kreuzer
+ *
+ */
+public class ThingItemProvider implements ItemProvider, RegistryChangeListener- {
+
+ private Set> listeners = new HashSet<>();
+
+ private ItemRegistry itemRegistry;
+ private EventPublisher eventPublisher;
+ private GroupItem rootItem;
+
+ private boolean enabled = false;
+
+ @Override
+ public Collection
- getAll() {
+ if(!enabled) return Collections.emptySet();
+
+ Set
- items = new HashSet<>();
+ GroupItem all = getRootItem();
+ for(Item item : itemRegistry.getItemsByTag("thing")) {
+ ActiveItem aItem = (ActiveItem) item;
+ aItem.addGroupName(all.getName());
+ all.addMember(item);
+ }
+ items.add(all);
+ return items;
+ }
+
+ @Override
+ public void addProviderChangeListener(ProviderChangeListener
- listener) {
+ listeners.add(listener);
+ for(Item item : getAll()) {
+ listener.added(this, item);
+ }
+ }
+
+ @Override
+ public void removeProviderChangeListener(
+ ProviderChangeListener
- listener) {
+ listeners.remove(listener);
+
+ }
+
+ protected void setItemRegistry(ItemRegistry itemRegistry) {
+ this.itemRegistry = itemRegistry;
+ itemRegistry.addRegistryChangeListener(this);
+ }
+
+ protected void unsetItemRegistry(ItemRegistry itemRegistry) {
+ itemRegistry.removeRegistryChangeListener(this);
+ this.itemRegistry = null;
+ }
+
+ protected void setEventPublisher(EventPublisher eventPublisher) {
+ this.eventPublisher = eventPublisher;
+ }
+
+ protected void unsetEventPublisher(EventPublisher eventPublisher) {
+ this.eventPublisher = null;
+ }
+
+ private synchronized GroupItem getRootItem() {
+ if(rootItem==null) {
+ rootItem = new GroupItem("All");
+ rootItem.addTag("home-group");
+ rootItem.setLabel("All");
+ getAll();
+ }
+ return rootItem;
+ }
+
+ protected void activate(Map properties) throws ConfigurationException {
+ if(properties!=null) {
+ String enabled = (String) properties.get("enabled");
+ if("true".equalsIgnoreCase(enabled)) {
+ this.enabled = true;
+ for(ProviderChangeListener
- listener : listeners) {
+ for(Item item : getAll()) {
+ listener.added(this, item);
+ }
+ }
+ } else {
+ this.enabled = false;
+ for(ProviderChangeListener
- listener : listeners) {
+ for(Item item : getAll()) {
+ listener.removed(this, item);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void added(Item element) {
+ if(!enabled) return;
+ if(!element.getTags().contains("thing")) return;
+ rootItem = null;
+ rootItem = getRootItem();
+ for(ProviderChangeListener
- listener : listeners) {
+ listener.removed(this, getRootItem());
+ listener.added(this, getRootItem());
+ }
+ }
+
+ @Override
+ public void removed(Item element) {
+ if(!enabled) return;
+ if(!element.getTags().contains("thing")) return;
+ for(ProviderChangeListener
- listener : listeners) {
+ listener.removed(this, getRootItem());
+ rootItem = null;
+ listener.added(this, getRootItem());
+ }
+ }
+
+ @Override
+ public void updated(Item oldElement, Item element) {
+ if(!enabled) return;
+ removed(oldElement);
+ added(element);
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+}
diff --git a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemUIProvider.java b/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemUIProvider.java
deleted file mode 100644
index 421ce9bc25079..0000000000000
--- a/bundles/core/org.openhab.core/src/main/java/org/openhab/core/internal/item/ThingItemUIProvider.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/**
- * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
- *
- * 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.openhab.core.internal.item;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.WordUtils;
-import org.eclipse.smarthome.core.common.registry.ProviderChangeListener;
-import org.eclipse.smarthome.core.common.registry.RegistryChangeListener;
-import org.eclipse.smarthome.core.events.EventPublisher;
-import org.eclipse.smarthome.core.items.GroupItem;
-import org.eclipse.smarthome.core.items.Item;
-import org.eclipse.smarthome.core.items.ItemFactory;
-import org.eclipse.smarthome.core.items.ItemProvider;
-import org.eclipse.smarthome.core.thing.Bridge;
-import org.eclipse.smarthome.core.thing.Channel;
-import org.eclipse.smarthome.core.thing.ManagedThingProvider;
-import org.eclipse.smarthome.core.thing.Thing;
-import org.eclipse.smarthome.core.thing.ThingRegistry;
-import org.eclipse.smarthome.core.thing.ThingStatus;
-import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
-import org.eclipse.smarthome.core.thing.type.ThingType;
-import org.eclipse.smarthome.core.thing.type.ThingTypeRegistry;
-import org.eclipse.smarthome.core.types.UnDefType;
-import org.eclipse.smarthome.model.sitemap.Widget;
-import org.eclipse.smarthome.ui.items.ItemUIProvider;
-import org.osgi.service.cm.ConfigurationException;
-
-/**
- * This class dynamically provides items incl. labels from all things of the {@link ManagedThingProvider}.
- * All items are hierarchically sorted with a root group item called "Things".
- *
- * @author Kai Kreuzer
- *
- */
-public class ThingItemUIProvider implements ItemUIProvider, ItemProvider, RegistryChangeListener {
-
- private Set> listeners = new HashSet<>();
-
- private ThingRegistry thingRegistry;
- private ItemFactory itemFactory;
- private ThingTypeRegistry thingTypeRegistry;
- private EventPublisher eventPublisher;
- private GroupItem rootItem;
-
- private boolean enabled = false;
-
-
- @Override
- public String getIcon(String itemName) {
- if(!enabled) return null;
-
- if("Things".equals(itemName)) {
- return "network";
- }
-
- for(Thing thing : thingRegistry.getAll()) {
- if(thing.getUID().toString().replaceAll(":", "_").replaceAll("#", "_").equals(itemName)) {
- String icon = null;
- if(thing instanceof Bridge) {
- icon = "network";
- } else {
- icon = "switch";
- }
- if(thing.getStatus().equals(ThingStatus.ONLINE)) {
- return icon + "-on";
- } else {
- return icon + "-off";
- }
- }
- for(Channel ch : thing.getChannels()) {
- if(ch.getUID().toString().replaceAll(":", "_").replaceAll("#", "_").equals(itemName)) {
- if(ch.getAcceptedItemType().equals("Color")) {
- return "switch";
- }
- if(ch.getAcceptedItemType().equals("Dimmer")) {
- return "switch";
- }
- }
- }
- }
- return null;
- }
-
- @Override
- public String getLabel(String itemName) {
- if(!enabled) return null;
-
- for(Thing thing : thingRegistry.getAll()) {
- if(thing.getUID().toString().replaceAll(":", "_").replaceAll("#", "_").equals(itemName)) {
- String label = (String) thing.getConfiguration().get("label");
- if(label!=null && !label.isEmpty()) {
- return label;
- } else {
- return WordUtils.capitalize(itemName.replace("_", " "));
- }
- }
- for(Channel channel : thing.getChannels()) {
- if(channel.getUID().toString().replaceAll(":", "_").replaceAll("#", "_").equals(itemName)) {
- String label = (String) StringUtils.capitalize(channel.getUID().getId());
- ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
- if(thingType!=null) {
- for(ChannelDefinition chDef : thingType.getChannelDefinitions()) {
- if (chDef.getId().equals(channel.getUID().getId())) {
- label = chDef.getType().getLabel();
- }
- }
- }
- if(channel.getAcceptedItemType().equals("String")) label += " [%s]";
- if(channel.getAcceptedItemType().equals("Number")) label += " [%.1f]";
- return label;
- }
- }
- }
- return null;
- }
-
- @Override
- public Widget getDefaultWidget(Class extends Item> itemType,
- String itemName) {
- return null;
- }
-
- @Override
- public Widget getWidget(String itemName) {
- return null;
- }
-
- @Override
- public Collection
- getAll() {
- if(!enabled) return Collections.emptySet();
-
- Set
- items = new HashSet<>();
- GroupItem all = getRootItem();
- for(Thing thing : thingRegistry.getAll()) {
- GroupItem group = createItemsForThing(thing);
- if((thing instanceof Bridge) || thing.getBridgeUID() == null) {
- if(group!=null) {
- if(all.getMembers().contains(group)) {
- all.removeMember(group);
- }
- all.addMember(group);
- }
- }
- for(Item item : group.getAllMembers()) {
- items.add(item);
- }
- items.add(group);
- }
- items.add(all);
- return items;
- }
-
- /*default*/ GroupItem createItemsForThing(Thing thing) {
- GroupItem group = new GroupItem(thing.getUID().toString().replaceAll(":", "_").replaceAll("#", "_"));
- for(Channel channel : thing.getChannels()) {
- Item item = itemFactory.createItem(channel.getAcceptedItemType(), channel.getUID().toString().replaceAll(":", "_").replaceAll("#", "_"));
- if(item!=null) {
- if(group.getMembers().contains(item)) {
- group.removeMember(item);
- }
- group.addMember(item);
- }
- }
- if(thing instanceof Bridge) {
- Bridge bridge = (Bridge) thing;
- for(Thing child : bridge.getThings()) {
- group.addMember(createItemsForThing(child));
- }
- }
- if(thing.getBridgeUID()!=null) {
- group.addGroupName(thing.getBridgeUID().toString().replaceAll(":", "_").replaceAll("#", "_"));
- } else {
- group.addGroupName("Things");
- }
- return group;
- }
-
- @Override
- public void addProviderChangeListener(ProviderChangeListener
- listener) {
- listeners.add(listener);
- for(Item item : getAll()) {
- listener.added(this, item);
- }
- }
-
- @Override
- public void removeProviderChangeListener(
- ProviderChangeListener
- listener) {
- listeners.remove(listener);
-
- }
-
- protected void setItemFactory(ItemFactory itemFactory) {
- this.itemFactory = itemFactory;
- }
-
- protected void unsetItemFactory(ItemFactory itemFactory) {
- this.itemFactory = null;
- }
-
- protected void setThingRegistry(ThingRegistry thingRegistry) {
- this.thingRegistry = thingRegistry;
- this.thingRegistry.addRegistryChangeListener(this);
- }
-
- protected void unsetThingRegistry(ThingRegistry thingRegistry) {
- this.thingRegistry.addRegistryChangeListener(this);
- this.thingRegistry = null;
- }
-
- protected void setEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- protected void unsetEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = null;
- }
-
- protected void setThingTypeRegistry(ThingTypeRegistry thingTypeRegistry) {
- this.thingTypeRegistry = thingTypeRegistry;
- }
-
- protected void unsetThingTypeRegistry(ThingTypeRegistry thingProvider) {
- this.thingTypeRegistry = null;
- }
-
- private synchronized GroupItem getRootItem() {
- if(rootItem==null) {
- rootItem = new GroupItem("Things");
- getAll();
- }
- return rootItem;
- }
-
- protected void activate(Map properties) throws ConfigurationException {
- if(properties!=null) {
- String enabled = (String) properties.get("enabled");
- if("true".equalsIgnoreCase(enabled)) {
- this.enabled = true;
- for(ProviderChangeListener
- listener : listeners) {
- for(Item item : getAll()) {
- listener.added(this, item);
- }
- }
- } else {
- this.enabled = false;
- for(ProviderChangeListener
- listener : listeners) {
- for(Item item : getAll()) {
- listener.removed(this, item);
- }
- }
- }
- }
- }
-
- @Override
- public void added(Thing element) {
- if(!enabled) return;
- for(ProviderChangeListener
- listener : listeners) {
- listener.removed(this, getRootItem());
- }
- rootItem = null;
- GroupItem group = createItemsForThing(element);
- rootItem = getRootItem();
- for(ProviderChangeListener
- listener : listeners) {
- for(Item item : group.getMembers()) {
- listener.added(this, item);
- }
- listener.added(this, group);
- listener.added(this, getRootItem());
-
- }
- if(group.getAcceptedDataTypes().contains(UnDefType.UNDEF)) {
- eventPublisher.postUpdate(group.getName(), UnDefType.UNDEF);
- }
- if(rootItem.getAcceptedDataTypes().contains(UnDefType.UNDEF)) {
- eventPublisher.postUpdate(rootItem.getName(), UnDefType.UNDEF);
- }
- }
-
- @Override
- public void removed(Thing element) {
- if(!enabled) return;
- for(ProviderChangeListener
- listener : listeners) {
- listener.removed(this, getRootItem());
- rootItem = null;
- GroupItem group = createItemsForThing(element);
- listener.removed(this, group);
- for(Item item : group.getMembers()) {
- listener.removed(this, item);
- }
- listener.added(this, getRootItem());
- }
- }
-
- @Override
- public void updated(Thing oldElement, Thing element) {
- if(!enabled) return;
- removed(oldElement);
- added(element);
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
-}