Skip to main content



      Home
Home » Eclipse Projects » JFace » [databinding] Binding same TableViewer with 2nd input
[databinding] Binding same TableViewer with 2nd input [message #20498] Sat, 11 July 2009 12:23 Go to next message
Eclipse UserFriend
I am trying to use databinding to bind a model to a tableviewer. This
works fine using ViewerSupport.bind().

However when i try to bind the tableviewer a 2nd time (due to the input
object changing) i receive an

"assertion failed: Getter called on disposed observable message."

On initial inspection, ViewerSupport.bind() method sets the new content
provider which in turn disposes of the old one on the tableviewer which in
turn calls TableViewer.refresh(). At this point however the treeviewer is
still using the old LabelProvider and the error occurs.

Is there a correct way of doing this? If i manually set the LabelProvider
of the treeviewer to a new LabelProvider() (standard labelprovider class),
then rebind, it works fine, however i'm not sure if this will leak
listeners.

cheers

Matt
Re: [databinding] Binding same TableViewer with 2nd input [message #20528 is a reply to message #20498] Mon, 13 July 2009 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Are you binding the columns exactly to exactly the same properties? If
so you could just set a new input on the TableViewer.

Matthew

Matt Biggs wrote:
> I am trying to use databinding to bind a model to a tableviewer. This
> works fine using ViewerSupport.bind().
> However when i try to bind the tableviewer a 2nd time (due to the input
> object changing) i receive an
>
> "assertion failed: Getter called on disposed observable message."
>
> On initial inspection, ViewerSupport.bind() method sets the new content
> provider which in turn disposes of the old one on the tableviewer which
> in turn calls TableViewer.refresh(). At this point however the
> treeviewer is still using the old LabelProvider and the error occurs.
> Is there a correct way of doing this? If i manually set the
> LabelProvider of the treeviewer to a new LabelProvider() (standard
> labelprovider class), then rebind, it works fine, however i'm not sure
> if this will leak listeners.
>
> cheers
>
> Matt
>
>
>
Re: [databinding] Binding same TableViewer with 2nd input [message #20614 is a reply to message #20528] Tue, 14 July 2009 03:22 Go to previous messageGo to next message
Eclipse UserFriend
Yes the columns remain the same.

I copied the code from ViewerSupport.bind(StructuredViewer viewer,
IObservableList input, IValueProperty[] labelProperties) and swapped
around the order of setting the label provider *BEFORE* setting the
content provider and it works perfectly.

I personally think this is a bug.

Setting the content provider first means when the old content provider is
disposed a refresh is called which uses the old label provider and the old
elements.

Setting the label provider first means the exception isn't thrown.
Re: [databinding] Binding same TableViewer with 2nd input [message #20627 is a reply to message #20614] Tue, 14 July 2009 10:43 Go to previous messageGo to next message
Eclipse UserFriend
Matt Biggs wrote:
> Yes the columns remain the same.

For the moment, the workaround is to set up the label and content
providers only once when you first initialize your UI. You could do
this by calling ViewerSupport.bind() with an input argument of null.

Then, when the content of your table changes, you only need to call
TableViewer.setInput() with the new observable list, rather than calling
ViewerSupport.bind().

> I copied the code from ViewerSupport.bind(StructuredViewer viewer,
> IObservableList input, IValueProperty[] labelProperties) and swapped
> around the order of setting the label provider *BEFORE* setting the
> content provider and it works perfectly.
> I personally think this is a bug.

Calling ViewerSupport.bind repeatedly on the same viewer was not a use
case I had planned for, but it does make sense. Would you file a bug
report?

> Setting the content provider first means when the old content provider
> is disposed a refresh is called which uses the old label provider and
> the old elements.
> Setting the label provider first means the exception isn't thrown.

This is because ObservableMapLabelProvider is using observable maps
which are derived from ObservableListTreeContentProvider's known
elements set. When the content provider is disposed, it disposes the
known elements set with it. Since the observable maps in the label
provider are dependent on it they are also disposed. Thus when the
viewer tries to refresh with the label provider a "observable is
disposed" exception is thrown. As you discovered the solution is to set
the label provider first.

Matthew
Re: [databinding] Binding same TableViewer with 2nd input [message #20630 is a reply to message #20627] Tue, 14 July 2009 10:57 Go to previous message
Eclipse UserFriend
Thanks,

I've submitted Bug 283428
Previous Topic:How to provide own ValidationStatus without to bind a model-property to something?
Next Topic:ChangeManager#getRealm thread safety concern
Goto Forum:
  


Current Time: Tue Jul 01 06:20:16 EDT 2025

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

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

Back to the top