Community
Participate
Working Groups
bug 206839 added the ability to bind to a viewer input. However if there is a selection it is not preserved. If the selection is no longer valid under the new content for the new input then of course the selection cannot be preserved, but if it is still valid it should be preserved. This can potentially cause fairly serious problems. Consider a combo viewer that is bound using master-detail binding. The selection (single or multiple) is bound to a property in a bean. The viewer content depends on properties in the bean, so the bean itself is input to the combo viewer. We thus bind the observable on the bean to the viewer input. We also bind the master-detail observable of the property containing the selection to the viewer selection. So far that all works well. The problem is when the bean switches to another bean but that other bean has the same selection as the previous. The input changes and the content is replaced, though the content happens to be the same. The selection is cleared. The master-detail binding on the selection property however sees no change so does nothing; it does not set the selection because it assumed it was already set. The net result is that whenever users switch to another bean that has the same selection, they don't see the selection. The workaround is simple. Just listen for when the bean changes, set the input yourself, and set the selection. However this should be fairly easy to fix in the data binding. StructuredViewer has a 'preserve selection' property but that, I believe, only works across updates, not changes in the input. But it should be easy to get the selection before changing the input and to set it afterwards.
Nigel, this is not something I can fix on the data binding side. The workaround is not as simple as you suppose. The problem is that when you observe a viewers input, and observe its selection somewhere else, I have no way to link those two to each other. At least not without creating some sort of monstrous global cache of observables. I suggest opening a new bug against JFace Viewers, requesting a feature to preserve the selection if possible when the input is reassigned. Although I thought they were already doing that. If I've missed something feel free to reopen and explain it to me. :) Marking resolved as wontfix, since this has to be fixed by another team.