Search in sources :

Example 21 with WMenuItem

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

the class MenuPanel method addRecentExample.

/**
 * Adds an example to the recent subMenu.
 *
 * @param text the text to display.
 * @param data the example data instance
 * @param select should the menuItem be selected
 */
private void addRecentExample(final String text, final ExampleData data, final boolean select) {
    WMenuItem item = new WMenuItem(text, new SelectExampleAction());
    menu.add(item);
    item.setActionObject(data);
    if (select) {
        menu.setSelectedMenuItem(item);
    }
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem)

Example 22 with WMenuItem

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

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

the class WMenuItemRenderer method doRender.

/**
 * Paints the given WMenuItem.
 *
 * @param component the WMenuItem to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMenuItem item = (WMenuItem) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:menuitem");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    if (item.isSubmit()) {
        xml.appendAttribute("submit", "true");
    } else {
        xml.appendOptionalUrlAttribute("url", item.getUrl());
        xml.appendOptionalAttribute("targetWindow", item.getTargetWindow());
    }
    xml.appendOptionalAttribute("disabled", item.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", item.isHidden(), "true");
    xml.appendOptionalAttribute("selected", item.isSelected(), "true");
    xml.appendOptionalAttribute("role", getRole(item));
    xml.appendOptionalAttribute("cancel", item.isCancel(), "true");
    xml.appendOptionalAttribute("msg", item.getMessage());
    xml.appendOptionalAttribute("toolTip", item.getToolTip());
    if (item.isTopLevelItem()) {
        xml.appendOptionalAttribute("accessKey", item.getAccessKeyAsString());
    }
    xml.appendClose();
    item.getDecoratedLabel().paint(renderContext);
    xml.appendEndTag("ui:menuitem");
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 24 with WMenuItem

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

the class WMenuItemRenderer_Test method testUrl.

@Test
public void testUrl() throws IOException, SAXException, XpathException {
    // Test with URL
    WMenuItem item = new WMenuItem(itemText, url);
    WMenu wrapped = wrapMenuItem(item);
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo(itemText, "normalize-space(//ui:menuitem/ui:decoratedlabel)", item);
    assertXpathUrlEvaluatesTo(url, "//ui:menuitem/@url", item);
    assertXpathNotExists("//ui:menuitem/@submit", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 25 with WMenuItem

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

the class WMenuItemRenderer_Test method testRoleWhenSelectedNotSelectable.

@Test
public void testRoleWhenSelectedNotSelectable() throws IOException, SAXException, XpathException {
    /*
		 * A WMenuItem may be set as selected even if it is not in a selection container. This is a flaw in an
		 * old part of the WComponents API.
		 */
    WMenuItem item = new WMenuItem(itemText);
    WMenu wrapped = wrapMenuItem(item);
    wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.SINGLE);
    assertXpathNotExists("//ui:menuitem/@selected", item);
    wrapped.setSelectedItem(item);
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo("true", "//ui:menuitem/@selected", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Aggregations

WMenuItem (com.github.bordertech.wcomponents.WMenuItem)31 WMenu (com.github.bordertech.wcomponents.WMenu)23 Test (org.junit.Test)16 WSubMenu (com.github.bordertech.wcomponents.WSubMenu)11 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)5 WText (com.github.bordertech.wcomponents.WText)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WImage (com.github.bordertech.wcomponents.WImage)4 WMenuItemGroup (com.github.bordertech.wcomponents.WMenuItemGroup)4 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)2 Margin (com.github.bordertech.wcomponents.Margin)1 Request (com.github.bordertech.wcomponents.Request)1 TestAction (com.github.bordertech.wcomponents.TestAction)1 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)1 WButton (com.github.bordertech.wcomponents.WButton)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WContent (com.github.bordertech.wcomponents.WContent)1 WContentLink (com.github.bordertech.wcomponents.WContentLink)1 WPanel (com.github.bordertech.wcomponents.WPanel)1