I have an issue : Several tabs, one new is opened and after some activity in it, it is closed. The problem is that I also have TabSelectedHandler
s on every Tab
and they are executed not only onTabSelected
, but also upon remove (and this happens to be a problem). When removing the last Tab, the prevoius one is being selected. How to avoid this and do only remove? Here is example of the code:
Tab existingTab0 = new Tab("Static tab 0");
existingTab0.setID("0");
existingTab0.addTabSelectedHandler(new TabSelectedHandler () {
public void onTabSelected(final TabSelectedEvent event) {
// do stuff 0
}
});
Tab existingTab1 = new Tab("Static tab 1");
existingTab1.setID("1");
existingTab1.addTabSelectedHandler(new TabSelectedHandler () {
public void onTabSelected(final TabSelectedEvent event) {
// do stuff 1
}
});
Tab dynamicTab = new Tab("Dynamic tab");
dynamicTab.setID("2");
dynamicTab.addTabSelectedHandler(new TabSelectedHandler () {
public void onTabSelected(final TabSelectedEvent event) {
// do stuff 2
}
});
TabSet tabSet = new TabSet();
tabSet.addTab(existingTab0);
tabSet.addTab(existingTab1);
tabSet.addTab(dynamicTab);
// upon a specific case I need to remove dynamicTab
tabSet.removeTab(dynamicTab); // forces onTabSelected method for Static tab 1 to be fired and does stuff 1 and this should NOT happen here
Any ideas of a workaround? Thanks in advance.
You can get the HandlerRegistration
returned by addTabSelectedHandler
method and use it to remove the handler when you want to get rid of your dynamicTab and before invoking the removeTab
method.