Community
Participate
Working Groups
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 ) ); }
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() ); }
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.
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.
Created attachment 162909 [details] Patch with ListModel fitting the ListModel_Test requirements The JUnit tests now run successfully.
*** Bug 310799 has been marked as a duplicate of this bug. ***
Maybe CCombo is affected too. JUnit tests are needed for CCombo too.
I confirm that with my app, CCombo and ComboViewer has also this problem.
Applied patch to ListModel with some changes. Fixed Combo and CCombo problem in a different way. Changes are in CVS HEAD.