Search in sources :

Example 1 with ItemUIProvider

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;
}
Also used : ItemUIProvider(org.eclipse.smarthome.ui.items.ItemUIProvider) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem)

Example 2 with ItemUIProvider

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;
}
Also used : ItemUIProvider(org.eclipse.smarthome.ui.items.ItemUIProvider) Slider(org.eclipse.smarthome.model.sitemap.Slider) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 3 with ItemUIProvider

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);
}
Also used : ItemUIProvider(org.eclipse.smarthome.ui.items.ItemUIProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ItemUIProvider (org.eclipse.smarthome.ui.items.ItemUIProvider)3 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)1 LinkableWidget (org.eclipse.smarthome.model.sitemap.LinkableWidget)1 Slider (org.eclipse.smarthome.model.sitemap.Slider)1 Widget (org.eclipse.smarthome.model.sitemap.Widget)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1