org.eclipse.cdt.internal.ui.viewsupport
Class TreeNavigator

java.lang.Object
  extended by org.eclipse.cdt.internal.ui.viewsupport.TreeNavigator

public class TreeNavigator
extends java.lang.Object

Utility to perform next/previous navigation on a tree.

Author:
markus.schorn@windriver.com

Constructor Summary
TreeNavigator(org.eclipse.swt.widgets.Tree tree, java.lang.Class dataClass)
          Creates a tree navigator for the given tree.
 
Method Summary
 org.eclipse.swt.widgets.TreeItem getFirstItemOnLevel(int level, boolean fwd)
          Find the first valid item on the given level.
 org.eclipse.swt.widgets.TreeItem getNextSibbling(org.eclipse.swt.widgets.TreeItem current, boolean forward)
          Searches for the next valid sibbling of the given item.
 org.eclipse.swt.widgets.TreeItem getSelectedItem()
          Find the first valid item of the selection.
 org.eclipse.swt.widgets.TreeItem getSelectedItemOrFirstOnLevel(int level, boolean fwd)
          Combines the methods getSelectedItem() and getFirstItemOnLevel(int, boolean).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNavigator

public TreeNavigator(org.eclipse.swt.widgets.Tree tree,
                     java.lang.Class dataClass)
Creates a tree navigator for the given tree. It allows for finding tree items. In case you supply a dataClass only nodes with data of this class are considered.

Parameters:
tree - the tree to operate on
dataClass - the required class for the data of the tree nodes, or null.
Method Detail

getSelectedItem

public org.eclipse.swt.widgets.TreeItem getSelectedItem()
Find the first valid item of the selection.

Returns:
the first valid item in the selection or null

getFirstItemOnLevel

public org.eclipse.swt.widgets.TreeItem getFirstItemOnLevel(int level,
                                                            boolean fwd)
Find the first valid item on the given level. All parents have to be valid also.

Parameters:
level - the level to search, use 0 for the root nodes of the tree.
fwd - if set to false the tree is searched reverse from the buttom.
Returns:
the first item on the given level, or null

getSelectedItemOrFirstOnLevel

public org.eclipse.swt.widgets.TreeItem getSelectedItemOrFirstOnLevel(int level,
                                                                      boolean fwd)
Combines the methods getSelectedItem() and getFirstItemOnLevel(int, boolean).

Parameters:
level - the level to search, use 0 for the root nodes of the tree.
fwd - if set to false the tree is searched reverse from the buttom.
Returns:
the first valid item of the selection or the first item on the given level, or null

getNextSibbling

public org.eclipse.swt.widgets.TreeItem getNextSibbling(org.eclipse.swt.widgets.TreeItem current,
                                                        boolean forward)
Searches for the next valid sibbling of the given item.

Parameters:
current - a tree item to start the search
forward - if false the previous sibbling is returned
Returns:
the next sibbling after the given one, or null