Search in sources :

Example 11 with WMenuItem

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

the class WMenuRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WMenu menu = new WMenu();
    menu.add(new WMenuItem(""));
    assertSchemaMatch(menu);
    assertXpathExists("//ui:menu/@id", menu);
    assertXpathEvaluatesTo(menu.getId(), "//ui:menu/@id", menu);
    assertXpathEvaluatesTo("bar", "//ui:menu/@type", menu);
    assertXpathNotExists("//ui:menu/@disabled", menu);
    assertXpathNotExists("//ui:menu/@selectMode", menu);
    assertXpathExists("//ui:menu/ui:menuitem", menu);
    assertXpathNotExists("//ui:menu/ui:separator", menu);
    menu.addSeparator();
    assertSchemaMatch(menu);
    assertXpathExists("//ui:menu/ui:separator", menu);
    menu.setDisabled(true);
    setFlag(menu, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("true", "//ui:menu/@disabled", menu);
    assertXpathEvaluatesTo("true", "//ui:menu/@hidden", menu);
    menu.setSelectMode(SelectMode.SINGLE);
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("single", "//ui:menu/@selectMode", menu);
    menu.setSelectMode(SelectMode.MULTIPLE);
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("multiple", "//ui:menu/@selectMode", menu);
    menu.setRows(1);
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("1", "//ui:menu/@rows", menu);
    menu = new WMenu(WMenu.MenuType.FLYOUT);
    menu.add(new WMenuItem(""));
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("flyout", "//ui:menu/@type", menu);
    menu = new WMenu(WMenu.MenuType.TREE);
    menu.add(new WMenuItem(""));
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("tree", "//ui:menu/@type", menu);
    menu = new WMenu(WMenu.MenuType.COLUMN);
    menu.add(new WMenuItem(""));
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("column", "//ui:menu/@type", menu);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 12 with WMenuItem

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

the class WSubMenuRenderer_Test method testOpenTree.

@Test
public void testOpenTree() throws IOException, SAXException, XpathException {
    menu = new WMenu(WMenu.MenuType.TREE);
    subMenu = new WSubMenu("SubMenu");
    menu.add(subMenu);
    subMenu.add(new WMenuItem("Item"));
    subMenu.setOpen(true);
    assertSchemaMatch(menu);
    assertXpathEvaluatesTo("true", "//ui:submenu/@open", menu);
    assertXpathEvaluatesTo("true", "//ui:submenu/@open", menu);
}
Also used : WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 13 with WMenuItem

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

the class WSubMenuRenderer_Test method before.

@Before
public void before() {
    menu = new WMenu();
    subMenu = new WSubMenu(SUB_MENU_TEXT);
    menu.add(subMenu);
    subMenu.add(new WMenuItem("Item"));
}
Also used : WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Before(org.junit.Before)

Example 14 with WMenuItem

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

the class ColumnMenuExample method buildColumnMenu.

/**
 * Builds up a column menu for inclusion in the example.
 *
 * @param selectedMenuText the WText to display the selected menu.
 * @return a column menu for the example.
 */
private WMenu buildColumnMenu(final WText selectedMenuText) {
    WMenu menu = new WMenu(WMenu.MenuType.COLUMN);
    menu.setSelectMode(SelectMode.SINGLE);
    menu.setRows(8);
    StringTreeNode root = getOrgHierarchyTree();
    mapColumnHierarchy(menu, root, selectedMenuText);
    // Demonstrate different menu modes
    getSubMenuByText("Australia", menu).setAccessKey('A');
    getSubMenuByText("NSW", menu).setMode(MenuMode.CLIENT);
    getSubMenuByText("Branch 1", menu).setMode(MenuMode.DYNAMIC);
    getSubMenuByText("VIC", menu).setMode(MenuMode.LAZY);
    WMenuItem itemWithIcon = new WMenuItem("Help");
    itemWithIcon.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // do something
        }
    });
    itemWithIcon.setHtmlClass(HtmlClassProperties.ICON_HELP_BEFORE);
    menu.add(itemWithIcon);
    return menu;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMenu(com.github.bordertech.wcomponents.WMenu)

Example 15 with WMenuItem

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

the class ColumnMenuExample method mapColumnHierarchy.

/**
 * Recursively maps a tree hierarchy to a column menu.
 *
 * @param currentComponent the current component in the menu.
 * @param currentNode the current node in the tree.
 * @param selectedMenuText the WText to display the selected menu item.
 */
private void mapColumnHierarchy(final WComponent currentComponent, final StringTreeNode currentNode, final WText selectedMenuText) {
    if (currentNode.isLeaf()) {
        WMenuItem menuItem = new WMenuItem(currentNode.getData(), new ExampleMenuAction(selectedMenuText));
        menuItem.setActionObject(currentNode.getData());
        if (currentComponent instanceof WMenu) {
            ((WMenu) currentComponent).add(menuItem);
        } else {
            ((WSubMenu) currentComponent).add(menuItem);
        }
    } else {
        WSubMenu subMenu = new WSubMenu(currentNode.getData());
        subMenu.setSelectMode(SelectMode.SINGLE);
        subMenu.setSelectable(false);
        subMenu.setAction(new ExampleMenuAction(selectedMenuText));
        subMenu.setActionObject(currentNode.getData());
        if (currentComponent instanceof WMenu) {
            ((WMenu) currentComponent).add(subMenu);
        } else {
            ((WSubMenu) currentComponent).add(subMenu);
        }
        // Expand the first level in the tree by default.
        if (currentNode.getLevel() == 0) {
            subMenu.setOpen(true);
        }
        for (Iterator<TreeNode> i = currentNode.children(); i.hasNext(); ) {
            mapColumnHierarchy(subMenu, (StringTreeNode) i.next(), selectedMenuText);
        }
    }
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) WMenu(com.github.bordertech.wcomponents.WMenu)

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