Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334996 - PageBook#showPage(Control) should set all other pages to invisible
Summary: PageBook#showPage(Control) should set all other pages to invisible
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 334966
  Show dependency tree
 
Reported: 2011-01-21 06:45 EST by Markus Keller CLA
Modified: 2011-10-06 04:15 EDT (History)
2 users (show)

See Also:


Attachments
Fix (2.11 KB, patch)
2011-01-21 06:45 EST, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2011-01-21 06:45:25 EST
Created attachment 187273 [details]
Fix

HEAD

PageBook#showPage(Control) should set all other pages to invisible. Currently, only pages that have been explicitly shown before are set to invisible, but controls that have just been created as children of a PageBook have getVisible()==true (but their bounds are not set by the layout).

This is a problem when a focus should be set to the PageBook. In the snippet below, the focus ends up in the Text, because the hidden page is not set to invisible.

This was a real problem in bug 334966, and I will remove the workaround there as soon as this bug has been fixed.

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.PageBook;

public class PageBookSnippet {
	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setSize(320, 200);
		shell.setLayout(new GridLayout());

		final StyledText editor = new StyledText(shell, SWT.BORDER);
		editor.setText("editor");
		editor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		final PageBook pageBook = new PageBook(shell, SWT.NONE);
		pageBook.setLayoutData(new GridData(GridData.FILL_BOTH));

		display.timerExec(1000, new Runnable() {
			public void run() {
				Text text = new Text(pageBook, SWT.BORDER);
				text.setText("Text");

				Table table = new Table(pageBook, SWT.BORDER);
				for (int i = 0; i < 10; i++) {
					new TableItem(table, SWT.NONE).setText("Item " + i);
				}
				table.select(0);

				pageBook.showPage(table);
				pageBook.setFocus();

				editor.setText(display.getFocusControl().toString());
			}
		});

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 1 Markus Keller CLA 2011-01-21 06:46:59 EST
I think the fix is correct, but to get more internal testing, I think it's better to wait with releasing it for after M5.
Comment 2 Markus Keller CLA 2011-02-07 10:51:35 EST
Fixed in HEAD (and reverted bug 334966).
Comment 3 Markus Keller CLA 2011-03-08 10:33:21 EST
Verified in I20110307-2110.
Comment 4 Dani Megert CLA 2011-10-06 04:15:37 EDT
This didn't make it into the 4.x stream. Cherry-picked now:
Commit eab9e01d0609234b09f6b52ef55ed1b67e4f75d9