Search in sources :

Example 1 with WSubMenu

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

the class MenuBarExample method buildMenuBar.

/**
 * Builds up a menu bar for inclusion in the example.
 *
 * @param selectedMenuText the WText to display the selected menu item.
 * @return a menu bar for the example.
 */
private WMenu buildMenuBar(final WText selectedMenuText) {
    WMenu menu = new WMenu();
    // The Colours menu just shows simple text
    WSubMenu colourMenu = new WSubMenu("Colours");
    colourMenu.setMode(WSubMenu.MenuMode.LAZY);
    colourMenu.setAccessKey('C');
    addMenuItem(colourMenu, "Red", selectedMenuText);
    addMenuItem(colourMenu, "Green", selectedMenuText);
    addMenuItem(colourMenu, "Blue", selectedMenuText);
    colourMenu.addSeparator();
    colourMenu.add(new WMenuItem("Disable colour menu", new ToggleDisabledAction(colourMenu)));
    menu.add(colourMenu);
    // The Shapes menu shows grouping of items
    WSubMenu shapeMenu = new WSubMenu("Shapes");
    shapeMenu.setAccessKey('S');
    addMenuItem(shapeMenu, "Circle", selectedMenuText);
    WMenuItemGroup triangleGroup = new WMenuItemGroup("Triangles");
    shapeMenu.add(triangleGroup);
    shapeMenu.setMode(WSubMenu.MenuMode.DYNAMIC);
    addMenuItem(triangleGroup, "Equilateral", selectedMenuText);
    addMenuItem(triangleGroup, "Isosceles", selectedMenuText);
    addMenuItem(triangleGroup, "Scalene", selectedMenuText);
    addMenuItem(triangleGroup, "Right-angled", selectedMenuText);
    addMenuItem(triangleGroup, "Obtuse", selectedMenuText);
    WMenuItemGroup quadGroup = new WMenuItemGroup("Quadrilaterals");
    shapeMenu.add(quadGroup);
    addMenuItem(quadGroup, "Square", selectedMenuText);
    addMenuItem(quadGroup, "Rectangle", selectedMenuText);
    addMenuItem(quadGroup, "Rhombus", selectedMenuText);
    addMenuItem(quadGroup, "Trapezoid", selectedMenuText);
    addMenuItem(quadGroup, "Parallelogram", selectedMenuText);
    shapeMenu.addSeparator();
    shapeMenu.add(new WMenuItem("Disable shape menu", new ToggleDisabledAction(shapeMenu)));
    menu.add(shapeMenu);
    // The Image menu shows use of decorated labels and images
    WDecoratedLabel imageLabel = new WDecoratedLabel(new WImage("/image/wrench.png", "spanner"), new WText("Images"), null);
    WSubMenu imageMenu = new WSubMenu(imageLabel);
    imageMenu.add(createImageMenuItem("/image/flag.png", "Flag", "eg-menu-image-1", selectedMenuText));
    imageMenu.add(createImageMenuItem("/image/attachment.png", "Attachment", "eg-menu-image-2", selectedMenuText));
    imageMenu.add(createImageMenuItem("/image/settings.png", "Settings", "eg-menu-image-3", selectedMenuText));
    imageMenu.addSeparator();
    imageMenu.add(new WMenuItem("Disable image menu", new ToggleDisabledAction(imageMenu)));
    menu.add(imageMenu);
    WSubMenu sitesMenu = new WSubMenu("External apps");
    sitesMenu.add(new WMenuItem("External website", "http://www.example.com/"));
    WMenuItem google = new WMenuItem("Example (new window)", "http://www.example.com/");
    google.setTargetWindow("exampleWindow");
    sitesMenu.add(google);
    menu.add(sitesMenu);
    // Add an item to toggle the states of all the menus
    menu.add(new WMenuItem("Toggle top-level menus", new ToggleDisabledAction(colourMenu, shapeMenu, imageMenu, sitesMenu)));
    menu.add(new WMenuItem("Link", "http://www.example.com"));
    menu.add(new WMenuItem("No Action"));
    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);
    WMenuItem itemWithImage = new WMenuItem(new WDecoratedLabel(new WImage("/image/home.png", "home"), new WText("Home"), null));
    menu.add(itemWithImage);
    menu.add(new WMenuItem(new WDecoratedLabel(new WImage("/image/settings.png", "settings"), new WText("Settings Menu"), null)));
    itemWithImage = new WMenuItem(new WDecoratedLabel(new WImage("/image/flag.png", "flag")));
    itemWithImage.setAccessibleText("flag this view");
    menu.add(itemWithImage);
    return menu;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenuItemGroup(com.github.bordertech.wcomponents.WMenuItemGroup) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMenu(com.github.bordertech.wcomponents.WMenu) WImage(com.github.bordertech.wcomponents.WImage) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 2 with WSubMenu

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

the class MenuFlyoutExample method addMenuItem.

/**
 * Adds an example menu item with the given text and an example action to the a parent component.
 *
 * @param parent the component to add the menu item to.
 * @param text the text to display on the menu item.
 * @param selectedMenuText the WText to display the selected menu item.
 */
private void addMenuItem(final WComponent parent, final String text, final WText selectedMenuText) {
    WMenuItem menuItem = new WMenuItem(text, new ExampleMenuAction(selectedMenuText));
    menuItem.setActionObject(text);
    if (parent instanceof WSubMenu) {
        ((WSubMenu) parent).add(menuItem);
    } else {
        ((WMenuItemGroup) parent).add(menuItem);
    }
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItemGroup(com.github.bordertech.wcomponents.WMenuItemGroup)

Example 3 with WSubMenu

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

the class TreeMenuExample method mapTreeHierarchy.

/**
 * Recursively maps a tree hierarchy to a hierarchical 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 mapTreeHierarchy(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);
        if (currentComponent instanceof WMenu) {
            ((WMenu) currentComponent).add(subMenu);
        } else {
            ((WSubMenu) currentComponent).add(subMenu);
        }
        // Expand the first couple of levels in the tree by default.
        if (currentNode.getLevel() < 2) {
            subMenu.setOpen(true);
        }
        for (Iterator<TreeNode> i = currentNode.children(); i.hasNext(); ) {
            mapTreeHierarchy(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)

Example 4 with WSubMenu

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

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

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