Search in sources :

Example 1 with Slider

use of org.eclipse.smarthome.model.sitemap.Slider 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 2 with Slider

use of org.eclipse.smarthome.model.sitemap.Slider in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSliderWidgetThroughGetState.

@Test
public void testStateConversionForSliderWidgetThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,75");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Slider sliderWidget = mock(Slider.class);
    when(sliderWidget.getItem()).thenReturn("myItem");
    State stateForSlider = uiRegistry.getState(sliderWidget);
    assertTrue(stateForSlider instanceof PercentType);
    PercentType pt = (PercentType) stateForSlider;
    assertEquals(75, pt.longValue());
}
Also used : Slider(org.eclipse.smarthome.model.sitemap.Slider) State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 3 with Slider

use of org.eclipse.smarthome.model.sitemap.Slider in project smarthome by eclipse.

the class SliderRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Slider s = (Slider) w;
    String snippetName = "slider";
    String snippet = getSnippet(snippetName);
    // set the default send-update frequency to 200ms
    String frequency = s.getFrequency() == 0 ? "200" : Integer.toString(s.getFrequency());
    String unit = getUnitForWidget(w);
    snippet = preprocessSnippet(snippet, w);
    snippet = StringUtils.replace(snippet, "%frequency%", frequency);
    snippet = StringUtils.replace(snippet, "%switch%", s.isSwitchEnabled() ? "1" : "0");
    snippet = StringUtils.replace(snippet, "%unit%", unit);
    // Process the color tags
    snippet = processColor(w, snippet);
    sb.append(snippet);
    return null;
}
Also used : Slider(org.eclipse.smarthome.model.sitemap.Slider)

Example 4 with Slider

use of org.eclipse.smarthome.model.sitemap.Slider in project smarthome by eclipse.

the class SliderRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Slider s = (Slider) w;
    String snippetName = "slider";
    String snippet = getSnippet(snippetName);
    // set the default send-update frequency to 200ms
    String frequency = s.getFrequency() == 0 ? "200" : Integer.toString(s.getFrequency());
    snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(s));
    snippet = StringUtils.replace(snippet, "%category%", getCategory(s));
    snippet = StringUtils.replace(snippet, "%item%", w.getItem());
    snippet = StringUtils.replace(snippet, "%label%", getLabel(s));
    snippet = StringUtils.replace(snippet, "%state%", getStateAsNumber(s));
    snippet = StringUtils.replace(snippet, "%format%", getFormat());
    snippet = StringUtils.replace(snippet, "%frequency%", frequency);
    snippet = StringUtils.replace(snippet, "%switch%", s.isSwitchEnabled() ? "1" : "0");
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
    // Process the color tags
    snippet = processColor(w, snippet);
    sb.append(snippet);
    return null;
}
Also used : Slider(org.eclipse.smarthome.model.sitemap.Slider)

Example 5 with Slider

use of org.eclipse.smarthome.model.sitemap.Slider in project smarthome by eclipse.

the class ItemUIRegistryImpl method convertState.

/**
 * Converts an item state to the type the widget supports (if possible)
 *
 * @param w Widget in sitemap that shows the state
 * @param i item
 * @return the converted state or the original if conversion was not possible
 */
private State convertState(Widget w, Item i) {
    State returnState = null;
    State itemState = i.getState();
    if (itemState instanceof QuantityType) {
        itemState = convertStateToWidgetUnit((QuantityType<?>) itemState, w);
    }
    if (w instanceof Switch && i instanceof RollershutterItem) {
        // RollerShutter are represented as Switch in a Sitemap but need a PercentType state
        returnState = itemState.as(PercentType.class);
    } else if (w instanceof Slider) {
        if (i.getAcceptedDataTypes().contains(PercentType.class)) {
            returnState = itemState.as(PercentType.class);
        } else {
            returnState = itemState.as(DecimalType.class);
        }
    } else if (w instanceof Switch) {
        Switch sw = (Switch) w;
        if (sw.getMappings().size() == 0) {
            returnState = itemState.as(OnOffType.class);
        }
    }
    // if returnState is null, a conversion was not possible
    if (returnState == null) {
        // we return the original state to not break anything
        returnState = itemState;
    }
    return returnState;
}
Also used : Switch(org.eclipse.smarthome.model.sitemap.Switch) Slider(org.eclipse.smarthome.model.sitemap.Slider) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) State(org.eclipse.smarthome.core.types.State) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Aggregations

Slider (org.eclipse.smarthome.model.sitemap.Slider)6 PercentType (org.eclipse.smarthome.core.library.types.PercentType)2 State (org.eclipse.smarthome.core.types.State)2 LinkableWidget (org.eclipse.smarthome.model.sitemap.LinkableWidget)2 Switch (org.eclipse.smarthome.model.sitemap.Switch)2 Widget (org.eclipse.smarthome.model.sitemap.Widget)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 EList (org.eclipse.emf.common.util.EList)1 GenericItem (org.eclipse.smarthome.core.items.GenericItem)1 Item (org.eclipse.smarthome.core.items.Item)1 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)1 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)1 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)1 Chart (org.eclipse.smarthome.model.sitemap.Chart)1 Frame (org.eclipse.smarthome.model.sitemap.Frame)1 Image (org.eclipse.smarthome.model.sitemap.Image)1