Bug 187263 - [DataBinding] Problem switching models bound to a ComboViewer - nulls value
Summary: [DataBinding] Problem switching models bound to a ComboViewer - nulls value
Status: RESOLVED DUPLICATE of bug 251611
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Dave Orme CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 127424 (view as bug list)
Depends on: 214621
Blocks:
  Show dependency tree
 
Reported: 2007-05-16 10:13 EDT by Geoff CLA
Modified: 2009-01-21 21:47 EST (History)
4 users (show)

See Also:


Attachments
Test eclipse project illustrating problem (44.04 KB, application/zip)
2007-05-16 10:13 EDT, Geoff CLA
no flags Details
One workaround that avoides ComboViewer altogether (43.91 KB, application/zip)
2007-05-17 10:26 EDT, Dave Orme CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Geoff CLA 2007-05-16 10:13:05 EDT
Build ID: I20070503-1400

Steps To Reproduce:
With the attached zipped eclipse project:
The view on the left is the ListView and contains a ComboViewer that contains groups bound to a GroupModel model.  The view on the right is the GroupView and contains a ComboViewer that contains Brokers bound to a Group model.
1.  With the group AUD-123 selected in the ListView, select a broker in the GroupView comboViewer.
2.  Change the selection in the ListView to group CAD-123 and select a broker in the GroupView comboViewer.
3.  Now change the selection in the ListView back to AUD-123 and notice that the previously selected broker for the group gets nulled out by the binding.  


More information:
Comment 1 Geoff CLA 2007-05-16 10:13:50 EDT
Created attachment 67404 [details]
Test eclipse project illustrating problem
Comment 2 Boris Bokowski CLA 2007-05-17 00:36:07 EDT
ComboViewer will generate a selection change event when its old selection cannot be preserved. This happens when you switch between groups.

If ComboViewer wasn't final, you could write this in GroupView.java to avoid the selection change event:

final ComboViewer comboViewer = new ComboViewer(composite, SWT.BORDER){
	protected void handleInvalidSelection(ISelection invalidSelection,
			ISelection newSelection) {
		// ignore
	}
};

Unfortunately, ComboViewer is final, and we cannot change that for 3.3 since we are well past the API freeze. It should be possible though to make a private copy of ComboViewer and go from there.

For 3.4, we should look at this in more detail and come up with an easier to understand story.  Debugging this made my head hurt.
Comment 3 Dave Orme CLA 2007-05-17 10:26:59 EDT
Created attachment 67660 [details]
One workaround that avoides ComboViewer altogether

I noticed that ComboViewer was final too, so here's a 100% Databinding-based approach to doing the same thing as ComboViewer -- attaching a model to a Combo.

Some notes/thoughts:

- This is so easy to do because of: WritableList and WritableValue

- Our current viewer story never uses dbc.bind() but rather just chains observables together.  The consequence is that you can't use our update strategy objects to intercept updates to viewers in order to emit log messages or insert breakpoints into the data binding pipeline.  Attaching a WritableList / WritableValue pair to a Combo and using dbc.bind, makes the pipeline explicit and transparent again.
Comment 4 Dave Orme CLA 2007-05-17 10:31:15 EDT
Boris, I'm sorry this made your head hurt.  :-)  I assigned the bug to myself because I was working on it.  I guess I should have added a comment too.  :-)

BTW, this is the Combo order of evaluation bug we spoke about at EclipseCon and that I agreed to create a snippet illustrating.  (But Geoff did that for us. :-)

Basically, the problem is that removing all items in a Combo also clears the Text/selectionIndex.  

So either you have to make sure that the items observable is always updated first, and then the text/selection, or you have to create a wrapper that remembers the selection and tries to reset it after the items is set.
Comment 5 Dave Orme CLA 2007-05-17 10:32:51 EDT
and tries to reset it after the items is set.

==>

and tries to reset it after the items observable (the set of valid values in the Combo) is updated.
Comment 6 Dave Orme CLA 2007-05-17 10:35:37 EDT
Geoff, does this solve your problem?
Comment 7 Geoff CLA 2007-05-17 11:10:58 EDT
Yes, it does solve my problem.  Thank you very much.  I am getting a fairly significant flicker in certain cases when switching between models I can live with that over the nulling out of values :-).
Comment 8 Boris Bokowski CLA 2007-05-17 11:49:56 EDT
(In reply to comment #7)
> Yes, it does solve my problem.

Dave's solution or mine?
Comment 9 Geoff CLA 2007-05-17 13:00:09 EDT
I went ahead and used Dave's solution.
Comment 10 Dave Orme CLA 2007-05-17 15:22:43 EDT
Boris, do you want to call this bug RESOLVED/FIXED now or retarget it against viewers for 3.4?
Comment 11 Boris Bokowski CLA 2007-06-26 15:43:28 EDT
*** Bug 127424 has been marked as a duplicate of this bug. ***
Comment 12 Matthew Hall CLA 2009-01-21 20:47:47 EST
May be related to bug 251611
Comment 13 Matthew Hall CLA 2009-01-21 21:47:19 EST
Both this bug and bug 251611 are caused by Combo's behavior of clearing the text / selection index whenever the items are changed.

*** This bug has been marked as a duplicate of bug 251611 ***