Class JTreeDriver
JTrees:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final JTreeLocationprivate final JTreePathFinderprivate static final StringFields inherited from class org.fest.swing.driver.ComponentDriver
robot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidassertEditable(JTree tree, boolean editable) (package private) JTreeCellReadervoidcellReader(JTreeCellReader newCellReader) Updates the implementation ofto use when comparing internal values of aJTreeCellReaderand the values expected in a test.JTreeprivate voidclearSelection(JTree tree) voidClicks the given path, expanding parent nodes if necessary.voidclickPath(JTree tree, String path, MouseButton button) Clicks the given path, expanding parent nodes if necessary.private voidclickPath(JTree tree, String path, MouseButton button, int times) voidclickPath(JTree tree, String path, MouseClickInfo mouseClickInfo) Clicks the given path, expanding parent nodes if necessary.voidClicks the given row.voidclickRow(JTree tree, int row, MouseButton button) Clicks the given row.private voidclickRow(JTree tree, int row, MouseButton button, int times) voidclickRow(JTree tree, int row, MouseClickInfo mouseClickInfo) Clicks the given row.voidcollapsePath(JTree tree, String path) Collapses the given path, is possible.voidcollapseRow(JTree tree, int row) Collapses the given row, is possible.private voiddoubleClick(JTree tree, Point p) voiddoubleClickPath(JTree tree, String path) Double-clicks the given path.voiddoubleClickRow(JTree tree, int row) Double-clicks the given row.voidStarts a drag operation at the location of the given row.voidStarts a drag operation at the location of the given.TreePathvoidEnds a drag operation at the location of the given row.voidEnds a drag operation at the location of the given.TreePathprivate static org.fest.assertions.DescriptioneditableProperty(JTree tree) voidexpandPath(JTree tree, String path) Expands the given path, is possible.voidExpands the given row, is possible.private booleanmakeParentVisible(JTree tree, TreePath path) private booleanmakeVisible(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 theStringrepresentation of the node at the given row index.Returns theStringrepresentation of the node at the given path.voidrequireEditable(JTree tree) Asserts that the givenis editable.JTreevoidrequireNoSelection(JTree tree) Asserts that the givendoes not have any selection.JTreevoidrequireNotEditable(JTree tree) Asserts that the givenis not editable.JTreevoidrequireSelection(JTree tree, int[] rows) Asserts that the given's selected rows are equal to the given one.JTreevoidrequireSelection(JTree tree, String[] paths) Asserts that the given's selected paths are equal to the given one.JTreeprivate voidrightClick(JTree tree, Point p) voidrightClickPath(JTree tree, String path) Right-clicks the given path, expanding parent nodes if necessary.voidrightClickRow(JTree tree, int row) Right-clicks the given row.private PointscrollAndSelectRow(JTree tree, int row) scrollToMatchingPath(JTree tree, String path) scrollToMatchingPathAndGetToggleInfo(JTree tree, String path, JTreePathFinder pathFinder, JTreeLocation location) private PointscrollToPath(JTree tree, String path) scrollToPathToSelect(JTree tree, TreePath path, JTreeLocation location) private PointscrollToRow(JTree tree, int row) scrollToRow(JTree tree, int row, JTreeLocation location) scrollToRowAndGetToggleInfo(JTree tree, int row, JTreeLocation location) private static PointscrollToTreePath(JTree tree, TreePath path, JTreeLocation location) private static PointscrollToVisible(JTree tree, int row, JTreeLocation location) private org.fest.assertions.DescriptionselectionProperty(JTree tree) private PointselectMatchingPath(JTree tree, String path) voidselectPath(JTree tree, String path) Selects the given path, expanding parent nodes if necessary.voidselectPaths(JTree tree, String[] paths) Selects the given paths, expanding parent nodes if necessary.voidSelects the given row.voidselectRows(JTree tree, int[] rows) Selects the given rows.Returns the separator to use when convertings toTreePathStrings.voidUpdates the separator to use when convertings toTreePathStrings.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 voidtoggleCell(JTree tree, Point p, int toggleClickCount) voidChange the open/closed state of the given row, if possible.private static voidtoggleRowThroughTreeUI(JTree tree, Point p) private voidvalidateIsNotNull(MouseButton button) private voidvalidateIsNotNull(MouseClickInfo mouseClickInfo) voidvalidatePath(JTree tree, String path) Verifies that the given node path exists.private voidvalidatePaths(String[] paths) voidvalidateRow(JTree tree, int row) Verifies that the given row index is valid.private voidvalidateRows(int[] rows) private voidwaitForChildrenToShowUp(JTree tree, TreePath path) Methods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisibleMethods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidthMethods 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 givenMouseClickInfoisnull.IllegalStateException- if theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 givenMouseClickInfoisnull.IllegalStateException- if theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 theJTreeis disabled.IllegalStateException- if theJTreeis 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 givenJTreeselection 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 givenJTreeselection is not equal to the given paths.- See Also:
-
requireNoSelection
Asserts that the givendoes not have any selection.JTree- Parameters:
tree- the givenJTree.- Throws:
AssertionError- if theJTreehas a selection.
-
selectionProperty
-
requireEditable
Asserts that the givenis editable.JTree- Parameters:
tree- the givenJTree.- Throws:
AssertionError- if theJTreeis not editable.
-
requireNotEditable
Asserts that the givenis not editable.JTree- Parameters:
tree- the givenJTree.- Throws:
AssertionError- if theJTreeis editable.
-
assertEditable
-
editableProperty
-
separator
Returns the separator to use when convertings toTreePathStrings.- Returns:
- the separator to use when converting
s toTreePathStrings.
-
separator
Updates the separator to use when convertings toTreePathStrings.- Parameters:
newSeparator- the new separator.- Throws:
NullPointerException- if the given separator isnull.
-
cellReader
Updates the implementation ofto use when comparing internal values of aJTreeCellReaderand the values expected in a test.JTree- Parameters:
newCellReader- the newJTreeCellValueReaderto use.- Throws:
NullPointerException- ifnewCellReaderisnull.
-
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 theStringrepresentation of the node at the given path.- Parameters:
tree- the givenJTree.path- the given path.- Returns:
- the
Stringrepresentation of the node at the given path. - Throws:
LocationUnavailableException- if the given path cannot be found.- Since:
- 1.2
-
nodeValue
Returns theStringrepresentation of the node at the given row index.- Parameters:
tree- the givenJTree.row- the given row.- Returns:
- the
Stringrepresentation 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()
-