use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WSelectToggleRenderer method doRender.
/**
* Paints the given WSelectToggle.
*
* @param component the WSelectToggle to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSelectToggle toggle = (WSelectToggle) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:selecttoggle");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
State state = toggle.getState();
if (State.ALL.equals(state)) {
xml.appendAttribute("selected", "all");
} else if (State.NONE.equals(state)) {
xml.appendAttribute("selected", "none");
} else {
xml.appendAttribute("selected", "some");
}
xml.appendOptionalAttribute("disabled", toggle.isDisabled(), "true");
xml.appendAttribute("target", toggle.getTarget().getId());
xml.appendAttribute("renderAs", toggle.isRenderAsText() ? "text" : "control");
xml.appendOptionalAttribute("roundTrip", !toggle.isClientSide(), "true");
xml.appendEnd();
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WShufflerRenderer method doRender.
/**
* Paints the given WShuffler.
*
* @param component the WShuffler to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WShuffler shuffler = (WShuffler) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = shuffler.isReadOnly();
// Start tag
xml.appendTagOpen("ui:shuffler");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", shuffler.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("disabled", shuffler.isDisabled(), "true");
xml.appendOptionalAttribute("toolTip", shuffler.getToolTip());
xml.appendOptionalAttribute("accessibleText", shuffler.getAccessibleText());
int rows = shuffler.getRows();
xml.appendOptionalAttribute("rows", rows > 0, rows);
}
xml.appendClose();
// Options
List<?> options = shuffler.getOptions();
if (options != null && !options.isEmpty()) {
for (int i = 0; i < options.size(); i++) {
String stringOption = String.valueOf(options.get(i));
xml.appendTagOpen("ui:option");
xml.appendAttribute("value", stringOption);
xml.appendClose();
xml.appendEscaped(stringOption);
xml.appendEndTag("ui:option");
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(shuffler, renderContext);
}
// End tag
xml.appendEndTag("ui:shuffler");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WSingleSelectRenderer method doRender.
/**
* Paints the given WSingleSelect.
*
* @param component the WSingleSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSingleSelect listBox = (WSingleSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
String dataKey = listBox.getListCacheKey();
boolean readOnly = listBox.isReadOnly();
int rows = listBox.getRows();
xml.appendTagOpen("ui:listbox");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", listBox.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("data", dataKey != null, dataKey);
xml.appendOptionalAttribute("disabled", listBox.isDisabled(), "true");
xml.appendOptionalAttribute("required", listBox.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", listBox.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
xml.appendOptionalAttribute("rows", rows >= 2, rows);
}
xml.appendAttribute("single", "true");
xml.appendClose();
// Options
List<?> options = listBox.getOptions();
boolean renderSelectionsOnly = readOnly || dataKey != null;
if (options != null) {
int optionIndex = 0;
Object selectedOption = listBox.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
xml.appendTagOpen("ui:optgroup");
xml.appendAttribute("label", ((OptionGroup) option).getDesc());
xml.appendClose();
for (Object nestedOption : ((OptionGroup) option).getOptions()) {
renderOption(listBox, nestedOption, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(listBox, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(listBox, renderContext);
}
xml.appendEndTag("ui:listbox");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WSubMenuRenderer method doRender.
/**
* Paints the given WSubMenu.
*
* @param component the WSubMenu to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSubMenu menu = (WSubMenu) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:submenu");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (isTree(menu)) {
xml.appendAttribute("open", String.valueOf(isOpen(menu)));
}
xml.appendOptionalAttribute("disabled", menu.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", menu.isHidden(), "true");
if (menu.isTopLevelMenu()) {
xml.appendOptionalAttribute("accessKey", menu.getAccessKeyAsString());
} else {
xml.appendAttribute("nested", "true");
}
xml.appendOptionalAttribute("type", getMenuType(menu));
switch(menu.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
case SERVER:
// mode server mapped to mode dynamic as per https://github.com/BorderTech/wcomponents/issues/687
xml.appendAttribute("mode", "dynamic");
break;
default:
throw new SystemException("Unknown menu mode: " + menu.getMode());
}
xml.appendClose();
// Paint label
menu.getDecoratedLabel().paint(renderContext);
MenuMode mode = menu.getMode();
// Paint submenu items
xml.appendTagOpen("ui:content");
xml.appendAttribute("id", component.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX request
if (mode != MenuMode.EAGER || AjaxHelper.isCurrentAjaxTrigger(menu)) {
// Visibility of content set in prepare paint
menu.paintMenuItems(renderContext);
}
xml.appendEndTag("ui:content");
xml.appendEndTag("ui:submenu");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WSuggestionsRenderer method doRender.
/**
* Paints the given WSuggestions.
*
* @param component the WSuggestions to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSuggestions suggestions = (WSuggestions) component;
XmlStringBuilder xml = renderContext.getWriter();
// Cache key for a lookup table
String dataKey = suggestions.getListCacheKey();
// Use AJAX if not using a cached list and have a refresh action
boolean useAjax = dataKey == null && suggestions.getRefreshAction() != null;
// Start tag
xml.appendTagOpen("ui:suggestions");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("min", suggestions.getMinRefresh() > 0, suggestions.getMinRefresh());
xml.appendOptionalAttribute("ajax", useAjax, "true");
xml.appendOptionalAttribute("data", dataKey);
WSuggestions.Autocomplete autocomplete = suggestions.getAutocomplete();
if (autocomplete == WSuggestions.Autocomplete.LIST) {
xml.appendOptionalAttribute("autocomplete", "list");
}
xml.appendClose();
// Check if this is the current AJAX trigger
boolean isTrigger = useAjax && AjaxHelper.isCurrentAjaxTrigger(suggestions);
// Render suggestions
if (isTrigger || (dataKey == null && !useAjax)) {
for (String suggestion : suggestions.getSuggestions()) {
xml.appendTagOpen("ui:suggestion");
xml.appendAttribute("value", suggestion);
xml.appendEnd();
}
}
// End tag
xml.appendEndTag("ui:suggestions");
}
Aggregations