Class JTreeDriver
JTree
s:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture
in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private final JTreeLocation
private final JTreePathFinder
private static final String
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
assertEditable
(JTree tree, boolean editable) (package private) JTreeCellReader
void
cellReader
(JTreeCellReader newCellReader) Updates the implementation of
to use when comparing internal values of aJTreeCellReader
and the values expected in a test.JTree
private void
clearSelection
(JTree tree) void
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.private void
clickPath
(JTree tree, String path, MouseButton button, int times) void
clickPath
(JTree tree, String path, MouseClickInfo mouseClickInfo) Clicks the given path, expanding parent nodes if necessary.void
Clicks the given row.void
clickRow
(JTree tree, int row, MouseButton button) Clicks the given row.private void
clickRow
(JTree tree, int row, MouseButton button, int times) 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.private void
doubleClick
(JTree tree, Point p) void
doubleClickPath
(JTree tree, String path) Double-clicks the given path.void
doubleClickRow
(JTree tree, int row) Double-clicks the given row.void
Starts a drag operation at the location of the given row.void
Starts a drag operation at the location of the given
.TreePath
void
Ends a drag operation at the location of the given row.void
Ends a drag operation at the location of the given
.TreePath
private static org.fest.assertions.Description
editableProperty
(JTree tree) void
expandPath
(JTree tree, String path) Expands the given path, is possible.void
Expands the given row, is possible.private boolean
makeParentVisible
(JTree tree, TreePath path) private boolean
makeVisible
(JTree tree, TreePath path, boolean expandWhenFound) Matches, makes visible, and expands the path one component at a time, from uppermost ancestor on down, since children may be lazily loaded/created.Returns theString
representation of the node at the given row index.Returns theString
representation of the node at the given path.void
requireEditable
(JTree tree) Asserts that the given
is editable.JTree
void
requireNoSelection
(JTree tree) Asserts that the given
does not have any selection.JTree
void
requireNotEditable
(JTree tree) Asserts that the given
is not editable.JTree
void
requireSelection
(JTree tree, int[] rows) Asserts that the given
's selected rows are equal to the given one.JTree
void
requireSelection
(JTree tree, String[] paths) Asserts that the given
's selected paths are equal to the given one.JTree
private void
rightClick
(JTree tree, Point p) 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.private Point
scrollAndSelectRow
(JTree tree, int row) scrollToMatchingPath
(JTree tree, String path) scrollToMatchingPathAndGetToggleInfo
(JTree tree, String path, JTreePathFinder pathFinder, JTreeLocation location) private Point
scrollToPath
(JTree tree, String path) scrollToPathToSelect
(JTree tree, TreePath path, JTreeLocation location) private Point
scrollToRow
(JTree tree, int row) scrollToRow
(JTree tree, int row, JTreeLocation location) scrollToRowAndGetToggleInfo
(JTree tree, int row, JTreeLocation location) private static Point
scrollToTreePath
(JTree tree, TreePath path, JTreeLocation location) private static Point
scrollToVisible
(JTree tree, int row, JTreeLocation location) private org.fest.assertions.Description
selectionProperty
(JTree tree) private Point
selectMatchingPath
(JTree tree, String path) 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
Selects the given row.void
selectRows
(JTree tree, int[] rows) Selects the given rows.Returns the separator to use when converting
s toTreePath
String
s.void
Updates the separator to use when converting
s toTreePath
String
s.showPopupMenu
(JTree tree, int row) Shows a pop-up menu at the position of the node in the given row.showPopupMenu
(JTree tree, String path) Shows a pop-up menu at the position of the last node in the given path.private void
toggleCell
(JTree tree, Point p, int toggleClickCount) void
Change the open/closed state of the given row, if possible.private static void
toggleRowThroughTreeUI
(JTree tree, Point p) private void
validateIsNotNull
(MouseButton button) private void
validateIsNotNull
(MouseClickInfo mouseClickInfo) void
validatePath
(JTree tree, String path) Verifies that the given node path exists.private void
validatePaths
(String[] paths) void
validateRow
(JTree tree, int row) Verifies that the given row index is valid.private void
validateRows
(int[] rows) private void
waitForChildrenToShowUp
(JTree tree, TreePath path) 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
-
Field Details
-
EDITABLE_PROPERTY
- See Also:
-
SELECTION_PROPERTY
- See Also:
-
location
-
pathFinder
-
-
Constructor Details
-
JTreeDriver
Creates a newJTreeDriver
.- Parameters:
robot
- the robot to use to simulate user input.
-
-
Method Details
-
clickRow
Clicks the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.- Since:
- 1.2
-
clickRow
Clicks the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.button
- the mouse button to use.- Throws:
NullPointerException
- if the given button isnull
.IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.- Since:
- 1.2
-
clickRow
Clicks the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.mouseClickInfo
- specifies the mouse button to use and how many times to click.- Throws:
NullPointerException
- if the givenMouseClickInfo
isnull
.IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.- Since:
- 1.2
-
clickRow
-
doubleClickRow
Double-clicks the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.- Since:
- 1.2
-
rightClickRow
Right-clicks the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.- Since:
- 1.2
-
scrollToRow
-
clickPath
Clicks the given path, expanding parent nodes if necessary.- Parameters:
tree
- the targetJTree
.path
- the path to path.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.
-
clickPath
Clicks the given path, expanding parent nodes if necessary.- Parameters:
tree
- the targetJTree
.path
- the path to path.button
- the mouse button to use.- Throws:
NullPointerException
- if the given button isnull
.IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.- Since:
- 1.2
-
validateIsNotNull
-
clickPath
Clicks the given path, expanding parent nodes if necessary.- Parameters:
tree
- the targetJTree
.path
- the path to path.mouseClickInfo
- specifies the mouse button to use and how many times to click.- Throws:
NullPointerException
- if the givenMouseClickInfo
isnull
.IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.- Since:
- 1.2
-
validateIsNotNull
-
clickPath
-
doubleClickPath
Double-clicks the given path.- Parameters:
tree
- the targetJTree
.path
- the path to double-click.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.- Since:
- 1.2
-
scrollToPath
-
doubleClick
-
rightClickPath
Right-clicks the given path, expanding parent nodes if necessary.- Parameters:
tree
- the targetJTree
.path
- the path to path.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.- Since:
- 1.2
-
rightClick
-
expandRow
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 targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.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
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 targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.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
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 targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if this method fails to toggle the row.
-
scrollToRowAndGetToggleInfo
@RunsInEDT private static Triple<Boolean,Point, scrollToRowAndGetToggleInfoInteger> (JTree tree, int row, JTreeLocation location) -
expandPath
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 targetJTree
.path
- the path to expand.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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
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 targetJTree
.path
- the path to collapse.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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
-
scrollToMatchingPathAndGetToggleInfo
@RunsInEDT private static Triple<Boolean,Point, scrollToMatchingPathAndGetToggleInfoInteger> (JTree tree, String path, JTreePathFinder pathFinder, JTreeLocation location) -
toggleCell
-
toggleRowThroughTreeUI
-
selectRows
Selects the given rows.- Parameters:
tree
- the targetJTree
.rows
- the rows to select.- Throws:
NullPointerException
- if the array of rows isnull
.IllegalArgumentException
- if the array of rows is empty.IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for any of the given rows cannot be found.
-
validateRows
private void validateRows(int[] rows) -
clearSelection
-
selectRow
Selects the given row.- Parameters:
tree
- the targetJTree
.row
- the row to select.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.
-
selectPaths
Selects the given paths, expanding parent nodes if necessary.- Parameters:
tree
- the targetJTree
.paths
- the paths to select.- Throws:
NullPointerException
- if the array of rows isnull
.IllegalArgumentException
- if the array of rows is empty.IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if any the given path cannot be found.
-
validatePaths
-
selectPath
Selects the given path, expanding parent nodes if necessary. Unlike
, this method will not click the path if it is already selectedclickPath(JTree, String)
- Parameters:
tree
- the targetJTree
.path
- the path to select.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.
-
showPopupMenu
Shows a pop-up menu at the position of the node in the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.- Returns:
- a driver that manages the displayed pop-up menu.
- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.
-
showPopupMenu
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 targetJTree
.path
- the given path.- Returns:
- a driver that manages the displayed pop-up menu.
- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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:
-
drag
Starts a drag operation at the location of the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.
-
scrollAndSelectRow
-
drop
Ends a drag operation at the location of the given row.- Parameters:
tree
- the targetJTree
.row
- the given row.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if there is no drag action in effect.
-
scrollToRow
@RunsInEDT private static Pair<Boolean,Point> scrollToRow(JTree tree, int row, JTreeLocation location) -
scrollToVisible
@RunsInCurrentThread private static Point scrollToVisible(JTree tree, int row, JTreeLocation location) -
drag
Starts a drag operation at the location of the given
.TreePath
- Parameters:
tree
- the targetJTree
.path
- the given path.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.- See Also:
-
selectMatchingPath
-
drop
Ends a drag operation at the location of the given
.TreePath
- Parameters:
tree
- the targetJTree
.path
- the given path.- Throws:
IllegalStateException
- if theJTree
is disabled.IllegalStateException
- if theJTree
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:
-
scrollToMatchingPath
-
scrollToPathToSelect
@RunsInEDT private static Pair<Boolean,Point> scrollToPathToSelect(JTree tree, TreePath path, JTreeLocation location) -
scrollToTreePath
@RunsInCurrentThread private static Point scrollToTreePath(JTree tree, TreePath path, JTreeLocation location) -
makeParentVisible
-
makeVisible
Matches, makes visible, and expands the path one component at a time, from uppermost ancestor on down, since children may be lazily loaded/created.- Parameters:
tree
- the targetJTree
.path
- the tree path to make visible.expandWhenFound
- indicates if nodes should be expanded or not when found.- Returns:
- if it was necessary to make visible and/or expand a node in the path.
-
waitForChildrenToShowUp
-
requireSelection
Asserts that the given
's selected rows are equal to the given one.JTree
- Parameters:
tree
- the targetJTree
.rows
- the indices of the rows, expected to be selected.- Throws:
NullPointerException
- if the array of row indices isnull
.AssertionError
- if the givenJTree
selection is not equal to the given rows.
-
requireSelection
Asserts that the given
's selected paths are equal to the given one.JTree
- Parameters:
tree
- the targetJTree
.paths
- the given paths, expected to be selected.- Throws:
NullPointerException
- if the array of paths isnull
.LocationUnavailableException
- if any of the given paths cannot be found.AssertionError
- if the givenJTree
selection is not equal to the given paths.- See Also:
-
requireNoSelection
Asserts that the given
does not have any selection.JTree
- Parameters:
tree
- the givenJTree
.- Throws:
AssertionError
- if theJTree
has a selection.
-
selectionProperty
-
requireEditable
Asserts that the given
is editable.JTree
- Parameters:
tree
- the givenJTree
.- Throws:
AssertionError
- if theJTree
is not editable.
-
requireNotEditable
Asserts that the given
is not editable.JTree
- Parameters:
tree
- the givenJTree
.- Throws:
AssertionError
- if theJTree
is editable.
-
assertEditable
-
editableProperty
-
separator
Returns the separator to use when converting
s toTreePath
String
s.- Returns:
- the separator to use when converting
s toTreePath
String
s.
-
separator
Updates the separator to use when converting
s toTreePath
String
s.- Parameters:
newSeparator
- the new separator.- Throws:
NullPointerException
- if the given separator isnull
.
-
cellReader
Updates the implementation of
to use when comparing internal values of aJTreeCellReader
and the values expected in a test.JTree
- Parameters:
newCellReader
- the newJTreeCellValueReader
to use.- Throws:
NullPointerException
- ifnewCellReader
isnull
.
-
validateRow
Verifies that the given row index is valid.- Parameters:
tree
- the givenJTree
.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 theJTree
.- Since:
- 1.2
-
validatePath
Verifies that the given node path exists.- Parameters:
tree
- the givenJTree
.path
- the given path.- Throws:
LocationUnavailableException
- if the given path cannot be found.- Since:
- 1.2
-
nodeValue
Returns theString
representation of the node at the given path.- Parameters:
tree
- the givenJTree
.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
Returns theString
representation of the node at the given row index.- Parameters:
tree
- the givenJTree
.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 theJTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.- Since:
- 1.2
-
cellReader
JTreeCellReader cellReader()
-