Bug 81264 - Table fails to setTopIndex after new items are added to the table
Summary: Table fails to setTopIndex after new items are added to the table
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux-GTK
: P3 critical (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Billy Biggs CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 74559
  Show dependency tree
 
Reported: 2004-12-15 13:17 EST by Samantha Chan CLA
Modified: 2006-04-12 13:22 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samantha Chan CLA 2004-12-15 13:17:42 EST
I am working on a table viewer that keeps track of the scroll bar and loads
content into the table dynamically as the user scrolls to the end of the table.
 Items could be added/removed from the table as the user scrolls.

To maintain the position of the table, I call setTopIndex at the end of the update.

I have created a small testcase to simulate the process.

Here's my testcase to demonstrate the problem:

	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		shell.setBounds(10,10,200,200);
		final Table table = new Table(shell, SWT.NONE);
		table.setBounds(10,10,100,100);
		for (int i = 0; i < 99; i++) {
			new TableItem(table, SWT.NONE).setText("item " + i);
		}
		
		table.setTopIndex(20);

		shell.open();

		System.out.println("top visible index: " + table.getTopIndex());
		
		for (int i = 0; i < 5; i++) {
			new TableItem(table, SWT.NONE).setText("item " + i);
		}

		table.setTopIndex(40);
		System.out.println("top visible index: " + table.getTopIndex());
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}

Table.setTopIndex fails to position to the correct table item if new items are 
added to the table after the shell is opened.

The first call to setTopIndex succeeds.  The table is correctly positioned at
item 20.  After adding new table items to the table, calling setTopTable(40) has
no effect. Calling getTopIndex continues to return 20.

Expected Result:
Calling setTopIndex(40) should move table item #40 to the top of the table.
Calling getTopIndex after should return 40.

If the last 5 items are added before the shell is opened, setTopIndex to 40 will
also succeed.

The testcase works as expected on Windows.
Comment 1 Steve Northover CLA 2005-01-12 12:04:42 EST
Billy, I believe this is a dup ...
Comment 2 Billy Biggs CLA 2005-01-20 16:25:16 EST
I can reproduce this problem using GtkTreeView.  Running an event loop after
adding items to the table works around the problem.  I filed the following bug
upstream:

  http://bugzilla.gnome.org/show_bug.cgi?id=164749
Comment 3 Samantha Chan CLA 2005-03-11 17:22:26 EST
Hi Billy -

Again, is it possible to force the setTopIndex to take effect without running
the event loop?

Thanks
Samantha
Comment 4 Veronika Irvine CLA 2006-04-06 10:53:16 EDT
Fixed in HEAD for 3.2 RC1.