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 and, 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. can be buggy.
4.Finally its fun

 * Browser example snippet: call Java from JavaScript.
 * For a list of all SWT example snippets see
 * @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.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 cTabItem2 = new CTabItem(ct, SWT.None);
		button.addSelectionListener(new SelectionAdapter() {

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

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


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;

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

Current Time: Wed Dec 11 19:22:59 GMT 2019

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

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

Back to the top