Binding: ComputedList/ObserveDetail resets wrong Element [message #799692] |
Thu, 16 February 2012 02:36  |
Eclipse User |
|
|
|
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 16:24   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.07155 seconds