Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Preventing the user from leaving the tab in a CTabFolder
Preventing the user from leaving the tab in a CTabFolder [message #537447] Wed, 02 June 2010 13:38 Go to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
In my application I want the user to save any changes before he leaves a tab (implemented as CTabFolder). Presumably this isn't a rare requirement.

I tried to handle SelectionEvent, but it fires _after_ the tab has been changed (so why does it even have a doit field? Does it fire before change for some other controls?)

Looking on Bugzilla, I've found https://bugs.eclipse.org/bugs/show_bug.cgi?id=193453 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=193064, neither of which is fixed. Are there any workarounds?

[Updated on: Wed, 02 June 2010 17:52]

Report message to a moderator

Re: Preventing the user from leaving the tab in a CTabFolder [message #537516 is a reply to message #537447] Wed, 02 June 2010 17:35 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
before the answer
1.This is not the proper solution.
2.Its heavy.
3.it can be buggy.
4.Finally its fun

/*
 * Browser example snippet: call Java from JavaScript.
 * 
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.5
 */
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolder2Listener;
import org.eclipse.swt.custom.CTabFolderEvent;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet {
	

	protected static boolean allow = false;

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setBounds(10, 10, 300, 200);
		final Button button = new Button(shell, SWT.CHECK);
		button.setText("dont allow");

		final CTabFolder ct = new CTabFolder(shell, SWT.None);
		CTabItem cTabItem = new CTabItem(ct, SWT.None);
		cTabItem.setText("one");
		CTabItem cTabItem2 = new CTabItem(ct, SWT.None);
		cTabItem2.setText("two");
		button.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				allow =button.getSelection();

			}
		});
		display.addFilter(SWT.MouseDown, new Listener() {
			
			@Override
			public void handleEvent(Event event) {
				if(allow && event.widget == ct)
				{
					event.type = SWT.None;
				}
				
			}
		});
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}


you may as well add a message dialog in display.asyncExec telling the user what ever u want in
if(allow && event.widget == ct)
				{
					event.type = SWT.None;
>>>here
				}


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:Any way to draw on Browser object?
Next Topic:Wiggly Mouse Browser Pre-help: Display.readAndDispatch
Goto Forum:
  


Current Time: Thu Aug 22 07:13:35 GMT 2019

Powered by FUDForum. Page generated in 0.01539 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top