org.fest.swing.driver
Class JTreeDriver

java.lang.Object
  extended by org.fest.swing.driver.ComponentDriver
      extended by org.fest.swing.driver.ContainerDriver
          extended by org.fest.swing.driver.JComponentDriver
              extended by org.fest.swing.driver.JTreeDriver

public class JTreeDriver
extends JComponentDriver

Understands functional testing of JTrees:

This class is intended for internal use only. Please use the classes in the package org.fest.swing.fixture in your tests.

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
 
Constructor Summary
JTreeDriver(Robot robot)
          Creates a new JTreeDriver.
 
Method Summary
 void cellReader(JTreeCellReader newCellReader)
          Updates the implementation of JTreeCellReader to use when comparing internal values of a JTree and the values expected in a test.
 void clickPath(JTree tree, String path)
          Clicks the given path, expanding parent nodes if necessary.
 void clickPath(JTree tree, String path, MouseButton button)
          Clicks the given path, expanding parent nodes if necessary.
 void clickPath(JTree tree, String path, MouseClickInfo mouseClickInfo)
          Clicks the given path, expanding parent nodes if necessary.
 void clickRow(JTree tree, int row)
          Clicks the given row.
 void clickRow(JTree tree, int row, MouseButton button)
          Clicks the given row.
 void clickRow(JTree tree, int row, MouseClickInfo mouseClickInfo)
          Clicks the given row.
 void collapsePath(JTree tree, String path)
          Collapses the given path, is possible.
 void collapseRow(JTree tree, int row)
          Collapses the given row, is possible.
 void doubleClickPath(JTree tree, String path)
          Double-clicks the given path.
 void doubleClickRow(JTree tree, int row)
          Double-clicks the given row.
 void drag(JTree tree, int row)
          Starts a drag operation at the location of the given row.
 void drag(JTree tree, String path)
          Starts a drag operation at the location of the given TreePath.
 void drop(JTree tree, int row)
          Ends a drag operation at the location of the given row.
 void drop(JTree tree, String path)
          Ends a drag operation at the location of the given TreePath.
 void expandPath(JTree tree, String path)
          Expands the given path, is possible.
 void expandRow(JTree tree, int row)
          Expands the given row, is possible.
 String nodeValue(JTree tree, int row)
          Returns the String representation of the node at the given row index.
 String nodeValue(JTree tree, String path)
          Returns the String representation of the node at the given path.
 void requireEditable(JTree tree)
          Asserts that the given JTree is editable.
 void requireNoSelection(JTree tree)
          Asserts that the given JTree does not have any selection.
 void requireNotEditable(JTree tree)
          Asserts that the given JTree is not editable.
 void requireSelection(JTree tree, int[] rows)
          Asserts that the given JTree's selected rows are equal to the given one.
 void requireSelection(JTree tree, String[] paths)
          Asserts that the given JTree's selected paths are equal to the given one.
 void rightClickPath(JTree tree, String path)
          Right-clicks the given path, expanding parent nodes if necessary.
 void rightClickRow(JTree tree, int row)
          Right-clicks the given row.
 void selectPath(JTree tree, String path)
          Selects the given path, expanding parent nodes if necessary.
 void selectPaths(JTree tree, String[] paths)
          Selects the given paths, expanding parent nodes if necessary.
 void selectRow(JTree tree, int row)
          Selects the given row.
 void selectRows(JTree tree, int[] rows)
          Selects the given rows.
 String separator()
          Returns the separator to use when converting TreePaths to Strings.
 void separator(String newSeparator)
          Updates the separator to use when converting TreePaths to Strings.
 JPopupMenu showPopupMenu(JTree tree, int row)
          Shows a pop-up menu at the position of the node in the given row.
 JPopupMenu showPopupMenu(JTree tree, String path)
          Shows a pop-up menu at the position of the last node in the given path.
 void toggleRow(JTree tree, int row)
          Change the open/closed state of the given row, if possible.
 void validatePath(JTree tree, String path)
          Verifies that the given node path exists.
 void validateRow(JTree tree, int row)
          Verifies that the given row index is valid.
 
Methods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisible
 
Methods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidth
 
Methods inherited from class org.fest.swing.driver.ComponentDriver
assertIsEnabledAndShowing, click, click, click, click, click, doubleClick, drag, dragOver, drop, focus, focusAndWaitForFocusGain, invokePopupMenu, invokePopupMenu, moveMouseIgnoringAnyError, moveMouseIgnoringAnyError, performAccessibleActionOf, pressAndReleaseKey, pressAndReleaseKey, pressAndReleaseKeys, pressKey, propertyName, releaseKey, requireDisabled, requireEnabled, requireEnabled, requireFocused, requireNotVisible, requireSize, requireVisible, rightClick, settings, waitForShowing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTreeDriver

public JTreeDriver(Robot robot)
Creates a new JTreeDriver.

Parameters:
robot - the robot to use to simulate user input.
Method Detail

clickRow

@RunsInEDT
public void clickRow(JTree tree,
                               int row)
Clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
Since:
1.2

clickRow

@RunsInEDT
public void clickRow(JTree tree,
                               int row,
                               MouseButton button)
Clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
button - the mouse button to use.
Throws:
NullPointerException - if the given button is null.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
Since:
1.2

clickRow

@RunsInEDT
public void clickRow(JTree tree,
                               int row,
                               MouseClickInfo mouseClickInfo)
Clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
mouseClickInfo - specifies the mouse button to use and how many times to click.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
Since:
1.2

doubleClickRow

@RunsInEDT
public void doubleClickRow(JTree tree,
                                     int row)
Double-clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
Since:
1.2

rightClickRow

@RunsInEDT
public void rightClickRow(JTree tree,
                                    int row)
Right-clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
Since:
1.2

clickPath

@RunsInEDT
public void clickPath(JTree tree,
                                String path)
Clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

clickPath

@RunsInEDT
public void clickPath(JTree tree,
                                String path,
                                MouseButton button)
Clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
button - the mouse button to use.
Throws:
NullPointerException - if the given button is null.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
Since:
1.2

clickPath

@RunsInEDT
public void clickPath(JTree tree,
                                String path,
                                MouseClickInfo mouseClickInfo)
Clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
mouseClickInfo - specifies the mouse button to use and how many times to click.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
Since:
1.2

doubleClickPath

@RunsInEDT
public void doubleClickPath(JTree tree,
                                      String path)
Double-clicks the given path.

Parameters:
tree - the target JTree.
path - the path to double-click.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
Since:
1.2

rightClickPath

@RunsInEDT
public void rightClickPath(JTree tree,
                                     String path)
Right-clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
Since:
1.2

expandRow

@RunsInEDT
public void expandRow(JTree tree,
                                int row)
Expands the given row, is possible. If the row is already expanded, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
ActionFailedException - if this method fails to expand the row.
Since:
1.2

collapseRow

@RunsInEDT
public void collapseRow(JTree tree,
                                  int row)
Collapses the given row, is possible. If the row is already collapsed, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
ActionFailedException - if this method fails to collapse the row.
Since:
1.2

toggleRow

@RunsInEDT
public void toggleRow(JTree tree,
                                int row)
Change the open/closed state of the given row, if possible.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
ActionFailedException - if this method fails to toggle the row.

expandPath

@RunsInEDT
public void expandPath(JTree tree,
                                 String path)
Expands the given path, is possible. If the path is already expanded, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
path - the path to expand.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
ActionFailedException - if this method fails to expand the path.
Since:
1.2

collapsePath

@RunsInEDT
public void collapsePath(JTree tree,
                                   String path)
Collapses the given path, is possible. If the path is already expanded, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
path - the path to collapse.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
ActionFailedException - if this method fails to collapse the path.
Since:
1.2

selectRows

@RunsInEDT
public void selectRows(JTree tree,
                                 int[] rows)
Selects the given rows.

Parameters:
tree - the target JTree.
rows - the rows to select.
Throws:
NullPointerException - if the array of rows is null.
IllegalArgumentException - if the array of rows is empty.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if any of the given rows is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for any of the given rows cannot be found.

selectRow

@RunsInEDT
public void selectRow(JTree tree,
                                int row)
Selects the given row.

Parameters:
tree - the target JTree.
row - the row to select.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.

selectPaths

@RunsInEDT
public void selectPaths(JTree tree,
                                  String[] paths)
Selects the given paths, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
paths - the paths to select.
Throws:
NullPointerException - if the array of rows is null.
IllegalArgumentException - if the array of rows is empty.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if any the given path cannot be found.

selectPath

@RunsInEDT
public void selectPath(JTree tree,
                                 String path)
Selects the given path, expanding parent nodes if necessary. Unlike clickPath(JTree, String), this method will not click the path if it is already selected

Parameters:
tree - the target JTree.
path - the path to select.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

showPopupMenu

@RunsInEDT
public JPopupMenu showPopupMenu(JTree tree,
                                          int row)
Shows a pop-up menu at the position of the node in the given row.

Parameters:
tree - the target JTree.
row - the given row.
Returns:
a driver that manages the displayed pop-up menu.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.

showPopupMenu

@RunsInEDT
public JPopupMenu showPopupMenu(JTree tree,
                                          String path)
Shows a pop-up menu at the position of the last node in the given path. The last node in the given path will be made visible (by expanding the parent node(s)) if it is not visible.

Parameters:
tree - the target JTree.
path - the given path.
Returns:
a driver that manages the displayed pop-up menu.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.
LocationUnavailableException - if the given path cannot be found.
See Also:
separator(String)

drag

@RunsInEDT
public void drag(JTree tree,
                           int row)
Starts a drag operation at the location of the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.

drop

@RunsInEDT
public void drop(JTree tree,
                           int row)
Ends a drag operation at the location of the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
ActionFailedException - if there is no drag action in effect.

drag

@RunsInEDT
public void drag(JTree tree,
                           String path)
Starts a drag operation at the location of the given TreePath.

Parameters:
tree - the target JTree.
path - the given path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
See Also:
separator(String)

drop

@RunsInEDT
public void drop(JTree tree,
                           String path)
Ends a drag operation at the location of the given TreePath.

Parameters:
tree - the target JTree.
path - the given path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
ActionFailedException - if there is no drag action in effect.
See Also:
separator(String)

requireSelection

@RunsInEDT
public void requireSelection(JTree tree,
                                       int[] rows)
Asserts that the given JTree's selected rows are equal to the given one.

Parameters:
tree - the target JTree.
rows - the indices of the rows, expected to be selected.
Throws:
NullPointerException - if the array of row indices is null.
AssertionError - if the given JTree selection is not equal to the given rows.

requireSelection

@RunsInEDT
public void requireSelection(JTree tree,
                                       String[] paths)
Asserts that the given JTree's selected paths are equal to the given one.

Parameters:
tree - the target JTree.
paths - the given paths, expected to be selected.
Throws:
NullPointerException - if the array of paths is null.
LocationUnavailableException - if any of the given paths cannot be found.
AssertionError - if the given JTree selection is not equal to the given paths.
See Also:
separator(String)

requireNoSelection

@RunsInEDT
public void requireNoSelection(JTree tree)
Asserts that the given JTree does not have any selection.

Parameters:
tree - the given JTree.
Throws:
AssertionError - if the JTree has a selection.

requireEditable

@RunsInEDT
public void requireEditable(JTree tree)
Asserts that the given JTree is editable.

Parameters:
tree - the given JTree.
Throws:
AssertionError - if the JTree is not editable.

requireNotEditable

@RunsInEDT
public void requireNotEditable(JTree tree)
Asserts that the given JTree is not editable.

Parameters:
tree - the given JTree.
Throws:
AssertionError - if the JTree is editable.

separator

public String separator()
Returns the separator to use when converting TreePaths to Strings.

Returns:
the separator to use when converting TreePaths to Strings.

separator

public void separator(String newSeparator)
Updates the separator to use when converting TreePaths to Strings.

Parameters:
newSeparator - the new separator.
Throws:
NullPointerException - if the given separator is null.

cellReader

public void cellReader(JTreeCellReader newCellReader)
Updates the implementation of JTreeCellReader to use when comparing internal values of a JTree and the values expected in a test.

Parameters:
newCellReader - the new JTreeCellValueReader to use.
Throws:
NullPointerException - if newCellReader is null.

validateRow

@RunsInEDT
public void validateRow(JTree tree,
                                  int row)
Verifies that the given row index is valid.

Parameters:
tree - the given JTree.
row - the given index.
Throws:
IndexOutOfBoundsException - if the given index is less than zero or equal than or greater than the number of visible rows in the JTree.
Since:
1.2

validatePath

@RunsInEDT
public void validatePath(JTree tree,
                                   String path)
Verifies that the given node path exists.

Parameters:
tree - the given JTree.
path - the given path.
Throws:
LocationUnavailableException - if the given path cannot be found.
Since:
1.2

nodeValue

@RunsInEDT
public String nodeValue(JTree tree,
                                  String path)
Returns the String representation of the node at the given path.

Parameters:
tree - the given JTree.
path - the given path.
Returns:
the String representation of the node at the given path.
Throws:
LocationUnavailableException - if the given path cannot be found.
Since:
1.2

nodeValue

public String nodeValue(JTree tree,
                        int row)
Returns the String representation of the node at the given row index.

Parameters:
tree - the given JTree.
row - the given row.
Returns:
the String representation of the node at the given row index.
Throws:
IndexOutOfBoundsException - if the given row is less than zero or equal than or greater than the number of visible rows in the JTree.
LocationUnavailableException - if a tree path for the given row cannot be found.
Since:
1.2


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.