" RootPanel rootPanel = RootPanel.get();",
" MenuBar bar = new MenuBar();",
" rootPanel.add(bar);",
" }",
"}");
MenuBarInfo bar = getJavaInfoByName("bar");
IMenuInfo barObject = MenuObjectInfoUtils.getMenuInfo(bar);
IMenuPolicy policy = barObject.getPolicy();
// don't accept something other than MenuItem
assertFalse(policy.validateCreate(new Object()));
// create new MenuItem
MenuItemInfo newItem = createJavaInfo("com.google.gwt.user.client.ui.MenuItem", "withSubMenu");
assertTrue(policy.validateCreate(newItem));
policy.commandCreate(newItem, null);
assertEditor(
"public class Test implements EntryPoint {",
" public void onModuleLoad() {",
" RootPanel rootPanel = RootPanel.get();",
" MenuBar bar = new MenuBar();",
" rootPanel.add(bar);",
" {",
" MenuBar menuBar = new MenuBar(true);",
" MenuItem menuItem = new MenuItem('New menu', false, menuBar);",
" bar.addItem(menuItem);",
" }",
" }",
"}");
assertHierarchy(
"{RootPanel.get()} {local-unique: rootPanel} {/RootPanel.get()/ /rootPanel.add(bar)/}",
" {new: com.google.gwt.user.client.ui.MenuBar} {local-unique: bar} {/new MenuBar()/ /rootPanel.add(bar)/ /bar.addItem(menuItem)/}",
" {new: com.google.gwt.user.client.ui.MenuItem withSubMenu} {local-unique: menuItem} {/new MenuItem('New menu', false, menuBar)/ /bar.addItem(menuItem)/}",
" {new: com.google.gwt.user.client.ui.MenuBar vertical} {local-unique: menuBar} {/new MenuBar(true)/ /new MenuItem('New menu', false, menuBar)/}");
{
MenuBarInfo subMenu = newItem.getSubMenu();
Association association = subMenu.getAssociation();
assertInstanceOf(ConstructorChildAssociation.class, association);
assertEquals("new MenuItem(\"New menu\", false, menuBar)", association.getSource());
assertSame(subMenu, association.getJavaInfo());
}
}