|TreeViewer find node [message #17656]
||Tue, 30 June 2009 13:43
| David Crecente
Registered: July 2009
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
Originally posted by: TheRealHawk.Freenet.de|
As far as I know org.eclipse.jface.viewers.IElementComparer should be the
right thing for you.
"David Crecente" <email@example.com> schrieb im Newsbeitrag
> 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 #488472 is a reply to message #18482]
||Mon, 28 September 2009 20:07
| Klaus Pesendorfer
Registered: July 2009
I've implemented a search/searchNext-feature for my TreeViewer the following
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?
> 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).
Powered by FUDForum
. Page generated in 0.01967 seconds