/**
* {@inheritDoc}
*/
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Switch s = (Switch) w;
String snippetName = null;
Item item;
try {
item = itemUIRegistry.getItem(w.getItem());
if(s.getMappings().size()==0) {
if(item instanceof RollershutterItem) {
snippetName = "rollerblind";
} else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) {
snippetName = "rollerblind";
} else {
snippetName = "switch";
}
} else {
snippetName = "buttons";
}
} catch (ItemNotFoundException e) {
logger.warn("Cannot determine item type of '{}'", w.getItem(), e);
snippetName = "switch";
}
String snippet = getSnippet(snippetName);
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(w)));
snippet = StringUtils.replace(snippet, "%item%", w.getItem());
snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
State state = itemUIRegistry.getState(w);
if(s.getMappings().size()==0) {
if(state instanceof PercentType) {
state = ((PercentType) state).intValue() > 0 ? OnOffType.ON : OnOffType.OFF;
}
if(state.equals(OnOffType.ON)) {
snippet = snippet.replaceAll("%checked%", "checked=true");
} else {
snippet = snippet.replaceAll("%checked%", "");
}
} else {
StringBuilder buttons = new StringBuilder();
for(Mapping mapping : s.getMappings()) {
String button = getSnippet("button");
button = StringUtils.replace(button, "%item%",w.getItem());
button = StringUtils.replace(button, "%cmd%", mapping.getCmd());
button = StringUtils.replace(button, "%label%", mapping.getLabel());
if(s.getMappings().size()>1 && state.toString().equals(mapping.getCmd())) {
button = StringUtils.replace(button, "%type%", "Warn"); // button with red color
} else {
button = StringUtils.replace(button, "%type%", "Action"); // button with blue color
}
buttons.insert(0, button);