[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: How to do a tree search?

Hi Dhiresh,

I do a similar, I select items with no children in a tree. this is
how i do it. here is the algorithm. I will send you an example tommorrow.

basically, I recursively go through each item in tree and if does not have any children then I add the item to an arraylist and at the end setselection
on the tree with the arraylist. I hope this helps.


ArrayList items;
for each toplevelitem in tree
treeitem[] childitems = toplevelitem.getitems();
for each childitem in childitems
  treeitems[] subitems = childitem
  if subitems.length > 0 // has children
   do recursive
  else
    items.add(treeitem)
 end for childitems

end for toplevelitem

tree.setSelection(items.coverttoarray)

Dhiresh Patel wrote:

Anybody? How to search treeModel and once you find the object, how do you set selection?

dhiresh wrote:
I am using a treeviewer to display a tree.

I have attached a keylistener to the tree. I want to search tree
base on keystrokes. I am able to capture keystrokes on tree- but I don't know


how to proceed with search on the tree - When I search the tree from beginning and then expand items to get children it takes up plenty of time - Also there is flicker on the the screen as I am expanding treeItem to get to their children.

When I search the treeModel that was used as an input and find the object, I am not able to set tree selection
e.g. Object[] oArr = new Object[1];
oArr[0] = obj3; // obj3 is object found from treemodal search
TreePath tp = new TreePath(oArr);
TreePath[] pArr = new TreePath[1];
pArr[0] = tp;
tv.setExpandedTreePaths(pArr); // tv = treeViewer
TreeSelection ts = new TreeSelection(tp);
tv.setSelection(ts, true); I would appreciate if anybody can help me with this problem or tree search in eclipse.


Thanks

Dhiresh