Search in sources :

Example 6 with WMenuItemGroup

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

the class MenuFlyoutExample method buildMenu.

/**
 * Builds up a menu bar for inclusion in the example.
 *
 * @param selectedMenuText the WText to display the selected menu item.
 * @return a menu for the example.
 */
private WMenu buildMenu(final WText selectedMenuText) {
    WMenu menu = new WMenu(WMenu.MenuType.FLYOUT);
    // The Colours menu just shows simple text
    WSubMenu colourMenu = new WSubMenu("Colours");
    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");
    addMenuItem(shapeMenu, "Circle", selectedMenuText);
    WMenuItemGroup triangleGroup = new WMenuItemGroup("Triangles");
    shapeMenu.add(triangleGroup);
    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
    WSubMenu imageMenu = new WSubMenu("Images");
    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("Example 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"));
    return menu;
}
Also used : WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenuItemGroup(com.github.bordertech.wcomponents.WMenuItemGroup) WMenu(com.github.bordertech.wcomponents.WMenu)

Example 7 with WMenuItemGroup

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

the class WMenuItemGroupRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    String groupName = "WMenuItemGroupRenderer_Test.testDoPaint.groupName";
    WMenuItemGroup menuGroup = new WMenuItemGroup(groupName);
    WComponent wrapped = wrapMenuGroup(menuGroup);
    setActiveContext(createUIContext());
    assertXpathExists("//ui:menugroup", wrapped);
    assertXpathEvaluatesTo(groupName, "normalize-space(//ui:menugroup/ui:decoratedlabel)", wrapped);
    assertXpathEvaluatesTo(menuGroup.getId(), "//ui:menugroup/@id", wrapped);
    assertXpathNotExists("//ui:menugroup/ui:submenu", wrapped);
    assertXpathNotExists("//ui:menugroup/ui:menuitem", wrapped);
    assertXpathNotExists("//ui:menugroup/ui:separator", wrapped);
    menuGroup.addSeparator();
    assertXpathExists("//ui:menugroup/ui:separator", wrapped);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WMenuItemGroup(com.github.bordertech.wcomponents.WMenuItemGroup) Test(org.junit.Test)

Aggregations

WMenuItemGroup (com.github.bordertech.wcomponents.WMenuItemGroup)7 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)4 WSubMenu (com.github.bordertech.wcomponents.WSubMenu)4 WMenu (com.github.bordertech.wcomponents.WMenu)2 Test (org.junit.Test)2 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)1 WImage (com.github.bordertech.wcomponents.WImage)1 WText (com.github.bordertech.wcomponents.WText)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1