Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [DATABINDING] How-to: binding the (current single) selection of treeViewers to something
[DATABINDING] How-to: binding the (current single) selection of treeViewers to something [message #1310811] Wed, 23 April 2014 12:11 Go to next message
Bernhard Anzeletti is currently offline Bernhard AnzelettiFriend
Messages: 17
Registered: July 2011
Location: Austria
Junior Member
Hi,
I'm trying to bind the current selection of a tree viewer but fail to find a suitable xyzProperties.value() method to get the "selection" IPropertyValue object. JFaceProperties.value(...) fails, as well does WidgetProperties.value(...). Do I have to look for this factory somewhere else?

Kind regards
Bernhard
Re: [DATABINDING] How-to: binding the (current single) selection of treeViewers to something [message #1310925 is a reply to message #1310811] Wed, 23 April 2014 13:39 Go to previous messageGo to next message
Bernhard Anzeletti is currently offline Bernhard AnzelettiFriend
Messages: 17
Registered: July 2011
Location: Austria
Junior Member
Found ViewerProperties.singleSelection(), but it still does not work...

/* setting up the model */
private Box theMainBox =
   new Box("MasterBox");

theMainBox = new Box("Main Box");
Box subBox = new Box("SubBox");
Item item1 = new Item("item1");
Item item2 = new Item("item2");
subBox.addItem(item1);
subBox.addItem(item2);
theMainBox.addItem(subBox);



/* ... and the viewer bindings */

private WritableValue currentSelectedBoxable =
   new WritableValue();

//The following works fine ...
ViewerSupport.bind(treeViewer,
   BeanProperties.value("items")
      .observe(theMainBox),
   BeanProperties.list("items"),
   BeanProperties.value("name")
);
treeViewer.setInput(theMainBox);

//This does not work at all.
IViewerObservableValue  widgetSelection = 
   ViewerProperties
      .singleSelection()
      .observe(treeViewer);
IObservableValue modelSelection  = 
   BeanProperties
      .value("value")
      .observeDetail(currentSelectedBoxable);
bindings.bindValue(widgetSelection,modelSelection);

Re: [DATABINDING] How-to: binding the selection of treeViewers to something - SOLVED [message #1310971 is a reply to message #1310811] Wed, 23 April 2014 14:11 Go to previous messageGo to next message
Bernhard Anzeletti is currently offline Bernhard AnzelettiFriend
Messages: 17
Registered: July 2011
Location: Austria
Junior Member
After some time, I came up with the following solution:

IViewerObservableValue  widgetSelection =
   ViewerProperties
      .singleSelection()
      .observe(treeViewer);

IObservableValue modelSelection  = 
   PojoProperties.value("value")
      .observe(currentSelectedBoxable);

bindings.bindValue(widgetSelection,modelSelection);


Interestingly enough, WritableValue does not support ChangeListeners and in consequence cannot be dealt with BeanProperties, but rather PojoProperties instead. I still feel uncomfortable about this, because I still think I miss an important point.
Re: [DATABINDING] How-to: binding the selection of treeViewers to something - SOLVED [message #1311064 is a reply to message #1310971] Wed, 23 April 2014 15:21 Go to previous messageGo to next message
Bernhard Anzeletti is currently offline Bernhard AnzelettiFriend
Messages: 17
Registered: July 2011
Location: Austria
Junior Member
... and the good solution seems to be ...
Properties.observableValue(Boxable.class).observe(currentSelectedBoxable);
Re: [DATABINDING] How-to: binding the (current single) selection of treeViewers to something [message #1323738 is a reply to message #1310811] Wed, 30 April 2014 12:14 Go to previous message
Nigel Westbury is currently offline Nigel WestburyFriend
Messages: 18
Registered: July 2009
Junior Member
ViewersObservables.observeSingleSelection is what you are looking for.

On 23/04/2014 13:11, Bernhard Anzeletti wrote:
> Hi,
> I'm trying to bind the current selection of a tree viewer but fail to
> find a suitable xyzProperties.value() method to get the "selection"
> IPropertyValue object. JFaceProperties.value(...) fails, as well does
> WidgetProperties.value(...). Do I have to look for this factory
> somewhere else?
>
> Kind regards
> Bernhard
Previous Topic:Getting/Setting EReferences of a EMF model instance in a TableViewer with ComboBox
Next Topic:TableViewer with OwnerDrawLabel only draws the first row
Goto Forum:
  


Current Time: Thu Apr 25 19:31:42 GMT 2024

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

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

Back to the top