@Override public void render(Context context, String value, SafeHtmlBuilder sb) { // Get the view data. Object key = context.getKey(); String viewData = getViewData(key); if (viewData != null && viewData.equals(value)) { clearViewData(key); viewData = null; } int selectedIndex = getSelectedIndex(viewData == null ? value : viewData); sb.appendHtmlConstant("<select tabindex=\"-1\">"); int index = 0; for (String option : options) { if (index++ == selectedIndex) { sb.append(template.selected(option)); } else { sb.append(template.deselected(option)); } } sb.appendHtmlConstant("</select>"); }
@Override public void render(Context context, String value, SafeHtmlBuilder sb) { // Get the view data. HasOptions key = (HasOptions) context.getKey(); String viewData = getViewData(key); if (viewData != null && viewData.equals(value)) { clearViewData(key); viewData = null; } if (key.hasOptions()) { if (cellWidth != null) sb.appendHtmlConstant("<select tabindex=\"-1\" style=\"width: " + cellWidth + "\">"); else sb.appendHtmlConstant("<select tabindex=\"-1\">"); int selectedOptionIndex = getSelectedOptionIndex(key, viewData == null ? value : viewData); int index = 0; // append options preamble List<String> optionsPreamble = key.getOptionsPreamble(); if (optionsPreamble != null) { for (String option : optionsPreamble) sb.append(template.deselected(option)); } // append the rest of the options for (String option : key.getOptions()) { if (index++ == selectedOptionIndex) { sb.append(template.selected(option)); } else { sb.append(template.deselected(option)); } } sb.appendHtmlConstant("</select>"); } else sb.appendHtmlConstant("<div>" + key.getNoOptionsString() + "</div>"); }