PDA

View Full Version : TabItem close listener



dato.java
8 Apr 2011, 4:02 AM
Hello,

I have several tabs and need to do some action when tab is being closed,but it does not work,i dont know why



TabItem ti = new TabItem(id);
ti.setClosable(true);

ti.addListener(Events.Close, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent arg0) {
com.google.gwt.user.client.Window.alert("");
}

});

tabPanel.add(ti);


I use EXT GWT 2.2.3 and GWT 2.2.1 version

chalu
8 Apr 2011, 6:17 AM
Set Events.BeforeRemove listener on the TabPanel, Try this instead :



tabPanel.addListener(Events.BeforeRemove, new Listener<TabPanelEvent>() {
@Override
public void handleEvent(TabPanelEvent evt) {
if(true){ // U decide what this condition should be
evt.setCancelled(true);
}
}
});

daddieke
8 Apr 2011, 6:18 AM
The containing component can detect closing of the tabitem or rather the event before removal from the tabpanel. My code is something like :



public void handleEvent(BaseEvent be) {
try {
if (be instanceof TabPanelEvent && be.getType() == Events.BeforeRemove) {
TabItem tabItem = ((TabPanelEvent) be).getItem();
// do your thing
}
}
catch (Exception e) {
// exception handling code
}
}

liondev
8 Apr 2011, 12:52 PM
BeforeClose : TabPanelEvent(tabPanel, item)
Fires before an item is closed by the user clicking the close icon. Listeners can cancel the action by calling BaseEvent.

You should see the API ;)

dato.java
11 Apr 2011, 1:50 AM
Thank you guys ,it works now :)