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);
}
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);
}
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"));
}
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;
}
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);
}
}
}
Aggregations