public class TabSelectionRevertedByServer extends AbstractTestUI {
@Override
protected void setup(VaadinRequest request) {
final TabSheet tabsheet = new TabSheet();
tabsheet.setWidth("400px");
Component lastLabel = null;
for (int i = 1; i <= 5; i++) {
String caption = "Tab " + i;
Label label = new Label(caption);
tabsheet.addTab(label, caption);
lastLabel = label;
}
tabsheet.setSelectedTab(0);
final Component lastTab = lastLabel;
tabsheet.addSelectedTabChangeListener(new SelectedTabChangeListener() {
@Override
public void selectedTabChange(SelectedTabChangeEvent event) {
if (tabsheet.getSelectedTab().equals(lastTab)) {
// Set focus back to first tab in tabsheet
tabsheet.setSelectedTab(0);
Notification.show("Focus set back to tab at position 0");
}
}
});
addComponent(tabsheet);
addButton("Select Last Tab", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
tabsheet.setSelectedTab(lastTab);
}
});
}