public void onRequest() {
final PLabel tab2Label = new PLabel("tab 2");
tab2Label.ensureDebugId("tab2Label");
final PHTML tab3Label = new PHTML("tab <font color='red'>3</font>");
final PTabPanel tabPanel1 = new PTabPanel();
tabPanel1.add(new PLabel("content 1"), "tab 1");
tabPanel1.add(new PLabel("content 2"), tab2Label);
tabPanel1.add(new PLabel("content 3"), tab3Label);
tabPanel1.addBeforeSelectionHandler(eventsListener);
tabPanel1.addSelectionHandler(eventsListener);
tabPanel1.ensureDebugId("tabPanel1");
PRootPanel.get().add(tabPanel1);
register(tabPanel1);
}
});
WebElement tabPanel1Bar = findElementById("tabPanel1-bar");
List<WebElement> tabBarElements = tabPanel1Bar.findElements(By.tagName("td"));
Assert.assertEquals(5, tabBarElements.size()); // 3 +(start+end);
Assert.assertEquals("tab 1", tabBarElements.get(1).getText());
Assert.assertEquals("tab 2", tabBarElements.get(2).getText());
Assert.assertEquals("tab 3", tabBarElements.get(3).getText());
final WebElement fontElement = tabBarElements.get(3).findElement(By.tagName("font"));
Assert.assertEquals("red", fontElement.getAttribute("color"));
final PTabPanel ptabPanel1 = get("tabPanel1");
Assert.assertEquals(3, ptabPanel1.getWidgetCount());
final PSelectionEvent<Integer> sa = eventsListener.poll();
Assert.assertEquals(new Integer(0), sa.getSelectedItem());
// add / remove
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PTabPanel tabPanel1 = get("tabPanel1");
tabPanel1.remove(2);
tabPanel1.insert(new PLabel("content 1.5"), "tab 1.5", 1);
}
});
tabPanel1Bar = findElementById("tabPanel1-bar");
tabBarElements = tabPanel1Bar.findElements(By.tagName("td"));
Assert.assertEquals(5, tabBarElements.size()); // 3 +(start+end);
Assert.assertEquals(5, tabBarElements.size()); // 3 +(start+end);
Assert.assertEquals("tab 1", tabBarElements.get(1).getText());
Assert.assertEquals("tab 1.5", tabBarElements.get(2).getText());
Assert.assertEquals("tab 2", tabBarElements.get(3).getText());
Assert.assertEquals(null, ptabPanel1.getSelectedItemIndex());
final WebElement tab2Label = findElementById("tab2Label");
tab2Label.click();
final PBeforeSelectionEvent<Integer> s0 = eventsListener.poll();
Assert.assertEquals(new Integer(2), s0.getSelectedItem());
final PSelectionEvent<Integer> s1 = eventsListener.poll();
Assert.assertEquals(new Integer(2), s1.getSelectedItem());
// server-side selection
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PTabPanel tabPanel1 = get("tabPanel1");
tabPanel1.selectTab(1);
}
});
tabPanel1Bar = findElementById("tabPanel1-bar");
Assert.assertEquals(new Integer(1), ptabPanel1.getSelectedItemIndex());