0

onClose on Tab

asked 2010-10-27 15:57:41 +0800

firestorm gravatar image firestorm
9

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

delete flag offensive retag edit

9 Replies

Sort by » oldest newest

answered 2010-10-27 16:48:59 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-10-27 16:52:02 +0800

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

link publish delete flag offensive edit

answered 2010-10-28 10:50:08 +0800

firestorm gravatar image firestorm
9

updated 2010-10-28 12:13:20 +0800

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)

link publish delete flag offensive edit

answered 2010-10-28 14:27:23 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

... tab to loose its selected attribute...

Yes, therefore the next lines. Working by selecting the tab new.

menuTab.setSelected(true);
break;

. . .
event.stopPropagation();

link publish delete flag offensive edit

answered 2010-10-29 07:22:24 +0800

firestorm gravatar image firestorm
9

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

link publish delete flag offensive edit

answered 2010-10-29 16:16:48 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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.

link publish delete flag offensive edit

answered 2010-10-31 14:26:02 +0800

gone gravatar image gone
12

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

link publish delete flag offensive edit

answered 2010-12-15 06:28:55 +0800

luckymax5000 gravatar image luckymax5000
3

Спасибо за ценный пост.

iphone 4 32 gb купить

link publish delete flag offensive edit

answered 2010-12-24 10:28:32 +0800

Inversiones gravatar image Inversiones
3
http://www.HacerFortuna.c...

sorry, this is a test

link publish delete flag offensive edit

answered 2015-05-12 16:01:46 +0800

WilliamB gravatar image WilliamB
1609 1 6

I've the same issue, however I use MVVM. How should I go about this?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2010-10-27 15:57:41 +0800

Seen: 868 times

Last updated: Nov 26 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More