Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How do you find a TreeItem index by searching the Data fields ?
How do you find a TreeItem index by searching the Data fields ? [message #462258] Mon, 10 October 2005 00:06 Go to next message
TJ is currently offline TJFriend
Messages: 1
Registered: July 2009
Junior Member
Here is my problem... I have a Tree and I am populating it from a database.
When I add a TreeItem to the tree, I am setting its Data field with the
index of the database record ( .setData(Integer.toString(dbIndex)) ). Now,
if I read a record from the database, and I know the index I am looking for,
how can I easily find the TreeItem in the Tree ?

I thought I could somehow use the .indexOf() function... but it requires a
TreeItem as the parameter... but that is what I am looking for.... can I
somehow create a 'dummy' TreeItem, do a setData of it to the index I am
searching for, and call .indexOf(dummyTreeItem) ? or does the .indexOf
require ALL fields fo the search item to match ?

Hope I am making sense....

Of course, I could create my own search function and just traverse the Tree
looking at each TreeItem's Data field.... just wondered if there was an
easier way.

TJ
Re: How do you find a TreeItem index by searching the Data fields ? [message #462366 is a reply to message #462258] Tue, 11 October 2005 13:58 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
There isn't a way provided for locating a TreeItem based on its data.
indexOf(TreeItem) does an identity match, so this won't help you.

Depending on your context there may be a better approach than running
through the full Tree each time though. For example, since your indexes
seem to be static, just keeping an array with index->TreeItem mappings could
provide a quicker solution.

Grant

"TJ Forshee" <timforshee@bgdigital.com> wrote in message
news:dicbat$6id$1@news.eclipse.org...
> Here is my problem... I have a Tree and I am populating it from a
database.
> When I add a TreeItem to the tree, I am setting its Data field with the
> index of the database record ( .setData(Integer.toString(dbIndex)) ).
Now,
> if I read a record from the database, and I know the index I am looking
for,
> how can I easily find the TreeItem in the Tree ?
>
> I thought I could somehow use the .indexOf() function... but it requires a
> TreeItem as the parameter... but that is what I am looking for.... can I
> somehow create a 'dummy' TreeItem, do a setData of it to the index I am
> searching for, and call .indexOf(dummyTreeItem) ? or does the .indexOf
> require ALL fields fo the search item to match ?
>
> Hope I am making sense....
>
> Of course, I could create my own search function and just traverse the
Tree
> looking at each TreeItem's Data field.... just wondered if there was an
> easier way.
>
> TJ
>
>
Previous Topic:Waiting dialogs
Next Topic:fixed TableColumn
Goto Forum:
  


Current Time: Fri Apr 26 06:30:06 GMT 2024

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

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

Back to the top