DESCRIPTION

Bug 491682 - TableViewerUpdater looses selection if element order isnt
preserved

the same problem occured in the TreeViewerUpdater, but only if an
comparator is set.

Change-Id: I539c8c8f40221762e0e3a42ab203c52f8d92d579
Signed-off-by: June Yoder xxx@xxx.xxx


COMMENTS

author: Zaid Mosley
date: 2016-09-23 11:58:32.000000000

Uploaded patch set 11: Patch Set 10 was rebased.

-------------------------------------
author: Brenden Conley
date: 2016-09-23 11:58:39.000000000

Patch Set 11:

Build Started https://hudson.eclipse.org/platform/job/eclipse.platform.ui-Gerrit/10568/

-------------------------------------
author: Zaid Mosley
date: 2016-09-23 12:09:28.000000000

Patch Set 11:

(1 comment)

Line:80, examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet064TreeViewerReplacingElements.java -> I suggest to added label with an explanation which keys can be pressed and what they do.

-------------------------------------
author: Zaid Mosley
date: 2016-09-23 12:15:35.000000000

Patch Set 11:

(2 comments)

Line:53, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> getStructuredSelection

Line:80, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> getStructuredSelection

-------------------------------------
author: Zaid Mosley
date: 2016-09-23 12:26:45.000000000

Patch Set 11:

(4 comments)

I don't think the patch catches single selection. Try to run this new test case:

public void testTableViewer_ReplacingSelectedItemShouldNotSelectNewItemIfSingleSelection() {
		List<String> input = Arrays.asList("Intellij", "Eclipse", "Netbeans");
		TableViewer tableViewer = new TableViewer(getShell());
		// only with sorter the TableViewerUpdater.replace method delegates to
		// ViewerUpdater.replace:
		tableViewer.setComparator(new ViewerComparator());
		tableViewer.setContentProvider(new ObservableListContentProvider());
		tableViewer.setInput(input);
		tableViewer.getTable().select(1);

		elementsList.set(0, "foo"); // replace "one"
		IStructuredSelection selection = tableViewer.getStructuredSelection();
		Assert.assertEquals("Eclipse", selection.getFirstElement());
		Assert.assertTrue(selection.toList().contains("Eclipse"));
	}

Line:46, examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet064TreeViewerReplacingElements.java -> use lambda

Line:43, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> Wrong method name?We should describe the desired behavior not the wrong one testTableViewer_ReplacingSelectedItemShouldNotSelectsNewItem

Line:58, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> Same as above

Line:63, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> use lambda

-------------------------------------
author: Brenden Conley
date: 2016-09-23 12:28:04.000000000

Patch Set 11: Verified+1

Build Successful 

https://hudson.eclipse.org/platform/job/eclipse.platform.ui-Gerrit/10568/ : SUCCESS

-------------------------------------
author: June Yoder
date: 2016-09-23 19:09:43.000000000

Patch Set 11:

(7 comments)

Line:46, examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet064TreeViewerReplacingElements.java -> Done

Line:80, examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet064TreeViewerReplacingElements.java -> Done

Line:43, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> That is the desired behavior. The new item should be selected.

Line:53, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> Done

Line:58, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> Same as above

Line:63, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> Done

Line:80, tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerUpdaterTest.java -> Done

-------------------------------------
author: June Yoder
date: 2016-09-23 19:14:31.000000000

Patch Set 11:

> (4 comments)
 > 
 > I don't think the patch catches single selection. Try to run this
 > new test case:
 > 
 > public void testTableViewer_ReplacingSelectedItemShouldNotSelectNewItemIfSingleSelection()
 > {
 > List<String> input = Arrays.asList("Intellij", "Eclipse",
 > "Netbeans");
 > TableViewer tableViewer = new TableViewer(getShell());
 > // only with sorter the TableViewerUpdater.replace method delegates
 > to
 > // ViewerUpdater.replace:
 > tableViewer.setComparator(new ViewerComparator());
 > tableViewer.setContentProvider(new ObservableListContentProvider());
 > tableViewer.setInput(input);
 > tableViewer.getTable().select(1);
 > 
 > elementsList.set(0, "foo"); // replace "one"
 > IStructuredSelection selection = tableViewer.getStructuredSelection();
 > Assert.assertEquals("Eclipse", selection.getFirstElement());
 > Assert.assertTrue(selection.toList().contains("Eclipse"));
 > }

The single selection case also works. Because of the ViewerComparator, the line tableViewer.getTable().select(1) selects Intellij and not Eclipse (which is in row 0).

-------------------------------------
author: Gerrit Code Review
date: 2017-05-03 15:50:26.000000000

Change has been successfully merged into the git repository by Zaid Mosley

-------------------------------------
