Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Databinding] How to refresh a ComboViewer's filter properly?
[Databinding] How to refresh a ComboViewer's filter properly? [message #1704889] Mon, 10 August 2015 12:44 Go to next message
Eclipse UserFriend
Hi,

I have a ComboViewer that is bound to a property of an IObservableValue
(master). The ComboViewer displays a set of elements of my EMF-Based
datamodel. The elements are provided by a custom content provider.
Depending on the current master I want to apply a filter to the ComboViewer.

I implemented this and it is basically working as expected.

However, there is one problem: the filter of the newly selected master
might filter out the selected value of the old master. If this happens
the bound property of the old master is reset before the new master gets
active. For me it seems like the filter is applied too early when the
master gets switched.

So, my question is: where is the correct place to update the filter?

Currently, I am using a ValueChangeListener that is attached to the
master. Whenever the listener gets triggered the filter and ComboViewer
get updated. Is this the correct way to do it? Is the observed behavior
a bug in the binding framework?

Thanks for your effort!

Regards,

Stefan
Re: [Databinding] How to refresh a ComboViewer's filter properly? [message #1705508 is a reply to message #1704889] Mon, 17 August 2015 09:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

is there anybody who is familiar with the mentioned problem?

Here is my code for updating the filter. It is from the constructor of
an AbstractForm:

master.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {

ClassA masterValue = (ClassA)master.getValue();
int filterCriterion = masterValue.getFilterCriterion();

// resolve the root element of the datamodel
Project masterProject = DatamodelUtil.getProject(masterValue);

// check if a new project was loaded
// => reset the ComboViewer's input
if(this.currentProject != masterProject) {
((MyFilter)this.filters[0]).setFilterCriterion(filterCriterion);

myComboViewer.setInput(masterProject);
this.currentProject = newProject;

// check if the filter got changed
} else if(filterCriterion !=
((MyFilter)this.filters[0]).getFilterCriterion()) {

((MyFilter)this.filters[0]).setFilterCriterion(filterCriterion);
myComboViewer.refresh();
}
}
}
});


Thanks for your help!

Regards,

Stefan

On 08/10/2015 02:44 PM, Stefan Warwas wrote:
> Hi,
>
> I have a ComboViewer that is bound to a property of an IObservableValue
> (master). The ComboViewer displays a set of elements of my EMF-Based
> datamodel. The elements are provided by a custom content provider.
> Depending on the current master I want to apply a filter to the
> ComboViewer.
>
> I implemented this and it is basically working as expected.
>
> However, there is one problem: the filter of the newly selected master
> might filter out the selected value of the old master. If this happens
> the bound property of the old master is reset before the new master gets
> active. For me it seems like the filter is applied too early when the
> master gets switched.
>
> So, my question is: where is the correct place to update the filter?
>
> Currently, I am using a ValueChangeListener that is attached to the
> master. Whenever the listener gets triggered the filter and ComboViewer
> get updated. Is this the correct way to do it? Is the observed behavior
> a bug in the binding framework?
>
> Thanks for your effort!
>
> Regards,
>
> Stefan
Re: [Databinding] How to refresh a ComboViewer's filter properly? [message #1705509 is a reply to message #1705508] Mon, 17 August 2015 09:39 Go to previous messageGo to next message
Eclipse UserFriend
The code is part of a ScrolledComposite - not "AbstractForm"...

On 08/17/2015 11:28 AM, Stefan Warwas wrote:
> Hi,
>
> is there anybody who is familiar with the mentioned problem?
>
> Here is my code for updating the filter. It is from the constructor of
> an AbstractForm:
>
> master.addValueChangeListener(new IValueChangeListener() {
> @Override
> public void handleValueChange(ValueChangeEvent event) {
>
> ClassA masterValue = (ClassA)master.getValue();
> int filterCriterion = masterValue.getFilterCriterion();
>
> // resolve the root element of the datamodel
> Project masterProject = DatamodelUtil.getProject(masterValue);
>
> // check if a new project was loaded
> // => reset the ComboViewer's input
> if(this.currentProject != masterProject) {
> ((MyFilter)this.filters[0]).setFilterCriterion(filterCriterion);
>
> myComboViewer.setInput(masterProject);
> this.currentProject = newProject;
>
> // check if the filter got changed
> } else if(filterCriterion !=
> ((MyFilter)this.filters[0]).getFilterCriterion()) {
>
> ((MyFilter)this.filters[0]).setFilterCriterion(filterCriterion);
> myComboViewer.refresh();
> }
> }
> }
> });
>
>
> Thanks for your help!
>
> Regards,
>
> Stefan
>
> On 08/10/2015 02:44 PM, Stefan Warwas wrote:
>> Hi,
>>
>> I have a ComboViewer that is bound to a property of an IObservableValue
>> (master). The ComboViewer displays a set of elements of my EMF-Based
>> datamodel. The elements are provided by a custom content provider.
>> Depending on the current master I want to apply a filter to the
>> ComboViewer.
>>
>> I implemented this and it is basically working as expected.
>>
>> However, there is one problem: the filter of the newly selected master
>> might filter out the selected value of the old master. If this happens
>> the bound property of the old master is reset before the new master gets
>> active. For me it seems like the filter is applied too early when the
>> master gets switched.
>>
>> So, my question is: where is the correct place to update the filter?
>>
>> Currently, I am using a ValueChangeListener that is attached to the
>> master. Whenever the listener gets triggered the filter and ComboViewer
>> get updated. Is this the correct way to do it? Is the observed behavior
>> a bug in the binding framework?
>>
>> Thanks for your effort!
>>
>> Regards,
>>
>> Stefan
>
Re: [Databinding] How to refresh a ComboViewer's filter properly? [message #1706273 is a reply to message #1705508] Tue, 25 August 2015 12:41 Go to previous message
Eclipse UserFriend
Hi,

I found a workaround to this problem.

Now, I am using a WritableList for managing the ComboViewer's content
like in this example:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet022ComputedListCombo.java

Moreover, I added a ValueChangeListener to the master. Whenever the
master is changed, the ValueChangeListener adds all possible values
(unfiltered) to the WritableList. So I make sure that the old value of
the ComboViewer/detail is not filtered out during the transition.

The actual filtering is done when the user clicks on the ComboViewer. At
this point in time the transition from the old to the new master is
finished and the filter cannot cause any trouble.

myComboViewer.getCombo().addMouseListener(new MouseListener() {
@Override
public void mouseDown(MouseEvent e) {
// update the content of the WritableList (apply the filter)
// refresh the ComboViewer
}
}

The basic problem is that the ValueChangeListener() is called when the
binding to the old master is still active. If you change the filter at
this point in time, it might cause side-effects to the old master
(depending on the filter, the old master's detail will be reset). I am
not sure whether this behavior is a bug in JFace/EMF Databinding or if
there is another way to do it. In my opinion a callback
"AfterValueChangeListener()" or something like this would be required,
which gets activated after the transition from one to another master was
performed.

Would be nice to get some feedback.

Regards,

Stefan
Previous Topic:Find Tree Node
Next Topic:TableViewer column header loses image on sorting
Goto Forum:
  


Current Time: Fri Sep 21 00:20:21 GMT 2018

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

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

Back to the top