Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Binding: ComputedList/ObserveDetail resets wrong Element(EMF Bug ?)
Binding: ComputedList/ObserveDetail resets wrong Element [message #799692] Thu, 16 February 2012 07:36 Go to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hi,
I have the following situation.

A MasterDetail Site
A ComboViewer on the DetailsPage
A ComputedList for computing the ComboViewerInput in dependency of the selected Element in the Master-Tree

That is my binding:

IViewerObservableValue viewerObsevable = ViewersObservables.observeSingleSelection(this.trainCategory2ComboViewer);
IObservableValue modelObsevable = EMFEditProperties.value(editingDomain, CoachgroupPackage.Literals.COACH_GROUP__TRAIN_CATEGORY2).observeDetail(masterTreeViewerObservable);
bindingContext.bindValue(viewerObsevable, modelObsevable);


and that is my ComputedListCode (simplyfied):

computedResourceList = new ComputedList() {

	@Override
	protected List<Object> calculate() {
	    List<Object> result = new ArrayList<Object>();

            CoachGroup coachGroup = (CoachGroup) getMasterTreeViewerObservable().getValue();

	 
	    for (TrainCategory trainCategory : coachGroup.getClientOrganization().getTrainCategories().getTrainCategory()) {
		result.add(trainCategory);
	    }
					
	}
};


For every selection in the master tree the comboviewer gets its own inputlist.

The problem now is that the binding resets the old selection.

When I change the master tree selection (from coachGroup1 to coachGroup2) calculate is called. getMasterTreeViewerObservable().getValue()returns the new selected coachGroup2 element....erverything fine so far.

Now I calculate the new input list for the viewer. The new input list is empty, because for the current selected coachGroup2 there should be no trainCategories available to choose. So I return an empty list.....still everything ok so far.

BUT now comes the problem....when I return the empty list the ValueBinding-stuff (see screenshot of stack) resets the trainCategory attribute (to null) of the old selected coachGroup1.

The selection changes, the getMasterTreeViewerObservable().getValue() return the fresh selection but the binding still is connected to the old selection.... is there an "observeDetail"-bug ? It seems that the binding gets refreshed after calculate is called and that would be very bad....then I would see no chance to use this combination of emf-binding and computed list.

Any ideas ?


Greetings
Re: Binding: ComputedList/ObserveDetail resets wrong Element [message #800247 is a reply to message #799692] Thu, 16 February 2012 21:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

This is a known "problem" in Eclipse Databinding. It's not really a bug
but not really solveable with the current API.

The only workaround i found is to dispose the selection-binding while
the master changes and recreate it afterwards.

Here's the thing in pseudo code:

final AtomicReference<Binding> binding ....

IObservable master = ...
master.addValueChangeListener(new ChangeListener() {
valueChanged() {
if( binding.get() != null ) {
binding.get().dispose();
binding.set(null);
}
}
});
IObservableList list = ...;
IObservableValue detailObs = ...;
viewer.setInput(list);
binding.set(dbc.bindValue(uiObs,detailObs));
master.addValueChangeListener(new ChangeListener() {
valueChanged() {
if( binding.get() == null ) {
binding.set(dbc.bindValue());
}
}
});

The position where the master.addValueChangeListeners are added are
extremly important because they ensure the binding is disposed before
any list changes, ... occur and recreated afterwards.

Tom

Am 16.02.12 08:36, schrieb Markus Jo:
> Hi,
> I have the following situation.
>
> A MasterDetail Site
> A ComboViewer on the DetailsPage
> A ComputedList for computing the ComboViewerInput in dependency of the selected Element in the Master-Tree
>
> That is my binding:
>
>
> IViewerObservableValue viewerObsevable = ViewersObservables.observeSingleSelection(this.trainCategory2ComboViewer);
> IObservableValue modelObsevable = EMFEditProperties.value(editingDomain, CoachgroupPackage.Literals.COACH_GROUP__TRAIN_CATEGORY2).observeDetail(masterTreeViewerObservable);
> bindingContext.bindValue(viewerObsevable, modelObsevable);
>
>
> and that is my ComputedListCode (simplyfied):
>
>
> computedResourceList = new ComputedList() {
>
> @Override
> protected List<Object> calculate() {
> List<Object> result = new ArrayList<Object>();
>
> CoachGroup coachGroup = (CoachGroup) getMasterTreeViewerObservable().getValue();
>
>
> for (TrainCategory trainCategory : coachGroup.getClientOrganization().getTrainCategories().getTrainCategory()) {
> result.add(trainCategory);
> }
>
> }
> };
>
>
> For every selection in the master tree the comboviewer gets its own inputlist.
>
> The problem now is that the binding resets the old selection.
>
> When I change the master tree selection (from coachGroup1 to coachGroup2) calculate is called. getMasterTreeViewerObservable().getValue()returns the new selected coachGroup2 element....erverything fine so far.
>
> Now I calculate the new input list for the viewer. The new input list is empty, because for the current selected coachGroup2 there should be no trainCategories available to choose. So I return an empty list.....still everything ok so far.
>
> BUT now comes the problem....when I return the empty list the ValueBinding-stuff (see screenshot of stack) resets the trainCategory attribute (to null) of the old selected coachGroup1.
>
> The selection changes, the getMasterTreeViewerObservable().getValue() return the fresh selection but the binding still is connected to the old selection.... is there an "observeDetail"-bug ? It seems that the binding gets refreshed after calculate is called and that would be very bad....then I would see no chance to use this combination of emf-binding and computed list.
>
> Any ideas ?
>
>
> Greetings
Re: Binding: ComputedList/ObserveDetail resets wrong Element [message #800603 is a reply to message #800247] Fri, 17 February 2012 09:11 Go to previous message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Ok,
I´ll do it like that. Thx
Previous Topic:Contextual EMF Factories ?
Next Topic:[CDO] start lightweight CDO server in setup method of unittest
Goto Forum:
  


Current Time: Fri Apr 26 01:12:53 GMT 2024

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

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

Back to the top