T - the element type in the TreeView.public class TreeViewSearchable<T> extends Searchable<javafx.scene.control.TreeItem<T>>
TreeViewSearchable is an concrete implementation of Searchable that enables the search function
in TreeView. It's very simple to use it. Assuming you have a TreeView, all you need to do is to call
TreeView tree = ....;
TreeViewSearchable searchable = new TreeViewSearchable(tree);
Now the TreeView will have the search function.
There is very little customization you need to do to TreeSearchable. The only thing you might need is when the element in the TreeView needs a special conversion to convert to string. If so, you can override convertElementToString() to provide you own algorithm to do the conversion.
TreeView tree = ....;
TreeViewSearchable searchable = new TreeViewSearchable(tree) {
protected String convertElementToString(Object object) {
...
}
};
The other customization you might want to is to call setRecursive(boolean) to true. It is false by default. If
setting it true, we will automatically expand the TreeItem to look for the string to be searched. If your TreeView
has a huge number or unlimited number of rows when fully expanded, please do not set it to true as it will for sure
run out of memory.
Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes, case sensitivity.
| Type | Property and Description |
|---|---|
javafx.beans.property.BooleanProperty |
recursive |
caeSensitiveProperty, fromStartProperty, matchingElementProperty, matchingIndexProperty, popupPositionProperty, popupPositionRelativeToProperty, repeatsProperty, searchingDelayProperty, searchingLabelProperty, searchingProperty, searchingTextProperty, typedTextProperty, wildcardEnabledPropertySearchable.SearchPopup_boundsListener, _keyListener, _node, _visibleListener, PROPERTY_SEARCHABLE| Constructor and Description |
|---|
TreeViewSearchable(javafx.scene.control.TreeView<T> treeView) |
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.String |
convertElementToString(javafx.scene.control.TreeItem<T> object)
Converts the element in TreeView to string.
|
protected javafx.scene.control.TreeItem<T> |
getElementAt(int index)
Gets the element at the specified index.
|
protected int |
getElementCount()
Gets the total element count in the control.
|
protected int |
getSelectedIndex()
Gets the selected index in the control.
|
protected java.util.List<javafx.scene.control.TreeItem> |
getTreeItems()
Gets the cached tree paths list.
|
void |
installListeners()
Installs necessary listeners to the control.
|
boolean |
isRecursive()
Checks if the searchable is recursive.
|
protected void |
populateTreePaths()
Recursively go through the tree to populate the tree paths into a list and cache them.
|
javafx.beans.property.BooleanProperty |
recursiveProperty() |
protected void |
resetTreeItems()
Reset the cached tree paths list.
|
void |
setRecursive(boolean recursive)
Sets the recursive attribute.
|
protected void |
setSelectedIndex(int index,
boolean incremental)
Sets the selected index.
|
void |
uninstallListeners()
Uninstall the listeners that installed before.
|
adjustSelectedIndex, caeSensitiveProperty, compare, compareAsString, createSearchPopup, findAll, findFirst, findFromCursor, findLast, findNext, findPrevious, fromStartProperty, getCurrentIndex, getCursor, getElementAtAsString, getHidePopupDelay, getMatchingElement, getMatchingIndex, getNode, getPopupPosition, getPopupPositionRelativeTo, getResourceString, getSearchable, getSearchingDelay, getSearchingText, getSearchLabel, getWildcardSupport, hidePopup, highlightAll, isActivateKey, isCaseSensitive, isDeactivateKey, isFindFirstKey, isFindLastKey, isFindNextKey, isFindPreviousKey, isFromStart, isIncrementalSelectKey, isNavigationKey, isPopupVisible, isRepeats, isReverseOrder, isSearching, isSelectAllKey, isWildcardEnabled, keyTypedOrPressed, matchingElementProperty, matchingIndexProperty, popupPositionProperty, popupPositionRelativeToProperty, repeatsProperty, reverseFindFromCursor, searchingDelayProperty, searchingLabelProperty, searchingProperty, searchingTextProperty, select, setCaseSensitive, setCursor, setCursor, setFromStart, setHidePopupDelay, setMatchingElement, setMatchingIndex, setPopupPosition, setPopupPositionRelativeTo, setRepeats, setReverseOrder, setSearching, setSearchingDelay, setSearchingText, setSearchLabel, setWildcardEnabled, setWildcardSupport, showPopup, typedTextProperty, wildcardEnabledPropertypublic javafx.beans.property.BooleanProperty recursiveProperty
isRecursive(),
setRecursive(boolean)public TreeViewSearchable(javafx.scene.control.TreeView<T> treeView)
public void installListeners()
SearchableinstallListeners in class Searchable<javafx.scene.control.TreeItem<T>>public void uninstallListeners()
SearchableuninstallListeners in class Searchable<javafx.scene.control.TreeItem<T>>public javafx.beans.property.BooleanProperty recursiveProperty()
isRecursive(),
setRecursive(boolean)public boolean isRecursive()
public void setRecursive(boolean recursive)
If TreeSearchable is recursive, it will all tree nodes including those which are not visible to find the matching node. Obviously, if your tree has unlimited number of tree nodes or a potential huge number of tree nodes (such as a tree to represent file system), the recursive attribute should be false. To avoid this potential problem in this case, we default it to false.
recursive - the attributeprotected void setSelectedIndex(int index,
boolean incremental)
SearchablesetSelectedIndex in class Searchable<javafx.scene.control.TreeItem<T>>index - the index to be selectedincremental - a flag to enable multiple selection. If the flag is true, the element at the index should be
added to current selection. If false, you should clear previous selection and then select the
element.protected int getSelectedIndex()
SearchableHere are some examples. In the case of ListView, the index is the row index. In the case of TreeView, the index is the row index too. In the case of TableView, depending on the selection mode, the index could be row index (in row selection mode), or could be the cell index (in cell selection mode).
getSelectedIndex in class Searchable<javafx.scene.control.TreeItem<T>>protected javafx.scene.control.TreeItem<T> getElementAt(int index)
SearchablegetElementAt in class Searchable<javafx.scene.control.TreeItem<T>>index - the indexprotected int getElementCount()
SearchablegetElementCount in class Searchable<javafx.scene.control.TreeItem<T>>protected void populateTreePaths()
Tree paths list is only used when recursive attribute is true.
protected void resetTreeItems()
Tree paths list is only used when recursive attributes true.
protected java.util.List<javafx.scene.control.TreeItem> getTreeItems()
Tree paths list is only used when recursive attributes true.
protected java.lang.String convertElementToString(javafx.scene.control.TreeItem<T> object)
toString() of the last path component in the TreePath.convertElementToString in class Searchable<javafx.scene.control.TreeItem<T>>object - the object to be converted