public class Tree extends AbstractSwingUIComponent
The nodes of a tree are identified using stringified paths. For instance, for the tree below:
root
|
+- child
| |
| +- subChild
|
+- otherChild
|
+- otherSubChild
the "subChild" element is identified with the following path:
child/subChild
Note that when defining paths the root element name is always omitted. The root
node path itself is denoted by an empty string ("").The default path separator is "/". However, this separator can be customized as follows:
setSeparator(String)
setDefaultSeparator(String)
uispec4j.tree.separator
property.
otherChild/otherSubChild
one can write:
other/sub
The contents of the tree can be checked with contentEquals(String)
,
which is used as follows:
assertTrue(jTree.contentEquals("root\n" +
" child1\n" +
" child1_1\n" +
" child2"));
The conversion between the values (Strings) given in the tests and the values
actually displayed by the JTree renderer is performed by a dedicated
TreeCellValueConverter
, which retrieves the graphical component that draws
the tree nodes and determines the displayed value accordingly.
A DefaultTreeCellValueConverter
is used by default by the Tree component.
Modifier and Type | Field and Description |
---|---|
static Class[] |
SWING_CLASSES |
static String |
TYPE_NAME |
Modifier and Type | Method and Description |
---|---|
void |
addToSelection(String path)
Expands the current jTree selection with a given node.
|
void |
addToSelection(String parentPath,
int childIndex)
Expands the current jTree selection with a node identified by its position in its parent node.
|
void |
clearSelection()
Removes the current selection.
|
void |
click(String path)
Simulates a user left-click on a given node.
|
Assertion |
contains(String path)
Checks that a node identified by the given path is present in the jTree.
|
Assertion |
contentEquals(String expectedContents)
Checks the nodes structure displayed by the jTree.
|
void |
doubleClick(String path) |
void |
expand(String path,
boolean expand)
Expands or collapses a given node.
|
void |
expandAll()
Expands all the nodes of the jTree.
|
Assertion |
foregroundEquals(String path,
String color)
Checks the font color used on a given node.
|
JTree |
getAwtComponent()
Returns the Java GUI component represented by this object.
|
int |
getChildCount(String path)
Returns the number of children of a given node.
|
String |
getDescriptionTypeName()
Returns the name of the component as it will appear in the XML representation
returned by
UIComponent.getDescription() . |
JTree |
getJTree()
Returns the JTree wrapped by this component.
|
String |
getSeparator()
Returns the separator currently used for specifying node paths in this jTree instance.
|
Assertion |
pathIsExpanded(String path)
Checks that the a given node of the jTree is expanded - i.e.
|
void |
removeFromSelection(String path)
Removes the given node from the current jTree selection.
|
void |
rightClick(String path)
Simulates a user right-click on a given node.
|
void |
rightClickInSelection()
Right-clicks on the first selected node.
|
void |
select(String path)
Sets the selection on the given node.
|
void |
select(String[] paths) |
void |
select(String parentPath,
int childIndex)
Sets the jTree selection on a node identified by its position in its parent node.
|
void |
select(String parentPath,
String childSubstring)
Selects under a given parent all the nodes whose name contains a given substring.
|
Assertion |
selectionEquals(String path)
Checks that a given node is selected, and that is is the only selection.
|
Assertion |
selectionEquals(String[] paths)
Checks the selection contents.
|
Assertion |
selectionIsEmpty()
Checks that the selection is empty.
|
void |
selectRoot()
Selects the root node of the jTree.
|
void |
setCellValueConverter(TreeCellValueConverter converter)
Sets a new converter for retrieving the text displayed on the tree cells.
|
static void |
setDefaultSeparator(String separator)
Sets the separator to be used for specifying node paths in new jTree instances.
|
void |
setSeparator(String separator)
Sets the separator to be used for specifying node paths in this jTree instance.
|
String |
toString() |
Trigger |
triggerClick(String path) |
Trigger |
triggerDoubleClick(String path) |
Trigger |
triggerRightClick(String path) |
Trigger |
triggerRightClickInSelection() |
tooltipContains, tooltipEquals
addAttributes, backgroundEquals, backgroundNear, foregroundEquals, foregroundNear, getContainer, getContainer, getDescription, getDescription, getLabel, getName, getSubDescription, isEnabled, isVisible, pressKey, releaseKey, typeKey
public static final String TYPE_NAME
public static final Class[] SWING_CLASSES
public Tree(JTree jTree)
public String getDescriptionTypeName()
UIComponent
UIComponent.getDescription()
.public JTree getAwtComponent()
UIComponent
getAwtComponent
in interface UIComponent
getAwtComponent
in class AbstractSwingUIComponent
public JTree getJTree()
public void setSeparator(String separator)
public String getSeparator()
public static void setDefaultSeparator(String separator)
public void setCellValueConverter(TreeCellValueConverter converter)
public Assertion contentEquals(String expectedContents)
The expected contents is a newline (\n) separated string where nodes are indented with two-space steps. For instance:
assertTrue(jTree.contentEquals("root\n" +
" child1\n" +
" child1_1\n" +
" child2"));
Text display properties such as boldness and color can be checked using a "#(...)"
specifier.
For instance:
assertTrue(jTree.contentEquals("root\n" +
" child1 #(bold)\n" +
" child1_1 #(bold,color=red)\n" +
" child2"));
The properties are defined as follows:
public Assertion contains(String path)
public void selectRoot()
public void addToSelection(String path)
public void removeFromSelection(String path)
public void addToSelection(String parentPath, int childIndex)
This method is preferred over addToSelection(String)
when there are several nodes
with the same name under a given parent.
public void clearSelection()
public void select(String path)
public void select(String parentPath, int childIndex)
This method is preferred over select(String)
when there are several nodes
with the same name under a given parent.
public void select(String parentPath, String childSubstring)
public void select(String[] paths)
public void click(String path)
public void rightClick(String path)
public void doubleClick(String path)
public void rightClickInSelection()
public Trigger triggerRightClickInSelection()
public int getChildCount(String path)
public Assertion selectionEquals(String path)
public Assertion selectionIsEmpty()
public Assertion foregroundEquals(String path, String color)
public Assertion pathIsExpanded(String path)
path
- a String identifying the path to be expanded or collapsedpublic void expand(String path, boolean expand)
path
- a String identifying the path to be expanded or collapsedexpand
- if true, expand the node, and collapse it otherwisepublic void expandAll()
Copyright © 2004–2016. All rights reserved.