Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Ralf Heilek is currently offline Ralf HeilekFriend
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 Go to previous messageGo to next message
Nigel Westbury is currently offline Nigel WestburyFriend
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
>
Re: TableViewer Sorting and MultiSelectionBinding [message #1086599 is a reply to message #1075456] Wed, 14 August 2013 12:06 Go to previous message
Ralf Heilek is currently offline Ralf HeilekFriend
Messages: 12
Registered: July 2009
Junior Member
Hi Nigel,

you can download the whole test case from the first post (http://www.eclipse.org/forums/index.php/fa/15553/). The binding code in this file looks like...

Realm realm = new DefaultRealm();

source = BeansObservables.observeList(realm, model, "source", String.class);
selection = ViewersObservables.observeMultiSelection(viewer);

DataBindingContext ctx = new DataBindingContext(realm);
ctx.bindList(selection, source);

...and the model should only fulfil the model-view-controller paradigm to display details from the selected values outside of the master table (e.g. detail block).

Best regards,

Ralf Heilek
Previous Topic:treeviewer resize issue
Next Topic:[Databinding] Howto add a single childs to the databinding properties for child nodes of a Treeviewe
Goto Forum:
  


Current Time: Fri Apr 19 10:16:43 GMT 2024

Powered by FUDForum. Page generated in 0.02010 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top