Class TreeView
- java.lang.Object
-
- org.apache.pivot.wtk.Component
-
- org.apache.pivot.wtk.TreeView
-
- All Implemented Interfaces:
ConstrainedVisual,Visual
@DefaultProperty("treeData") public class TreeView extends Component
Class that displays a hierarchical data structure, allowing a user to select one or more paths.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTreeView.NodeCheckStateEnumeration defining node check states.static interfaceTreeView.NodeEditorTree view node editor interface.static interfaceTreeView.NodeRendererRendererinterface to customize the appearance of items in a TreeView.static classTreeView.PathComparatorA comparator that sorts paths by the order in which they would visually appear in a fully expanded tree, otherwise known as their "row order".static classTreeView.SelectModeEnumeration defining supported selection modes.static interfaceTreeView.SkinTree view skin interface.-
Nested classes/interfaces inherited from class org.apache.pivot.wtk.Component
Component.DecoratorSequence, Component.StyleDictionary, Component.UserDataDictionary
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddSelectedPath(Sequence.Tree.Path path)Adds a path to the selection.voidclear()Clears any bound values in the component.voidclearSelection()Clears the selection.voidcollapseAll()Collapses all branches in the tree view.voidcollapseBranch(Sequence.Tree.Path path)Collapses the branch at the specified path.voidexpandAll()Expands all branches in the tree view.voidexpandBranch(Sequence.Tree.Path path)Expands the branch at the specified path.voidexpandToBranch(Sequence.Tree.Path path)Expand "to" the given branch, which means opening up all the parents so that this branch is exposed.Sequence<Sequence.Tree.Path>getCheckedPaths()Gets the sequence of node paths that are checked.booleangetCheckmarksEnabled()Filter<?>getDisabledCheckmarkFilter()Returns the disabled checkmark filter, which determines which checkboxes are interactive and which are not.Filter<?>getDisabledNodeFilter()Returns the disabled node filter, which determines the disabled state of all nodes.Sequence.Tree.PathgetFirstSelectedPath()Returns the first selected path, as it would appear in a fully expanded tree.Sequence.Tree.PathgetLastSelectedPath()Returns the last selected path, as it would appear in a fully expanded tree.Sequence.Tree.PathgetNodeAt(int y)Gets the path to the node found at the specified y-coordinate (relative to the tree view).BoundsgetNodeBounds(Sequence.Tree.Path path)Gets the bounds of the node at the specified path relative to the tree view.TreeView.NodeCheckStategetNodeCheckState(Sequence.Tree.Path path)Returns the checkmark state of the node at the specified path.TreeView.NodeEditorgetNodeEditor()Returns the editor used to edit nodes in this tree.intgetNodeIndent(int depth)Gets the pixel indent of nodes at the specified depth.TreeView.NodeRenderergetNodeRenderer()Gets the tree view's node renderer, which is responsible for the appearance of the node data.intgetRowIndex(Sequence.Tree.Path path)Gets the row index of the node, as seen in the current visible nodes list.java.lang.ObjectgetSelectedNode()Sequence.Tree.PathgetSelectedPath()Returns the currently selected index, even when in multi-select mode.ImmutableList<Sequence.Tree.Path>getSelectedPaths()Returns the currently selected paths.TreeView.SelectModegetSelectMode()Returns the current selection mode.booleangetShowMixedCheckmarkState()Tells whether or not the mixed check state will be reported by this tree view.List<?>getTreeData()Returns the tree view's data model.java.lang.StringgetTreeDataKey()ListenerList<TreeViewBranchListener>getTreeViewBranchListeners()Gets theTreeViewBranchListeners.ListenerList<TreeViewListener>getTreeViewListeners()Gets theTreeViewListeners.ListenerList<TreeViewNodeListener>getTreeViewNodeListeners()Gets theTreeViewNodeListeners.ListenerList<TreeViewNodeStateListener>getTreeViewNodeStateListeners()Gets theTreeViewNodeStateListeners.ListenerList<TreeViewSelectionListener>getTreeViewSelectionListeners()Gets theTreeViewSelectionListeners.booleanisBranchExpanded(Sequence.Tree.Path path)Tells whether or not the specified branch is expanded.booleanisNodeChecked(Sequence.Tree.Path path)Tells whether or not the node at the specified path is checked.booleanisNodeDisabled(Sequence.Tree.Path path)Returns the disabled state of a given node.booleanisNodeSelected(Sequence.Tree.Path path)booleanremoveSelectedPath(Sequence.Tree.Path path)Removes a path from the selection.voidsetBranchExpanded(Sequence.Tree.Path path, boolean expanded)Sets the expansion state of the specified branch.voidsetCheckmarksEnabled(boolean checkmarksEnabled)Enables or disables checkmarks.voidsetDisabledCheckmarkFilter(Filter<?> disabledCheckmarkFilter)Sets the disabled checkmark filter, which determines which checkboxes are interactive and which are not.voidsetDisabledNodeFilter(Filter<?> disabledNodeFilter)Sets the disabled node filter, which determines the disabled state of all nodes.voidsetNodeChecked(Sequence.Tree.Path path, boolean checked)Sets the check state of the node at the specified path.voidsetNodeEditor(TreeView.NodeEditor nodeEditor)Sets the editor used to edit nodes in this tree.voidsetNodeRenderer(TreeView.NodeRenderer nodeRenderer)Sets the tree view's node renderer, which is responsible for the appearance of the node data.voidsetSelectedPath(Sequence.Tree.Path path)Set the single selected path.Sequence<Sequence.Tree.Path>setSelectedPaths(Sequence<Sequence.Tree.Path> selectedPaths)Set the new selected nodes in the tree.voidsetSelectMode(TreeView.SelectMode selectMode)Sets the selection mode.voidsetShowMixedCheckmarkState(boolean showMixedCheckmarkState)Sets whether or not the "mixed" check state will be reported by this tree view.protected voidsetSkin(Skin skin)Sets the skin, replacing any previous skin.voidsetTreeData(List<?> treeData)Sets the tree data.voidsetTreeDataKey(java.lang.String treeDataKey)-
Methods inherited from class org.apache.pivot.wtk.Component
checkSkin, clearFocus, contains, copyStyle, copyStyle, getAncestor, getAncestor, getAttribute, getAutomationID, getBaseline, getBaseline, getBounds, getComponentClassListeners, getComponentDataListeners, getComponentDecoratorListeners, getComponentKeyListeners, getComponentListeners, getComponentMouseButtonListeners, getComponentMouseListeners, getComponentMouseWheelListeners, getComponentStateListeners, getComponentStyleListeners, getComponentTooltipListeners, getCursor, getDecoratedBounds, getDecorators, getDisplay, getDragSource, getDropTarget, getFocusedComponent, getGraphics, getHeight, getHeightLimits, getLocation, getMaximumHeight, getMaximumWidth, getMenuHandler, getMinimumHeight, getMinimumWidth, getMouseLocation, getName, getNamedStyles, getParent, getPreferredHeight, getPreferredHeight, getPreferredSize, getPreferredWidth, getPreferredWidth, getScreenBounds, getSize, getSkin, getStyle, getStyle, getStyleBoolean, getStyleBoolean, getStyleColor, getStyleColor, getStyleFont, getStyleFont, getStyleInt, getStyleInt, getStyles, getTextInputMethodListener, getTooltipDelay, getTooltipText, getTooltipWrapText, getTypedStyles, getUserData, getVisibleArea, getVisibleArea, getVisibleArea, getWidth, getWidthLimits, getWindow, getX, getY, indexBoundsCheck, installSkin, invalidate, isBlocked, isEnabled, isFocusable, isFocused, isMouseOver, isOpaque, isPreferredHeightSet, isPreferredSizeSet, isPreferredWidthSet, isShowing, isValid, isVisible, keyPressed, keyReleased, keyTyped, layout, load, mapPointFromAncestor, mapPointFromAncestor, mapPointToAncestor, mapPointToAncestor, mouseClick, mouseDown, mouseMove, mouseOut, mouseOver, mouseUp, mouseWheel, offsetToScreen, paint, putStyle, putStyle, reenterMouse, repaint, repaint, repaint, repaint, repaint, repaint, requestFocus, scrollAreaToVisible, scrollAreaToVisible, setAttribute, setAutomationID, setAutomationID, setCursor, setDragSource, setDropTarget, setEnabled, setFocused, setHeight, setHeightLimits, setHeightLimits, setLocation, setLocation, setMaximumHeight, setMaximumWidth, setMenuHandler, setMinimumHeight, setMinimumWidth, setName, setParent, setPreferredHeight, setPreferredSize, setPreferredSize, setPreferredWidth, setSize, setSize, setStyleName, setStyleNames, setStyleNames, setStyles, setStyles, setTooltipDelay, setTooltipText, setTooltipWrapText, setVisible, setWidth, setWidthLimits, setWidthLimits, setX, setY, store, toString, transferFocus, validate
-
-
-
-
Constructor Detail
-
TreeView
public TreeView()
Creates a newTreeViewwith empty tree data.
-
TreeView
public TreeView(List<?> treeData)
Creates a newTreeViewwith the specified tree data.- Parameters:
treeData- Default data set to be used with the tree. This list represents the root set of items displayed by the tree and will never itself be painted. Sub-items that also implement theListinterface are considered branches; other items are considered leaves.- See Also:
setTreeData(List)
-
-
Method Detail
-
setSkin
protected void setSkin(Skin skin)
Sets the skin, replacing any previous skin. This ensures that the skin being set implements theTreeView.Skininterface.
-
getTreeData
public List<?> getTreeData()
Returns the tree view's data model. This list represents the root set of items displayed by the tree and will never itself be painted. Sub-items that also implement theListinterface are considered branches; other items are considered leaves.For instance, a tree view that displays a single root branch would be backed by list with one child (also a list).
- Returns:
- The tree view's data model.
-
setTreeData
public void setTreeData(List<?> treeData)
Sets the tree data. Note that it is the responsibility of the caller to ensure that the current tree node renderer is capable of displaying the contents of the tree structure. By default, an instance ofTreeViewNodeRendereris used.When the tree data is changed, the state of all nodes (expansion, selection, and checked) will be cleared since the nodes themselves are being replaced. Note that corresponding events will not be fired, since these actions are implied by the
treeDataChangedevent.- Parameters:
treeData- The data to be presented by the tree.
-
getNodeRenderer
public TreeView.NodeRenderer getNodeRenderer()
Gets the tree view's node renderer, which is responsible for the appearance of the node data. As such, note that there is an implied coordination between the node renderer and the data model. The default node renderer used is an instance ofTreeViewNodeRenderer.- Returns:
- The current node renderer.
- See Also:
TreeViewNodeRenderer
-
setNodeRenderer
public void setNodeRenderer(TreeView.NodeRenderer nodeRenderer)
Sets the tree view's node renderer, which is responsible for the appearance of the node data.- Parameters:
nodeRenderer- The new node renderer.
-
getNodeEditor
public TreeView.NodeEditor getNodeEditor()
Returns the editor used to edit nodes in this tree.- Returns:
- The node editor, or
nullif no editor is installed.
-
setNodeEditor
public void setNodeEditor(TreeView.NodeEditor nodeEditor)
Sets the editor used to edit nodes in this tree.- Parameters:
nodeEditor- The node editor for the tree.
-
getSelectMode
public TreeView.SelectMode getSelectMode()
Returns the current selection mode.- Returns:
- The current selection mode.
-
setSelectMode
public void setSelectMode(TreeView.SelectMode selectMode)
Sets the selection mode. Clears the selection if the mode has changed. Note that if the selection is cleared, selection listeners will not be notified, as the clearing of the selection is implied by theselectModeChangedevent.- Parameters:
selectMode- The new selection mode.- See Also:
TreeViewListener,TreeViewSelectionListener
-
getSelectedPaths
public ImmutableList<Sequence.Tree.Path> getSelectedPaths()
Returns the currently selected paths.- Returns:
- An immutable list containing the currently selected paths. Note that the returned list is a wrapper around the actual selection, not a copy. Any changes made to the selection state will be reflected in the list, but events will not be fired.
-
setSelectedPaths
public Sequence<Sequence.Tree.Path> setSelectedPaths(Sequence<Sequence.Tree.Path> selectedPaths)
Set the new selected nodes in the tree.- Parameters:
selectedPaths- The new set of paths to the selected nodes.- Returns:
- The new set of selected paths (with duplicates eliminated).
- Throws:
java.lang.IllegalStateException- If selection has been disabled (select modeNONE).
-
getFirstSelectedPath
public Sequence.Tree.Path getFirstSelectedPath()
Returns the first selected path, as it would appear in a fully expanded tree.- Returns:
- The first selected path, or
nullif nothing is selected.
-
getLastSelectedPath
public Sequence.Tree.Path getLastSelectedPath()
Returns the last selected path, as it would appear in a fully expanded tree.- Returns:
- The last selected path, or
nullif nothing is selected.
-
getSelectedPath
public Sequence.Tree.Path getSelectedPath()
Returns the currently selected index, even when in multi-select mode.- Returns:
- The selected path, or
nullif nothing is selected.
-
setSelectedPath
public void setSelectedPath(Sequence.Tree.Path path)
Set the single selected path.- Parameters:
path- The new path to select.
-
getSelectedNode
public java.lang.Object getSelectedNode()
- Returns:
- The selected object, or
nullif nothing is selected. Note that technically, the selected path could be backed by anulldata value. If the caller wishes to distinguish between these cases, they can usegetSelectedPath()instead.
-
addSelectedPath
public boolean addSelectedPath(Sequence.Tree.Path path)
Adds a path to the selection.- Parameters:
path- The path to the node to be added to the selection.- Returns:
trueif the path was added to the selection;false, otherwise.- Throws:
java.lang.IllegalStateException- If multi-select is not enabled.
-
removeSelectedPath
public boolean removeSelectedPath(Sequence.Tree.Path path)
Removes a path from the selection.- Parameters:
path- Path to the node to be removed from the selection.- Returns:
trueif the path was removed from the selection;false, otherwise.- Throws:
java.lang.IllegalStateException- If multi-select is not enabled.
-
getTreeDataKey
public java.lang.String getTreeDataKey()
-
setTreeDataKey
public void setTreeDataKey(java.lang.String treeDataKey)
-
clear
public void clear()
Description copied from class:ComponentClears any bound values in the component. This functionality must be provided by the subclass; the base implementation is a no-op.
-
clearSelection
public void clearSelection()
Clears the selection.
-
isNodeSelected
public boolean isNodeSelected(Sequence.Tree.Path path)
- Parameters:
path- Path to the node to check.- Returns:
- Whether or not the node at the given path is part of the current selection.
-
isNodeDisabled
public boolean isNodeDisabled(Sequence.Tree.Path path)
Returns the disabled state of a given node.- Parameters:
path- The path to the node whose disabled state is to be tested- Returns:
trueif the node is disabled;false, otherwise
-
getDisabledNodeFilter
public Filter<?> getDisabledNodeFilter()
Returns the disabled node filter, which determines the disabled state of all nodes. Disabled nodes are not interactive to the user. Note, however, that disabled nodes may still be expanded, selected, and checked programatically. A disabled node may have enabled children.If the disabled node filter is set to
null, all nodes are enabled.- Returns:
- The disabled node filter, or
nullif no disabled node filter is set
-
setDisabledNodeFilter
public void setDisabledNodeFilter(Filter<?> disabledNodeFilter)
Sets the disabled node filter, which determines the disabled state of all nodes. Disabled nodes are not interactive to the user. Note, however, that disabled nodes may still be expanded, selected, and checked programatically. A disabled node may have enabled children.If the disabled node filter is set to
null, all nodes are enabled.- Parameters:
disabledNodeFilter- The disabled node filter, ornullfor no disabled node filter
-
getCheckmarksEnabled
public boolean getCheckmarksEnabled()
- Returns:
- Whether or not the checkmarks on each node are enabled.
-
setCheckmarksEnabled
public void setCheckmarksEnabled(boolean checkmarksEnabled)
Enables or disables checkmarks. If checkmarks are being disabled, all checked nodes will be automatically unchecked. Note that the corresponding event will not be fired, since the clearing of existing checkmarks is implied by thecheckmarksEnabledChangedevent.- Parameters:
checkmarksEnabled-trueto enable checkmarks;falseto disable them.
-
getShowMixedCheckmarkState
public boolean getShowMixedCheckmarkState()
Tells whether or not the mixed check state will be reported by this tree view. This state is a derived state meaning "the node is not checked, but one or more of its descendants are." When this state is configured to not be shown, such nodes will simply be reported as unchecked.- Returns:
trueif the tree view will report so-called mixed nodes as mixed;falseif it will report them as unchecked.- See Also:
TreeView.NodeCheckState.MIXED
-
setShowMixedCheckmarkState
public void setShowMixedCheckmarkState(boolean showMixedCheckmarkState)
Sets whether or not the "mixed" check state will be reported by this tree view. This state is a derived state meaning "the node is not checked, but one or more of its descendants are." When this state is configured to not be shown, such nodes will simply be reported as unchecked.Changing this flag may result in some nodes changing their reported check state. Note that the corresponding
nodeCheckStateChangedevents will not be fired, since the possibility of such a change in check state is implied by theshowMixedCheckmarkStateChangedevent.- Parameters:
showMixedCheckmarkState-trueto show the derived mixed state;falseto report so-called "mixed" nodes as unchecked.- See Also:
TreeView.NodeCheckState.MIXED
-
isNodeChecked
public boolean isNodeChecked(Sequence.Tree.Path path)
Tells whether or not the node at the specified path is checked. If checkmarks are not enabled, this is guaranteed to befalse. So called mixed nodes will always be reported as unchecked in this method.- Parameters:
path- The path to the node.- Returns:
trueif the node is explicitly checked;falseotherwise.- See Also:
getCheckmarksEnabled()
-
getNodeCheckState
public TreeView.NodeCheckState getNodeCheckState(Sequence.Tree.Path path)
Returns the checkmark state of the node at the specified path. If checkmarks are not enabled, this is guaranteed to beUNCHECKED.Note that the
MIXEDcheck state (meaning "the node is not checked, but one or more of its descendants are") is only reported when the tree view is configured as such. Otherwise, such nodes will be reported asUNCHECKED.- Parameters:
path- The path to the node.- Returns:
- The checkmark state of the specified node.
- See Also:
getCheckmarksEnabled(),setShowMixedCheckmarkState(boolean)
-
setNodeChecked
public void setNodeChecked(Sequence.Tree.Path path, boolean checked)
Sets the check state of the node at the specified path. If the node already has the specified check state, nothing happens.Note that it is impossible to set the check state of a node to
MIXED. This is because the mixed check state is a derived state meaning "the node is not checked, but one or more of its descendants are."- Parameters:
path- The path to the node.checked-trueto check the node;falseto uncheck it.- Throws:
java.lang.IllegalStateException- If checkmarks are not enabled (seegetCheckmarksEnabled()).- See Also:
TreeView.NodeCheckState.MIXED
-
getCheckedPaths
public Sequence<Sequence.Tree.Path> getCheckedPaths()
Gets the sequence of node paths that are checked. If checkmarks are not enabled (seegetCheckmarksEnabled()), this is guaranteed to return an empty sequence.Note that if the tree view is configured to show mixed checkmark states (see
getShowMixedCheckmarkState()), this will still only return the nodes that are fully checked.- Returns:
- The paths to the checked nodes in the tree, guaranteed to be
non-
null.
-
getDisabledCheckmarkFilter
public Filter<?> getDisabledCheckmarkFilter()
Returns the disabled checkmark filter, which determines which checkboxes are interactive and which are not. Note that this filter only affects user interaction; nodes may still be checked programatically despite their inclusion in this filter. If this filter is set tonull, all checkboxes will be interactive.Note: this filter is only relavent if
checkmarksEnabledis set to true.- Returns:
- The disabled checkmark filter, or
nullif no disabled checkmark filter is set
-
setDisabledCheckmarkFilter
public void setDisabledCheckmarkFilter(Filter<?> disabledCheckmarkFilter)
Sets the disabled checkmark filter, which determines which checkboxes are interactive and which are not. Note that this filter only affects user interaction; nodes may still be checked programatically despite their inclusion in this filter. If this filter is set tonull, all checkboxes will be interactive.Note: this filter is only relavent if
checkmarksEnabledis set to true. enabled.- Parameters:
disabledCheckmarkFilter- The disabled checkmark filter, ornullfor no disabled checkmark filter
-
setBranchExpanded
public void setBranchExpanded(Sequence.Tree.Path path, boolean expanded)
Sets the expansion state of the specified branch. If the branch already has the specified expansion state, nothing happens.The listeners are polled first to give them a chance to veto the operation for any reason. If the vote passes, then the state is changed.
- Parameters:
path- The path to the branch node.expanded-trueto expand the branch;falseto collapse it.
-
isBranchExpanded
public boolean isBranchExpanded(Sequence.Tree.Path path)
Tells whether or not the specified branch is expanded.- Parameters:
path- The path to the branch node.- Returns:
trueif the branch is expanded;falseotherwise.
-
expandBranch
public final void expandBranch(Sequence.Tree.Path path)
Expands the branch at the specified path. If the branch is already expanded, nothing happens.- Parameters:
path- The path to the branch node.
-
expandToBranch
public final void expandToBranch(Sequence.Tree.Path path)
Expand "to" the given branch, which means opening up all the parents so that this branch is exposed.- Parameters:
path- The path to the branch to expose.
-
expandAll
public final void expandAll()
Expands all branches in the tree view.
-
collapseBranch
public final void collapseBranch(Sequence.Tree.Path path)
Collapses the branch at the specified path. If the branch is already collapsed, nothing happens.- Parameters:
path- The path to the branch node.
-
collapseAll
public final void collapseAll()
Collapses all branches in the tree view.
-
getNodeAt
public Sequence.Tree.Path getNodeAt(int y)
Gets the path to the node found at the specified y-coordinate (relative to the tree view).- Parameters:
y- The y-coordinate in pixels.- Returns:
- The path to the node, or
nullif there is no node being painted at the specified y-coordinate.
-
getNodeBounds
public Bounds getNodeBounds(Sequence.Tree.Path path)
Gets the bounds of the node at the specified path relative to the tree view. Note that all nodes are left aligned with the tree; to get the pixel value of a node's indent, usegetNodeIndent(int).- Parameters:
path- The path to the node.- Returns:
- The bounds, or
nullif the node is not currently visible.
-
getNodeIndent
public int getNodeIndent(int depth)
Gets the pixel indent of nodes at the specified depth. Depth is measured in generations away from the tree view's "root" node, which is represented by thetree data.- Parameters:
depth- The depth, where the first child of the root has depth 1, the child of that branch has depth 2, etc.- Returns:
- The indent in pixels.
-
getRowIndex
public int getRowIndex(Sequence.Tree.Path path)
Gets the row index of the node, as seen in the current visible nodes list. Note that as branches are expanded and collapsed, the row index of any given node in the tree will change.- Parameters:
path- The path to the node.- Returns:
- The row index of the node, or
-1if the node is not currently visible.
-
getTreeViewListeners
public ListenerList<TreeViewListener> getTreeViewListeners()
Gets theTreeViewListeners. Developers interested in these events can register for notification on these events by adding themselves to the listener list.- Returns:
- The tree view listeners.
-
getTreeViewBranchListeners
public ListenerList<TreeViewBranchListener> getTreeViewBranchListeners()
Gets theTreeViewBranchListeners. Developers interested in these events can register for notification on these events by adding themselves to the listener list.- Returns:
- The tree view branch listeners.
-
getTreeViewNodeListeners
public ListenerList<TreeViewNodeListener> getTreeViewNodeListeners()
Gets theTreeViewNodeListeners. Developers interested in these events can register for notification on these events by adding themselves to the listener list.- Returns:
- The tree view node listeners.
-
getTreeViewNodeStateListeners
public ListenerList<TreeViewNodeStateListener> getTreeViewNodeStateListeners()
Gets theTreeViewNodeStateListeners. Developers interested in these events can register for notification on these events by adding themselves to the listener list.- Returns:
- The tree view node state listeners.
-
getTreeViewSelectionListeners
public ListenerList<TreeViewSelectionListener> getTreeViewSelectionListeners()
Gets theTreeViewSelectionListeners. Developers interested in these events can register for notification on these events by adding themselves to the listener list.- Returns:
- The tree view selection listeners.
-
-