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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations