Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Databinding a list to a ListViewer on selection
Databinding a list to a ListViewer on selection [message #506150] Wed, 06 January 2010 11:12 Go to next message
epoch  is currently offline epoch Friend
Messages: 12
Registered: September 2009
Junior Member
Hi

Assuming I have two classes such as:

class SomeParent {

	public List<SomeObject> getChildren() {
		return children;
	}
	
	public String toString() {
		return "Parent!";
	}

	private List<SomeObject> children;
}

class SomeObject {
	public String toString() {
		return "Child!";
	}
}


Assuming a list of SomeParent is bound to a TreeViewer, when an element in the TreeViewer is selected, I would like the current selection (of SomeParent) to be bound to a ListViewer so that SomeParent.getChildren() are displayed as rows.

I understand how to bind a single property of SomeParent to a Text field when selection changes but I am unsure how to bind the getChildren() list to the ListViewer.

Could somebody please help me with a small demonstration?

Cheers
Re: Databinding a list to a ListViewer on selection [message #507899 is a reply to message #506150] Fri, 15 January 2010 03:33 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
// Assuming parent viewer is already set up

IObservableValue parentSelection =
ViewerProperties.singleSelection().observe(someParentViewer) ;

IObservableList selectionChildren =
BeanProperties.list(SomeParent.class, "children", SomeObject.class)
.observeDetail(parentSelection);

childrenViewer.setContentProvider(new ObservableListContentProvider());
childrenViewer.setInput(selectionChildren);

hope this helps,

Matthew

epoch wrote:
> Hi
> Assuming I have two classes such as:
>
>
> class SomeParent {
>
> public List<SomeObject> getChildren() {
> return children;
> }
>
> public String toString() {
> return "Parent!";
> }
>
> private List<SomeObject> children;
> }
>
> class SomeObject {
> public String toString() {
> return "Child!";
> }
> }
>
>
> Assuming a list of SomeParent is bound to a TreeViewer, when an element
> in the TreeViewer is selected, I would like the current selection (of
> SomeParent) to be bound to a ListViewer so that SomeParent.getChildren()
> are displayed as rows.
>
> I understand how to bind a single property of SomeParent to a Text field
> when selection changes but I am unsure how to bind the getChildren()
> list to the ListViewer.
>
> Could somebody please help me with a small demonstration?
>
> Cheers
Previous Topic:Retrieving parent Composite from ViewPart
Next Topic:Content proposal (auto complete) of StyledText
Goto Forum:
  


Current Time: Thu Mar 28 09:52:55 GMT 2024

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

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

Back to the top