Search in sources :

Example 11 with WSubMenu

use of com.github.bordertech.wcomponents.WSubMenu in project wcomponents by BorderTech.

the class FilterableTableExample method buildFilterSubMenu.

/**
 * Creates and populates the sub-menu for each filter menu.
 *
 * @param menu The WMenu we are currently populating.
 * @param column The column index of the table column the menu is in. This is used to get the data off the table's
 * Bean to put text content into the menu's items.
 */
private void buildFilterSubMenu(final WMenu menu, final int column) {
    List<?> beanList = getFilterableTableModel().getFullBeanList();
    int rows = (beanList == null) ? 0 : beanList.size();
    if (rows == 0) {
        return;
    }
    final List<String> found = new ArrayList<>();
    final WDecoratedLabel filterSubMenuLabel = new WDecoratedLabel(new WText("\u200b"));
    filterSubMenuLabel.setToolTip("Filter this column");
    filterSubMenuLabel.setHtmlClass(HtmlIconUtil.getIconClasses("fa-filter"));
    final WSubMenu submenu = new WSubMenu(filterSubMenuLabel);
    submenu.setSelectionMode(SELECTION_MODE);
    menu.add(submenu);
    WMenuItem item = new WMenuItem(CLEAR_ALL, new ClearFilterAction());
    submenu.add(item);
    item.setActionObject(item);
    item.setSelectability(false);
    add(new WAjaxControl(item, table));
    Object cellObject;
    String cellContent, cellContentMatch;
    Object bean;
    if (beanList != null) {
        for (int i = 0; i < rows; ++i) {
            bean = beanList.get(i);
            if (bean != null) {
                cellObject = getFilterableTableModel().getBeanPropertyValueFullList(BEAN_PROPERTIES[column], bean);
                if (cellObject != null) {
                    if (cellObject instanceof Date) {
                        cellContent = new SimpleDateFormat(DATE_FORMAT).format((Date) cellObject);
                    } else {
                        cellContent = cellObject.toString();
                    }
                    if ("".equals(cellContent)) {
                        cellContent = EMPTY;
                    }
                    cellContentMatch = (getFilterableTableModel().isCaseInsensitiveMatch()) ? cellContent.toLowerCase() : cellContent;
                    if (found.indexOf(cellContentMatch) == -1) {
                        item = new WMenuItem(cellContent, new FilterAction());
                        submenu.add(item);
                        add(new WAjaxControl(item, table));
                        found.add(cellContentMatch);
                    }
                }
            }
        }
    }
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ArrayList(java.util.ArrayList) Date(java.util.Date) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) SimpleDateFormat(java.text.SimpleDateFormat) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 12 with WSubMenu

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

use of com.github.bordertech.wcomponents.WSubMenu in project wcomponents by BorderTech.

the class WMenuItemRenderer_Test method testAccessKey.

@Test
public void testAccessKey() throws IOException, SAXException, XpathException {
    // AccessKey
    WMenuItem item = new WMenuItem(itemText, url);
    WMenu wrapped = wrapMenuItem(item);
    item.setAccessKey('A');
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo("A", "//ui:menuitem/@accessKey", item);
    // no access key if nested
    WSubMenu sub = new WSubMenu("sub");
    wrapped.add(sub);
    item = new WMenuItem(itemText, url);
    sub.add(item);
    item.setAccessKey('A');
    assertSchemaMatch(wrapped);
    assertXpathNotExists("//ui:menuitem/@accessKey", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Aggregations

WSubMenu (com.github.bordertech.wcomponents.WSubMenu)13 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)11 WMenu (com.github.bordertech.wcomponents.WMenu)8 WMenuItemGroup (com.github.bordertech.wcomponents.WMenuItemGroup)4 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)3 WText (com.github.bordertech.wcomponents.WText)3 Test (org.junit.Test)3 Action (com.github.bordertech.wcomponents.Action)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)2 WImage (com.github.bordertech.wcomponents.WImage)2 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)2 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)1 MenuMode (com.github.bordertech.wcomponents.WSubMenu.MenuMode)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Before (org.junit.Before)1