org.eclipse.jubula.rc.swing.swing.implclasses
Class TreeOperationContext

java.lang.Object
  extended by org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
      extended by org.eclipse.jubula.rc.swing.swing.implclasses.TreeOperationContext

public class TreeOperationContext
extends org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext

This context holds the tree, the tree model and supports access to the Robot. It also implements some general operations on trees.

Created:
09.08.2005

Constructor Summary
TreeOperationContext(org.eclipse.jubula.rc.common.driver.IEventThreadQueuer queuer, org.eclipse.jubula.rc.common.driver.IRobot robot, javax.swing.JTree tree)
          Creates a new instance.
 
Method Summary
 void clickNode(java.lang.Object node, org.eclipse.jubula.rc.common.driver.ClickOptions clickOps)
          Move the mouse pointer directly over the given node's onscreen location and perform a mouse click.
 void collapseNode(java.lang.Object node)
          Collapses the given node.
protected  java.lang.String[] convertTreePathToText(java.lang.Object treePath)
          Calls JTree.convertValueToText(java.lang.Object, boolean, boolean, boolean, int, boolean) on any tree node of the treePath and returns the texts as an array.
protected  java.lang.String convertValueToText(java.lang.Object node, int row)
          Calls JTree.convertValueToText(java.lang.Object, boolean, boolean, boolean, int, boolean) on the passed JTree.
 void expandNode(java.lang.Object node)
          Expands the given node.
 java.lang.Object getChild(java.lang.Object parent, int index)
          
 java.lang.Object[] getChildren(java.lang.Object parent)
          
 java.lang.ClassLoader getClassLoaderForTree()
          
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          
protected  javax.swing.tree.TreeModel getModel()
          Getter for the model
 java.awt.Rectangle getNodeBounds(java.lang.Object node)
          
 java.util.Collection getNodeTextList(java.lang.Object node)
          Returns the result of toString on the node value and, if it can be obtained, the rendered value.
 int getNumberOfChildren(java.lang.Object parent)
          
 java.lang.Object getParent(java.lang.Object child)
          
 java.lang.String getRenderedText(java.lang.Object node)
          Returns the rendered text for the given node.
 java.lang.Object[] getRootNodes()
          
protected  int getRowForTreeNode(java.lang.Object node)
          Returns the row for the given node.
 java.lang.Object getSelectedNode()
          
protected  java.lang.Object[] getSelectionPaths()
          Returns the path of all selected values.
 java.awt.Rectangle getVisibleRowBounds(java.awt.Rectangle rowBounds)
          Computes the visible rowBounds inside the visible bounds of the tree.
The result is the intersection of the visible bounds of the tree and the rowBounds of the node.
 boolean isExpanded(java.lang.Object node)
          
 boolean isVisible(java.lang.Object node)
          Returns true if the node is visible
 void scrollNodeToVisible(java.lang.Object node)
          Scrolls the Tree's container, if necessary, in order to ensure that the given node is viewable.
 
Methods inherited from class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
getQueuer, getRobot, getTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeOperationContext

public TreeOperationContext(org.eclipse.jubula.rc.common.driver.IEventThreadQueuer queuer,
                            org.eclipse.jubula.rc.common.driver.IRobot robot,
                            javax.swing.JTree tree)
Creates a new instance. The JTree must have a tree model.

Parameters:
queuer - The queuer
robot - The Robot
tree - The tree
Method Detail

getChildren

public java.lang.Object[] getChildren(java.lang.Object parent)

Specified by:
getChildren in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
parent - The parent node. Can be null.
Returns:
an Array containing all child nodes of parent, or all root nodes if parent is null.

getNodeTextList

public java.util.Collection getNodeTextList(java.lang.Object node)
Returns the result of toString on the node value and, if it can be obtained, the rendered value. Consider using AbstractTreeOperationContext.getRenderedText(Object) instead if only the rendered text is needed.

Specified by:
getNodeTextList in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - the node
Returns:
a collection with the text strings of the node

getNumberOfChildren

public int getNumberOfChildren(java.lang.Object parent)

Specified by:
getNumberOfChildren in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
parent - The parent node. Can be null.
Returns:
the number of child nodes for parent, or the number of graphical root nodes if parent == null.

convertValueToText

protected java.lang.String convertValueToText(java.lang.Object node,
                                              int row)
                                       throws org.eclipse.jubula.rc.common.exception.StepExecutionException
Calls JTree.convertValueToText(java.lang.Object, boolean, boolean, boolean, int, boolean) on the passed JTree.

Specified by:
convertValueToText in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node.
row - The node row.
Returns:
The converted text
Throws:
org.eclipse.jubula.rc.common.exception.StepExecutionException - If the method call fails.

getRenderedText

public java.lang.String getRenderedText(java.lang.Object node)
                                 throws org.eclipse.jubula.rc.common.exception.StepExecutionException
Returns the rendered text for the given node.

Specified by:
getRenderedText in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The tree node for which to get the rendered text.
Returns:
the rendered text for the given node, or null if the given node does not have rendered text or if the rendered text cannot be determined.
Throws:
org.eclipse.jubula.rc.common.exception.StepExecutionException - If the method call fails (for example, if the given node could not be found).

convertTreePathToText

protected java.lang.String[] convertTreePathToText(java.lang.Object treePath)
Calls JTree.convertValueToText(java.lang.Object, boolean, boolean, boolean, int, boolean) on any tree node of the treePath and returns the texts as an array.

Parameters:
treePath - The tree path
Returns:
The array of converted texts

getRowForTreeNode

protected int getRowForTreeNode(java.lang.Object node)
                         throws org.eclipse.jubula.rc.common.exception.StepExecutionException
Returns the row for the given node. The row is calculated based on how many nodes are visible above this node.

Parameters:
node - The node for which to find the row.
Returns:
A zero-based index representing the row that the given node occupies in the tree.
Throws:
org.eclipse.jubula.rc.common.exception.StepExecutionException - if the node cannot be found.

getNodeBounds

public java.awt.Rectangle getNodeBounds(java.lang.Object node)
                                 throws org.eclipse.jubula.rc.common.exception.StepExecutionException

Specified by:
getNodeBounds in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node for which to find the bounds.
Returns:
the graphical bounds of the node, as a java.awt.Rectangle.
Throws:
org.eclipse.jubula.rc.common.exception.StepExecutionException

getSelectionPaths

protected java.lang.Object[] getSelectionPaths()
Returns the path of all selected values.

Returns:
an array of Objects indicating the selected nodes, or null if nothing is currently selected.

isVisible

public boolean isVisible(java.lang.Object node)
Returns true if the node is visible

Specified by:
isVisible in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - a node
Returns:
if the node is visible

getModel

protected javax.swing.tree.TreeModel getModel()
Getter for the model

Returns:
Returns the model.

getVisibleRowBounds

public java.awt.Rectangle getVisibleRowBounds(java.awt.Rectangle rowBounds)
Computes the visible rowBounds inside the visible bounds of the tree.
The result is the intersection of the visible bounds of the tree and the rowBounds of the node.

Specified by:
getVisibleRowBounds in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
rowBounds - the rowBounds of the node to click in. These bounds must be relative to the tree's location.
Returns:
the visible rowBounds, relative to the tree's location.

getClassLoaderForTree

public java.lang.ClassLoader getClassLoaderForTree()

Specified by:
getClassLoaderForTree in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Returns:
The ClassLoader for the tree

collapseNode

public void collapseNode(java.lang.Object node)
Collapses the given node.

Specified by:
collapseNode in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node

expandNode

public void expandNode(java.lang.Object node)
Expands the given node.

Specified by:
expandNode in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node

getRootNodes

public java.lang.Object[] getRootNodes()

Specified by:
getRootNodes in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Returns:
All top-level nodes for the tree. These are the highest-level nodes that the user can see.

scrollNodeToVisible

public void scrollNodeToVisible(java.lang.Object node)
Scrolls the Tree's container, if necessary, in order to ensure that the given node is viewable.

Specified by:
scrollNodeToVisible in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)

Specified by:
getChild in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
parent - The parent node. Can be null.
index - The index for the child node.
Returns:
the child node of parent with index index in the parent's child node list. If parent is null, then the nth graphical root node will be returned, where n is equal to index (i.e. when index == 0, the topmost root node will be returned).

getParent

public java.lang.Object getParent(java.lang.Object child)

Specified by:
getParent in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
child - The child node.
Returns:
The parent node of the given node, or null if the node is a graphical root node.

isExpanded

public boolean isExpanded(java.lang.Object node)

Specified by:
isExpanded in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node
Returns:
true if the given node is currently expanded. Otherwise, false.

clickNode

public void clickNode(java.lang.Object node,
                      org.eclipse.jubula.rc.common.driver.ClickOptions clickOps)
Move the mouse pointer directly over the given node's onscreen location and perform a mouse click.

Specified by:
clickNode in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
node - The node
clickOps - The click options

getSelectedNode

public java.lang.Object getSelectedNode()

Specified by:
getSelectedNode in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Returns:
The currently selected node.

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)

Specified by:
getIndexOfChild in class org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext
Parameters:
parent - The parent node, can be null
child - The child node
Returns:
the index of the given child in the given parent's child node list, or -1 if child is not a child of parent. If parent is null, then child is assumed to be a root node, and the returned index will be determined by the order in which the root nodes are displayed (i.e. the topmost root node will have an index of 0).