updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PMenuBar subMenuBar = new PMenuBar();
subMenuBar.addItem("SubItem1");
subMenuBar.addItem("SubItem2");
subMenuBar.addItem("SubItem3", new PTestCommand(eventsListener, "Click on SubItem3"));
subMenuBar.ensureDebugId("subMenuBar1");
final PMenuBar menuBar1 = new PMenuBar();
menuBar1.ensureDebugId("menuBar1");
menuBar1.addItem("Item 1");
menuBar1.addItem("Item 2", new PTestCommand(eventsListener, "Click on command 2"));
menuBar1.addItem("Item 3 with <font color='red'>html</font>", true, new PTestCommand(eventsListener, "Click on command 3"));
menuBar1.addItem("SubMenu", subMenuBar);
PRootPanel.get().add(menuBar1);
register(menuBar1);
register(subMenuBar);
}
});
WebElement menuBar = findElementById("menuBar1");
List<WebElement> elements = menuBar.findElements(By.tagName("td"));
Assert.assertEquals(4, elements.size());
Assert.assertEquals("Item 1", elements.get(0).getText());
Assert.assertEquals("Item 2", elements.get(1).getText());
Assert.assertEquals("Item 3 with html", elements.get(2).getText());
Assert.assertEquals("SubMenu", elements.get(3).getText());
final WebElement font = elements.get(2).findElement(By.tagName("font"));
Assert.assertEquals("red", font.getAttribute("color"));
elements.get(1).click();
PTestEvent e1 = eventsListener.poll();
Assert.assertEquals("Click on command 2", e1.getBusinessMessage());
elements.get(2).click();
e1 = eventsListener.poll();
Assert.assertEquals("Click on command 3", e1.getBusinessMessage());
elements.get(3).click();
WebElement subMenuBar1 = findElementById("subMenuBar1");
elements = subMenuBar1.findElements(By.tagName("td"));
Assert.assertEquals(3, elements.size());
elements.get(2).click();
e1 = eventsListener.poll();
Assert.assertEquals("Click on SubItem3", e1.getBusinessMessage());
// clear
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PMenuBar subMenuBar = get("subMenuBar1");
subMenuBar.clearItems();
subMenuBar.addItem("SubItem4");
}
});
// open sub menubar
menuBar = findElementById("menuBar1");