use of org.eclipse.smarthome.ui.items.ItemUIProvider in project smarthome by eclipse.
the class ItemUIRegistryImpl method getCategory.
@Override
public String getCategory(String itemName) {
for (ItemUIProvider provider : itemUIProviders) {
String currentCategory = provider.getCategory(itemName);
if (currentCategory != null) {
return currentCategory;
}
}
// use the category, if defined
String category = getItemCategory(itemName);
if (category != null) {
return category.toLowerCase();
}
// do some reasonable default
// try to get the item type from the item name
Class<? extends Item> itemType = getItemType(itemName);
if (itemType == null) {
return null;
}
// like "rollerblind".
if (itemType.equals(NumberItem.class) || itemType.equals(ContactItem.class) || itemType.equals(RollershutterItem.class)) {
return itemType.getSimpleName().replace("Item", "").toLowerCase();
}
return null;
}
use of org.eclipse.smarthome.ui.items.ItemUIProvider in project smarthome by eclipse.
the class ItemUIRegistryImpl method getDefaultWidget.
@Override
public Widget getDefaultWidget(Class<? extends Item> targetItemType, String itemName) {
for (ItemUIProvider provider : itemUIProviders) {
Widget widget = provider.getDefaultWidget(targetItemType, itemName);
if (widget != null) {
return widget;
}
}
// do some reasonable default, if no provider had an answer
// if the itemType is not defined, try to get it from the item name
Class<? extends Item> itemType = targetItemType;
if (itemType == null) {
itemType = getItemType(itemName);
}
if (itemType == null) {
return null;
}
if (itemType.equals(SwitchItem.class)) {
return SitemapFactory.eINSTANCE.createSwitch();
}
if (itemType.equals(GroupItem.class)) {
return SitemapFactory.eINSTANCE.createGroup();
}
if (NumberItem.class.isAssignableFrom(itemType)) {
return SitemapFactory.eINSTANCE.createText();
}
if (itemType.equals(ContactItem.class)) {
return SitemapFactory.eINSTANCE.createText();
}
if (itemType.equals(DateTimeItem.class)) {
return SitemapFactory.eINSTANCE.createText();
}
if (itemType.equals(RollershutterItem.class)) {
return SitemapFactory.eINSTANCE.createSwitch();
}
if (itemType.equals(StringItem.class)) {
return SitemapFactory.eINSTANCE.createText();
}
if (itemType.equals(LocationItem.class)) {
return SitemapFactory.eINSTANCE.createText();
}
if (itemType.equals(CallItem.class)) {
return SitemapFactory.eINSTANCE.createText();
}
if (itemType.equals(DimmerItem.class)) {
Slider slider = SitemapFactory.eINSTANCE.createSlider();
slider.setSwitchEnabled(true);
return slider;
}
if (itemType.equals(ColorItem.class)) {
return SitemapFactory.eINSTANCE.createColorpicker();
}
if (itemType.equals(PlayerItem.class)) {
return createPlayerButtons();
}
if (itemType.equals(ImageItem.class)) {
return SitemapFactory.eINSTANCE.createImage();
}
return null;
}
use of org.eclipse.smarthome.ui.items.ItemUIProvider in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelFromUIProvider.
@Test
public void getLabel_labelFromUIProvider() throws ItemNotFoundException {
ItemUIProvider provider = mock(ItemUIProvider.class);
uiRegistry.addItemUIProvider(provider);
when(provider.getLabel(anyString())).thenReturn("ProviderLabel");
String label = uiRegistry.getLabel(widget);
assertEquals("ProviderLabel", label);
uiRegistry.removeItemUIProvider(provider);
}
Aggregations