Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TreeViewer find node
TreeViewer find node [message #17656] Tue, 30 June 2009 13:43 Go to next message
David Crecente is currently offline David CrecenteFriend
Messages: 18
Registered: July 2009
Junior Member
Hi all,
I've built a TreeViewer with my data model and a need to be able to
find a node using several criterias.

Is there any best practice to find a node in TreeViewers? a pattern or
may be a method already implmemed in this class?

Thanks in advance.
Re: TreeViewer find node [message #17722 is a reply to message #17656] Wed, 01 July 2009 07:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: TheRealHawk.Freenet.de

As far as I know org.eclipse.jface.viewers.IElementComparer should be the
right thing for you.

Markus

"David Crecente" <david.crecente@gmail.com> schrieb im Newsbeitrag
news:e735c0ca34a5eb15fc0f99f436cf8881$1@www.eclipse.org...
> Hi all,
> I've built a TreeViewer with my data model and a need to be able to find
> a node using several criterias.
>
> Is there any best practice to find a node in TreeViewers? a pattern or
> may be a method already implmemed in this class?
>
> Thanks in advance.
>
Re: TreeViewer find node [message #17734 is a reply to message #17656] Wed, 01 July 2009 07:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
FilteredTree?

Tom

David Crecente schrieb:
> Hi all,
> I've built a TreeViewer with my data model and a need to be able to
> find a node using several criterias.
>
> Is there any best practice to find a node in TreeViewers? a pattern or
> may be a method already implmemed in this class?
>
> Thanks in advance.
>
Re: TreeViewer find node [message #17742 is a reply to message #17734] Wed, 01 July 2009 08:09 Go to previous messageGo to next message
David Crecente is currently offline David CrecenteFriend
Messages: 18
Registered: July 2009
Junior Member
I think FilteredTree returns nodes which match the criteria in the
filter and you only can see those nodes. But I need to query the
TreeViewer and find my data in order to select it. And I want to see the
original tree with that node selected.

One option will be follow the tree from the root searching the node but
if treeviewer has some kind of quering tool I would prefer to use it.

Thanks in advance.
Re: TreeViewer find node [message #18450 is a reply to message #17742] Wed, 01 July 2009 09:14 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Well then you should take a look at stuff like JXPath, OCL, ... but this
is then not a JFace nor Eclipse question :-)

A viewer is simply a V in MVC so I can't give you generic search
functions like the above mentioned technologies.

Tom

David Crecente schrieb:
> I think FilteredTree returns nodes which match the criteria in the
> filter and you only can see those nodes. But I need to query the
> TreeViewer and find my data in order to select it. And I want to see the
> original tree with that node selected.
>
> One option will be follow the tree from the root searching the node
> but if treeviewer has some kind of quering tool I would prefer to use it.
>
> Thanks in advance.
>
Re: TreeViewer find node [message #18476 is a reply to message #18450] Wed, 01 July 2009 11:25 Go to previous messageGo to next message
David Crecente is currently offline David CrecenteFriend
Messages: 18
Registered: July 2009
Junior Member
Thank you Tom,
so I need to do that search in my model, ok.

But, once I find the information in my model I need to select this node
in the TreeViewer. Is it possible?.

My idea was find the TreeItem then select it.
TreeItem ti = this.findNode(searchedNode);
this.rcTree.setSelection(new StructuredSelection(ti));

If I follow your suggestion I must find the node in my model and then I
suppose I should build a TreeItem to use setSelection(...). But TreeItem's
constructors aren't apropiated.

Do you know how I could implement the funcionality mentioned above?
Re: TreeViewer find node [message #18482 is a reply to message #18476] Wed, 01 July 2009 11:39 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
David Crecente schrieb:
> Thank you Tom,
> so I need to do that search in my model, ok.
>
> But, once I find the information in my model I need to select this
> node in the TreeViewer. Is it possible?.
>
> My idea was find the TreeItem then select it.
> TreeItem ti = this.findNode(searchedNode);
> this.rcTree.setSelection(new StructuredSelection(ti));
>
> If I follow your suggestion I must find the node in my model and then
> I suppose I should build a TreeItem to use setSelection(...). But
> TreeItem's constructors aren't apropiated.
>
> Do you know how I could implement the funcionality mentioned above?
>

No you use your model element to set the selection or even better you
are using a TreeSelection(). The viewer internally translate your domain
object into the appropriate TreeItem

Naturally the element has to be visible to select it because the
TreeViewer is not expanding the tree for you.

As a general rule you can remember that:

When ever you see your self falling back to SWT when interfacing with
your Viewer there's something probably wrong (there are very very rare
cases when there's such a need).

Tom
Re: TreeViewer find node [message #488472 is a reply to message #18482] Mon, 28 September 2009 20:07 Go to previous messageGo to next message
Klaus Pesendorfer is currently offline Klaus PesendorferFriend
Messages: 5
Registered: July 2009
Junior Member
Hello,

I've implemented a search/searchNext-feature for my TreeViewer the following
way:
1) Walk through the content nodes, provided by the ContentProvider of the
TreeViewer (by means of using the getChildren and getParent methods)
2) Compare the displayed text content of the cell provided by the LabelProvider
of the TreeViewer with the desired search pattern
3) Highlight the found cell
4) Search further more - deeper into the tree by expanding nodes with children.

Works fine but I didn't find a clean solution for getting the ViewerCell
(or at least the TreeItem) for a given Content object.
Is there any possibility to get the corresponding ViewerCell for a data object
(not only via the display coordinates)?
-> my "dirty" work-around was to set the selection to that content object
and then get the ViewerCell from that selection.
Does anyone know a better solution?

Kind regards,
Klaus.

> David Crecente schrieb:
>
>> Thank you Tom,
>> so I need to do that search in my model, ok.
>> But, once I find the information in my model I need to select this
>> node in the TreeViewer. Is it possible?.
>>
>> My idea was find the TreeItem then select it.
>> TreeItem ti = this.findNode(searchedNode);
>> this.rcTree.setSelection(new StructuredSelection(ti));
>> If I follow your suggestion I must find the node in my model and then
>> I suppose I should build a TreeItem to use setSelection(...). But
>> TreeItem's constructors aren't apropiated.
>>
>> Do you know how I could implement the funcionality mentioned above?
>>
> No you use your model element to set the selection or even better you
> are using a TreeSelection(). The viewer internally translate your
> domain object into the appropriate TreeItem
>
> Naturally the element has to be visible to select it because the
> TreeViewer is not expanding the tree for you.
>
> As a general rule you can remember that:
>
> When ever you see your self falling back to SWT when interfacing with
> your Viewer there's something probably wrong (there are very very rare
> cases when there's such a need).
>
> Tom
>
Re: TreeViewer find node [message #1753761 is a reply to message #488472] Thu, 09 February 2017 20:19 Go to previous message
Teymuraz Khazaradze is currently offline Teymuraz KhazaradzeFriend
Messages: 4
Registered: September 2010
Junior Member
I have the same question - how to find TreeItem by element.
In other words: is there any public version of the method
protected final Widget StrudturedViewer.findItem(Object element)?
This is exactly the method I need.

And by the way. Why findItem(element) is protected, not public?
Previous Topic:IContentProposal
Next Topic:[databinding] ObservableListTreeContentProvider with IObservableList in different realm
Goto Forum:
  


Current Time: Thu Apr 25 20:49:10 GMT 2024

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

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

Back to the top