Search in sources :

Example 91 with XmlStringBuilder

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();
}
Also used : State(com.github.bordertech.wcomponents.WSelectToggle.State) WSelectToggle(com.github.bordertech.wcomponents.WSelectToggle) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 92 with XmlStringBuilder

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");
}
Also used : XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WShuffler(com.github.bordertech.wcomponents.WShuffler)

Example 93 with XmlStringBuilder

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");
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WSingleSelect(com.github.bordertech.wcomponents.WSingleSelect) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 94 with XmlStringBuilder

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");
}
Also used : WSubMenu(com.github.bordertech.wcomponents.WSubMenu) SystemException(com.github.bordertech.wcomponents.util.SystemException) MenuMode(com.github.bordertech.wcomponents.WSubMenu.MenuMode) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 95 with XmlStringBuilder

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");
}
Also used : WSuggestions(com.github.bordertech.wcomponents.WSuggestions) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)102 WComponent (com.github.bordertech.wcomponents.WComponent)30 SystemException (com.github.bordertech.wcomponents.util.SystemException)17 Size (com.github.bordertech.wcomponents.Size)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)6 UIContext (com.github.bordertech.wcomponents.UIContext)5 WPanel (com.github.bordertech.wcomponents.WPanel)5 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 WButton (com.github.bordertech.wcomponents.WButton)4 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)4 WTable (com.github.bordertech.wcomponents.WTable)4 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)3 WDataTable (com.github.bordertech.wcomponents.WDataTable)3 WRepeater (com.github.bordertech.wcomponents.WRepeater)3 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2