Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [databinding] Using TreeViewer with ViewerSupport.bind(...)
[databinding] Using TreeViewer with ViewerSupport.bind(...) [message #442923] Fri, 31 July 2009 13:53 Go to next message
Ben Dixon is currently offline Ben DixonFriend
Messages: 63
Registered: July 2009
Member
Hello,

I'm new to JFace databinding and was hoping to get some pointers or help
on how to get my TreeViewer to work with my existing model. The model is a
class that contains an array of "root" beans and those beans each form a
tree of data such that root nodes have 0 or more children, the child nodes
have children, and so on... all of the same type. I found an example of
using ViewerSupport.bind(...) with the TableViewer and its mentioned there
that it can work with TreeViewers as well. In the API I attempted to use
this method:

static void bind(AbstractTreeViewer viewer, Object input,
org.eclipse.core.databinding.property.list.IListProperty childrenProperty,
org.eclipse.core.databinding.property.value.IValueProperty[]
labelProperties)

in this way:

ViewerSupport.bind(viewer, BeansObservables.observeList(model, "roots"),
BeanProperties.values(new String[] { "name", "type", "value" } ) );

I know this isn't wholly correct because only the top-level model object
has a getRoots() method so there's nothing here to setup bindings to the
root objects and their child nodes (the values "name", "type", "value"
come from these nodes and are the columns of my table). So I have two
problems. First, when I run the above code I get this Assertion failed
message:

org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at
org.eclipse.jface.viewers.AbstractTreeViewer.assertContentPr oviderType(AbstractTreeViewer.java:2318)
at
org.eclipse.jface.viewers.TreeViewer.assertContentProviderTy pe(TreeViewer.java:383)
at
org.eclipse.jface.viewers.StructuredViewer.setContentProvide r(StructuredViewer.java:1610)

But the other problem is I don't understand how to bind to the child nodes
that follow on in the tree. Can someone give me some pointers?

Thank,

Ben
Re: [databinding] Using TreeViewer with ViewerSupport.bind(...) [message #443514 is a reply to message #442923] Fri, 31 July 2009 15:00 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Ben,

See comments below

Ben Dixon wrote:
> ViewerSupport.bind(viewer, BeansObservables.observeList(model, "roots"),
> BeanProperties.values(new String[] { "name", "type", "value" } ) );

You are one argument short--this method binds to a list-structured viewer.

When binding trees, you want to use your 'model' object as the
input--let the 'childrenProperty' argument create the observables for you.

Also, since 'model.getRoots()' is a different list property than the
children underneath it, you actual have a non-homogenous tree. So
you'll want to create a DelegatingListProperty to handle the different
children properties:

IListProperty childrenProp = new DelegatingListProperty() {
IListProperty inputChildren =
BeanProperties.list(InputType.class, "roots");
IListProperty elementChildren =
BeanProperties.list(ElementType.class, "childrenProperty");
protected IListProperty doGetDelegate(Object source) {
if (source instanceof InputType)
return inputChildren;
if (source instanceof ElementType)
return elementChildren;
return null;
}
};

You'll have to replace "InputType" with the class name of your model
object, and replace "ElementType" with the class name of your tree
elements. You should also change "childrenProperty" to the correct
property name for the tree elements.

IValueProperty[] labelProps = BeanProperties.values(
new String[] { "name", "type", "value" });

ViewerSupport.bind(viewer, model, childrenProp, labelProps);

Hope this helps,

Matthew

>
> I know this isn't wholly correct because only the top-level model object
> has a getRoots() method so there's nothing here to setup bindings to the
> root objects and their child nodes (the values "name", "type", "value"
> come from these nodes and are the columns of my table). So I have two
> problems. First, when I run the above code I get this Assertion failed
> message:
>
> org.eclipse.core.runtime.AssertionFailedException: assertion failed:
> at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
> at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
> at
> org.eclipse.jface.viewers.AbstractTreeViewer.assertContentPr oviderType(AbstractTreeViewer.java:2318)
>
> at
> org.eclipse.jface.viewers.TreeViewer.assertContentProviderTy pe(TreeViewer.java:383)
>
> at
> org.eclipse.jface.viewers.StructuredViewer.setContentProvide r(StructuredViewer.java:1610)
>
>
> But the other problem is I don't understand how to bind to the child
> nodes that follow on in the tree. Can someone give me some pointers?
>
> Thank,
>
> Ben
>
>
Re: [databinding] Using TreeViewer with ViewerSupport.bind(...) [message #1064188 is a reply to message #443514] Tue, 18 June 2013 07:21 Go to previous message
Markuz Surfing is currently offline Markuz SurfingFriend
Messages: 7
Registered: June 2013
Junior Member
Hi, I know I don't suppose to reply to a very old thread. But nobody answered my post:http://www.eclipse.org/forums/index.php/m/1064012/#msg_1064012 which is related to this one.

I made a tree based on the comment above. The tree works fine except that it does not reflect/show the changes if the model is updated. I still need to call viewer.refresh() to show its changes.
Previous Topic:TableViewer Inline Editting Snippet013
Next Topic:Actions and KeyBindings
Goto Forum:
  


Current Time: Fri Apr 19 01:39:24 GMT 2024

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

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

Back to the top