Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370752

Summary: [Table][Tree] topIndex is out of sync when Table/Tree is resized
Product: [RT] RAP Reporter: Stephan Leicht Vogt <stephan.leichtvogt>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: ivan
Version: 1.5   
Target Milestone: 1.5 M7   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch as described in comment 5 from Ivan none

Description Stephan Leicht Vogt CLA 2012-02-06 13:53:45 EST
When the table changes it's size, the topIndex isn't changed. This results in wrong item lookup by mouse event position (Table.getItem(eventPosition)). 


Overwriting the method setBounds on Table would correct it...

public class Table extends Composite {
...
  @Override
  public void setBounds( Rectangle bounds ) {
    super.setBounds( bounds );
    adjustTopIndex();
  }
...
}

...but I don't think that is the right way, is it?
Comment 1 Ivan Furnadjiev CLA 2012-02-06 14:50:15 EST
Reproducible with Controls Demo -> Table tab:
1. Scroll the table to the end - top item index is 3 (use "Query topIndex" button to check it)
2. Resize the table so that no vertical scrollbar is visible - visually top item is "item 0"
3. Use "Query topIndex" button to check the topIndex again - topIndex is still 3 instead of 0.
Comment 2 Ivan Furnadjiev CLA 2012-02-06 14:56:25 EST
This is valid for the Tree as well - tree topItem is out of sync too. Use the same scenario to reproduce it with Controls Demo -> Tree tab.
Comment 3 Ivan Furnadjiev CLA 2012-02-10 04:47:02 EST
Both Tree and Table have a resize listener where the scrollbars are updated. We could update the top item index there too. For Tree some more work is needed as there is no method to adjust the topItemIndex as in Table.
Comment 4 Ivan Furnadjiev CLA 2012-02-10 05:08:33 EST
Test cases for Table and Tree:
public void testUpdateTopItemIndexAfterResize() {
  Table table = new Table( shell, SWT.NONE );
  table.setSize( 100, 50 );
  createTableItems( table, 5 );
  table.setTopIndex( 1 );

  table.setSize( 100, 200 );
    
  assertEquals( 0, table.getTopIndex() );
}

public void testUpdateTopItemIndexAfterResize() {
  Tree tree = new Tree( composite, SWT.NONE );
  tree.setSize( 100, 50 );
  for( int i = 0; i < 5; i++ ) {
    new TreeItem( tree, SWT.NONE ).setText( "Item " + i );
  }
  tree.setTopItem( tree.getItem( 1 ) );

  tree.setSize( 100, 200 );

  assertEquals( tree.getItem( 0 ), tree.getTopItem() );
}
Comment 5 Ivan Furnadjiev CLA 2012-02-13 04:28:43 EST
The fix is easy for both Tree and Table (adding adjustTopIndex in the resize listener), but it leads to unwanted effect. When TSD takes place, the top index is changed unnecessarily in some cases.
Comment 6 Stephan Leicht Vogt CLA 2012-02-17 07:27:55 EST
Will this fix be commited soon or could I have the patch-file?
Comment 7 Ivan Furnadjiev CLA 2012-02-17 07:40:51 EST
(In reply to comment #6)
> Will this fix be commited soon or could I have the patch-file?
If you want to try it just add adjustTopIndex() in the Table inner ResizeListener class. As this fix brings some other issues (see comment#5) I will keep it out of CVS for now.
Comment 8 Stephan Leicht Vogt CLA 2012-02-17 07:44:17 EST
I'll try it out. But what do you mean by "TSD" and are the "some cases" defined or is it random?
Comment 9 Ivan Furnadjiev CLA 2012-02-17 08:14:56 EST
(In reply to comment #8)
> I'll try it out. But what do you mean by "TSD" and are the "some cases" defined
> or is it random?
TSD = "Text Size Determination". When the TSD take place the Shell is resized to a bigger bounds (+1000). Table is resized too. When you put the adjustTopIndex in the resize listener, it's possible topIndex to be adjusted when Table has these "intermediate" bigger bounds. For example you have a Table with topIndex = 5. During the TSD enlargement (width/height + 1000), the complete table (all rows) become visible and topIndex is adjusted to 0. You have unwanted scrolling of the Table.
Comment 10 Stephan Leicht Vogt CLA 2012-03-01 09:08:41 EST
Created attachment 211876 [details]
Patch as described in comment 5 from Ivan

This patch introduces the change as described by Ivan to the Table and Tree. Additionally it calls also showSelection() to ensure the selected item is visible (don't know if this should really be called, please correct me if wrong).
I'm well aware that this is not the final solution as Ivan stated in comment 9 but if others have also issues with this bug it could be an temporary solution for them.
Comment 11 Ivan Furnadjiev CLA 2012-04-23 01:54:52 EDT
Fixed by adjusting the topIndex/topItem in the notifyResize method. Resize listeners not needed anymore. Changes are in CVS HEAD.