Source:
public String getLabel(Widget w) { String label = getLabelFromWidget(w); String itemName = w.getItem(); if (itemName != null) { State state = null; String formatPattern = getFormatPattern(label); try { final Item item = getItem(itemName); final StateDescription stateDescription = item.getStateDescription(); if (formatPattern == null) { if (stateDescription != null) { final String pattern = stateDescription.getPattern(); if (pattern != null) { label = label + " [" + pattern + "]"; } } } String updatedPattern = getFormatPattern(label); if (updatedPattern != null) { formatPattern = updatedPattern; if (!formatPattern.isEmpty()) { if (label.contains("%d")) { state = item.getState(); if (!(state instanceof DecimalType)) { state = item.getStateAs(DecimalType.class); } } else { state = item.getState(); if (stateDescription != null && stateDescription.getOptions() != null) { for (StateOption option : stateDescription.getOptions()) { if (option.getValue().equals(state.toString()) && option.getLabel() != null) { state = new StringType(option.getLabel()); break; } } } } } } } catch (ItemNotFoundException e) { logger.error("Cannot retrieve item for widget {}", w.eClass().getInstanceTypeName()); } if (formatPattern != null) { if (formatPattern.isEmpty()) { label = label.substring(0, label.indexOf("[")).trim(); } else { if (state == null || state instanceof UnDefType) { formatPattern = formatUndefined(formatPattern); } else if (state instanceof Type) { try { formatPattern = ((Type) state).format(formatPattern); } catch (IllegalArgumentException e) { logger.warn("Exception while formatting value '{}' of item with format '{}': {}", state, itemName, formatPattern, e); formatPattern = new String("Err"); } } label = label.trim(); label = label.substring(0, label.indexOf("[") + 1) + formatPattern + "]"; } } } label = transform(label); return label; }

Target:
public String getLabel(Widget w) { String label = getLabelFromWidget(w); String itemName = w.getItem(); if (itemName != null) { State state = null; String formatPattern = getFormatPattern(label); try { final Item item = getItem(itemName); if (formatPattern == null) { final StateDescription stateDescription = item.getStateDescription(); if (stateDescription != null) { final String pattern = stateDescription.getPattern(); if (pattern != null) { label = label + " [" + pattern + "]"; } } } String updatedPattern = getFormatPattern(label); if (updatedPattern != null) { formatPattern = updatedPattern; if (!formatPattern.isEmpty()) { if (label.contains("%d")) { state = item.getState(); if (!(state instanceof DecimalType)) { state = item.getStateAs(DecimalType.class); } } else { state = item.getState(); } } } } catch (ItemNotFoundException e) { logger.error("Cannot retrieve item for widget {}", w.eClass().getInstanceTypeName()); } if (formatPattern != null) { if (formatPattern.isEmpty()) { label = label.substring(0, label.indexOf("[")).trim(); } else { if (state == null || state instanceof UnDefType) { formatPattern = formatUndefined(formatPattern); } else if (state instanceof Type) { try { formatPattern = ((Type) state).format(formatPattern); } catch (IllegalArgumentException e) { logger.warn("Exception while formatting value '{}' of item with format '{}': {}", state, itemName, formatPattern, e); formatPattern = new String("Err"); } } label = label.trim(); label = label.substring(0, label.indexOf("[") + 1) + formatPattern + "]"; } } } label = transform(label); return label; }