Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 294609 - [List] isSelected fails with duplicate list items
Summary: [List] isSelected fails with duplicate list items
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.5 M7   Edit
Assignee: Ralf Zahn CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 310799 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-11-09 09:45 EST by Benjamin Muskalla CLA
Modified: 2012-04-11 08:24 EDT (History)
2 users (show)

See Also:


Attachments
2 Bugfixes within 1 patch (7.50 KB, patch)
2010-02-25 15:47 EST, Ralf Zahn CLA
no flags Details | Diff
Updated patch (7.53 KB, patch)
2010-03-03 11:49 EST, Rüdiger Herrmann CLA
no flags Details | Diff
Patch with ListModel fitting the ListModel_Test requirements (7.57 KB, patch)
2010-03-24 15:44 EDT, Ralf Zahn CLA
ivan: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Muskalla CLA 2009-11-09 09:45:43 EST
If you have duplicate items in a List selected, the isSelected method fails to return the correct selection state. The selection is correctly send to the client (all 3 items selected) but the isSelected method doesn't recognize it.

  public void testIsSelected() throws Exception {
    Display display = new Display();
    Shell shell = new Shell( display );
    List list = new List( shell, SWT.MULTI );
    String[] items = { "text1", "text2", "text2" }; // two identical
    list.setItems( items );
    list.setSelection( items );
    assertTrue( list.isSelected( 0 ) );
    assertTrue( list.isSelected( 1 ) );
    assertTrue( list.isSelected( 2 ) );
  }
Comment 1 Benjamin Muskalla CLA 2009-11-09 13:32:17 EST
Here is another testcase for Combo which suffers from the same problem if you have multiple items with the same text. Not sure but it sounds like a common problem with our ListModel.

  public void testSelectionIndex() throws Exception {
    Display display = new Display();
    Shell shell = new Shell( display, SWT.NONE );
    final Combo combo = new Combo( shell, SWT.NONE );
    combo.add( "test" );
    combo.add( "test" );
    combo.add( "test" );
    assertEquals(-1, combo.getSelectionIndex());
    combo.select( 0 );
    assertEquals( 0, combo.getSelectionIndex() );
    combo.select( 1 );
    assertEquals( 1, combo.getSelectionIndex() );
    combo.select( 2 );
    assertEquals( 2, combo.getSelectionIndex() );
  }
Comment 2 Ralf Zahn CLA 2010-02-25 15:47:31 EST
Created attachment 160239 [details]
2 Bugfixes within 1 patch

The bug was in the setSelection(String[]) method of the ListModel. I fixed it.
The second bug was a bug within the Combo#setText(String) method, not a bug of the ListModel. I fixed it too.
Comment 3 Rüdiger Herrmann CLA 2010-03-03 11:49:49 EST
Created attachment 160803 [details]
Updated patch

I had a look at the patch and adjusted it to fit the coding conventions:
* I simplyfied to fix for the ListMode (hopefully not breaking it).
* The fix for the ListModel introduces a regression (see the failing test case in ListModel_Test). 
* I haven't ahd a look at the fix for the Combo-problem so far.
Please use this patch as a basis for further development.
Comment 4 Ralf Zahn CLA 2010-03-24 15:44:10 EDT
Created attachment 162909 [details]
Patch with ListModel fitting the ListModel_Test requirements

The JUnit tests now run successfully.
Comment 5 Ivan Furnadjiev CLA 2010-04-28 07:56:00 EDT
*** Bug 310799 has been marked as a duplicate of this bug. ***
Comment 6 Ivan Furnadjiev CLA 2010-04-28 07:58:49 EDT
Maybe CCombo is affected too. JUnit tests are needed for CCombo too.
Comment 7 Wen Ai CLA 2010-04-28 08:09:15 EDT
I confirm that with my app, CCombo and ComboViewer has also this problem.
Comment 8 Ivan Furnadjiev CLA 2012-04-11 08:24:09 EDT
Applied patch to ListModel with some changes. Fixed Combo and CCombo problem in a different way. Changes are in CVS HEAD.