• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access the Elements of a TreeViewer Selection  RSS feed

 
E Vogel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hierarchal data structure (Machine, Component, Measurement, Fault are classes) displayed in a TreeViewer. I have added SelectionChanged and DoubleClick listeners, but can't find a way to get to the data stored in the selected instance of the data structure class. For example, the selection is a Measurement which has a String name field. I can see the data in the Element in Debug-Variables, but I can't find any getters to access it. I tried casting the selection as a Measurement but it is an ISelection, or TreeSelection class and it won't accept the cast.

It seems there should be get methods to access the data in the selection, but there aren't, so I'm must be missing something fundamental.

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to the Ranch!

Normally, tree selection gives you the node object. Which has a method named getUserObject() which returns the object associated with the node.

Do checkout the tutorial which shows how to get the selected object.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think TreeViewer is a Swing component.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!