Search in sources :

Example 1 with MenuMode

use of com.github.bordertech.wcomponents.WSubMenu.MenuMode 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)

Aggregations

WSubMenu (com.github.bordertech.wcomponents.WSubMenu)1 MenuMode (com.github.bordertech.wcomponents.WSubMenu.MenuMode)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1