-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi folks,
Is there a way to handle the onClose event on a Tab in order to validate whether or not the tabpanel should be closed.
I.e : If the tabpanel is containing some data that were not saved yet, in this case I want to prevent the tab to be closed and inform the user...
Thanks
That's the way i work:
In our case we set the Tab-ID dynamically, so we must get them first to catch the onClose event.
If you have a fixed name you don't need that.
... extends GenericForwardComposer ... . . . // the menu created Tab for this module window private Tab menuTab; . . . @Override public void doAfterCompose(Component window) throws Exception { super.doAfterCompose(window); . . . /** * Get the menu-created Tab for this module and add the EventListener * for 'onClose' because by onClose we will check if their are unsaved * data. The menuTab have a programatically created ID from the * menuController.<br> * i.e. 'tab_' + Labels.getLabel("menu.items.Orders")= 'tab_Auftraege'. */ Component cmp = (Component) windowSupplierMain.getParent().getParent().getParent(); String menuName = "tab_" + Labels.getLabel("menu.Item.Suppliers").trim(); menuTab = (Tab) cmp.getFellowIfAny(menuName, false); menuTab.addEventListener("onClose", new EventListener() { @Override public void onEvent(Event event) throws Exception { doClose(event); } }); . . . }
.
/** * When the Tab is closed.<br> * We check if their are unsaved data by comparing the selectedBean's data * with the originalBean's data. * * @param event * @throws InterruptedException */ public void doClose(Event event) throws InterruptedException { // check if data is changed if (isDataChanged()) { // Show a confirm box final String msg = Labels.getLabel("message_Data_Modified_Save_Data_YesNo"); final String title = Labels.getLabel("message.Information"); MultiLineMessageBox.doSetTemplate(); if (MultiLineMessageBox.show(msg, title, MultiLineMessageBox.YES | MultiLineMessageBox.NO | MultiLineMessageBox.CANCEL, MultiLineMessageBox.QUESTION, true, new EventListener() { @Override public void onEvent(Event evt) { switch (((Integer) evt.getData()).intValue()) { case MultiLineMessageBox.YES: doSave(evt); menuTab.onClose(); case MultiLineMessageBox.NO: menuTab.onClose(); case MultiLineMessageBox.CANCEL: menuTab.setSelected(true); tabSupplierAddress.setSelected(true); break; } } } ) == MultiLineMessageBox.YES) { } event.stopPropagation(); } }
best
Stephan
I already tried the event.stopPropagation() technique.
In 5.0.4 version, it successfully prevent the tab to be closed but it seem that there is a client side effect that make the "not closed" tab to loose its selected attribute. The next tab is then selected, as if the tab has been closed normally.
EDIT : Ok I see that you allow the tab to be close anyway. I was looking for a way to completely stop the tab from closing in some situation (i.e.: when a complex action from user is required before saving)
... tab to loose its selected attribute...
Yes, therefore the next lines. Working by selecting the tab new.
menuTab.setSelected(true); break; . . . event.stopPropagation();
There was a bug, which will be fixed in the 5.0.5 version :
http://sourceforge.net/tracker/?func=detail&aid=3081315&group_id=152762&atid=785191
Ahhh good. I'm not up to date. Thanks for the hint.
Hope they can fixed the order of Buttons in a MessageBox too, in the same release.
My some friends have informed me that I become so troubling. I have been making decision over termite control for my family for ages. And so what I want to say that the article comes across so many options to people as I've had
sorry, this is a test
Asked: 2010-10-27 15:57:41 +0800
Seen: 868 times
Last updated: Nov 26 '18