Home » Eclipse Projects » JFace » TableViewer Sorting and MultiSelectionBinding(Faulty multi selection binding after sorting a column )
TableViewer Sorting and MultiSelectionBinding [message #1067751] |
Wed, 10 July 2013 12:50 |
Ralf Heilek Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hello,
i am using the databinding framework to bind TableViewers to ObservableLists. The bidirectional binding from viewer to model works fine but the bidirectional binding from multi-selection to model fails after sorting a column. I can reproduce this failure everytime with the following test case.
model.setSource(Arrays.asList("3", "4", "5"));
assertEquals(source, selection);
final Table table = viewer.getTable();
comparator.setColumn(0);
table.setSortDirection(comparator.getDirection());
table.setSortColumn(table.getColumn(0));
table.showSelection();
viewer.refresh();
assertEquals(source.size(), selection.size());
model.setSource(Arrays.asList("1", "2", "3", "4", "5"));
assertEquals(source.size(), selection.size());
viewer.setSelection(new StructuredSelection(Arrays.asList("1", "2")));
assertEquals(source.size(), selection.size());
model.setSource(Arrays.asList("1", "2", "3", "4", "5"));
assertEquals(source.size(), selection.size()); // failure
The list of the viewer is always "1", "2", "3", "4", "5" (form ContentProvider) but the multi-selection stored in "selection" and bind to "source" is different at the end.
source=[1, 2, 3, 4, 5]
selection=[3, 2, 1]
If i comment out the sort block the result is
source=[1, 2, 3, 4, 5]
selection=[1, 2, 3, 4, 5]
The whole implementation is based on a tutorial of vogella (http://www.vogella.com/articles/EclipseJFaceTableAdvanced/article.html#sortcolumns).
Has anyone an idea to fix this? Any suggestion? Thank you!
Builds: org.eclipse.jface_3.7.0.I20110522-1430.jar, org.eclipse.core.databinding.observable_1.4.0.I20110222-0800.jar
|
|
|
Re: TableViewer Sorting and MultiSelectionBinding [message #1075456 is a reply to message #1067751] |
Mon, 29 July 2013 13:05 |
Nigel Westbury Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Hi Ralf,
I'm confused here. You mentioned binding but there is no code in your
post that does any kind of bidirectional binding. Furthermore the
tutorial to which you link is on JFace viewer, not databinding. The
full test case would help.
Note also that it is unusual for a selection to be bound to the
persisted model. You may like to consider using check boxes instead of
the selection if this subset is to be persisted in the datastore.
Nigel Westbury
On 10/07/2013 13:50, Ralf Heilek wrote:
> Hello,
>
> i am using the databinding framework to bind TableViewers to ObservableLists. The bidirectional binding from viewer to model works fine but the bidirectional binding from multi-selection to model fails after sorting a column. I can reproduce this failure everytime with the following test case.
>
> model.setSource(Arrays.asList("3", "4", "5"));
> assertEquals(source, selection);
>
> final Table table = viewer.getTable();
> comparator.setColumn(0);
> table.setSortDirection(comparator.getDirection());
> table.setSortColumn(table.getColumn(0));
> table.showSelection();
> viewer.refresh();
> assertEquals(source.size(), selection.size());
>
> model.setSource(Arrays.asList("1", "2", "3", "4", "5"));
> assertEquals(source.size(), selection.size());
>
> viewer.setSelection(new StructuredSelection(Arrays.asList("1", "2")));
> assertEquals(source.size(), selection.size());
>
> model.setSource(Arrays.asList("1", "2", "3", "4", "5"));
> assertEquals(source.size(), selection.size()); // failure
>
> The list of the viewer is always "1", "2", "3", "4", "5" (form ContentProvider) but the multi-selection stored in "selection" and bind to "source" is different at the end.
>
> source=[1, 2, 3, 4, 5]
> selection=[3, 2, 1]
>
> If i comment out the sort block the result is
>
> source=[1, 2, 3, 4, 5]
> selection=[1, 2, 3, 4, 5]
>
> The whole implementation is based on a tutorial of vogella (http://www.vogella.com/articles/EclipseJFaceTableAdvanced/article.html#sortcolumns).
>
> Has anyone an idea to fix this? Any suggestion? Thank you!
>
> Builds: org.eclipse.jface_3.7.0.I20110522-1430.jar, org.eclipse.core.databinding.observable_1.4.0.I20110222-0800.jar
>
|
|
| |
Goto Forum:
Current Time: Fri Sep 20 08:23:51 GMT 2024
Powered by FUDForum. Page generated in 0.03523 seconds
|