public interface ItsNatTree extends ItsNatElementComponent
A tree component manages a javax.swing.tree.TreeModel
data model, tree node values are rendered as markup using a special object, the renderer,
and may be optionally edited "in place" using a user defined editor.
Any change to the data model is notified to the component and the markup is rendered again. The data model ever mandates over the markup, any initial markup content (initial root node) is removed.
Almost a root node must be present in the markup, this element is used as a pattern to create new tree nodes, and is removed because by default the data model is empty.
This component family uses a javax.swing.tree.TreeSelectionModel
to keep
track of selection states. When a tree node is selected (usually by clicking it) the selection
state is updated accordingly using the selection model (this one fires any listener registered).
There is no default decoration of tree node selection, selection model listeners may be used to decorate the tree node markup when its selection state changes.
The component internally manages the expand/collapse behavior, when
a mouse event is received (by default one click on handler, double click
if icon or label) usually changes the expand/collapse state, this change
is notified sending a javax.swing.event.TreeExpansionEvent
to the registered listeners, these listeners must be used to manage how the expansion/collapsing
is rendered visually (by default the component does not modify the view,
does not force a default view behavior).
By default this component uses the default renderer and editor and
a javax.swing.tree.DefaultTreeModel
data model.
Row indexes start in 0.
This component family is the "componentized" version of ElementTree
and
follows a similar philosophy.
ItsNat only provides "free trees" because no <tree> tag is present in HTML.
Modifier and Type | Method and Description |
---|---|
void |
addTreeExpansionListener(javax.swing.event.TreeExpansionListener tel)
Registers a new tree expansion listener.
|
void |
addTreeWillExpandListener(javax.swing.event.TreeWillExpandListener tel)
Registers a new "tree will expand" listener.
|
void |
collapseNode(javax.swing.tree.TreePath treePath)
Marks the specified node as collapsed.
|
void |
collapsePath(javax.swing.tree.TreePath path)
Collapses the specified node and node parents.
|
javax.swing.tree.TreeModel |
createDefaultTreeModel()
Creates a data model instance appropriated to this component.
|
void |
expandNode(javax.swing.tree.TreePath treePath)
Marks the specified node as expanded.
|
void |
expandPath(javax.swing.tree.TreePath path)
Expands the specified node and node parents.
|
javax.swing.tree.TreePath |
getEditingPath()
Returns the path of the tree node being edited.
|
int |
getEditingRow()
Returns the row index of the tree node being edited.
|
java.lang.String |
getEditorActivatorEvent()
Returns the event type used to activate the tree node edition process by the user.
|
ItsNatTreeCellEditor |
getItsNatTreeCellEditor()
Returns the current tree node label editor.
|
ItsNatTreeCellRenderer |
getItsNatTreeCellRenderer()
Returns the current component renderer.
|
ItsNatTreeStructure |
getItsNatTreeStructure()
Returns the component structure.
|
ItsNatTreeUI |
getItsNatTreeUI()
Returns the user interface manager of this component.
|
javax.swing.tree.TreePath |
getLastPath()
Returns the last node (tree order)
|
javax.swing.tree.TreePath |
getNextPath(javax.swing.tree.TreePath path)
Returns the path of the next node seeing the data model as a list (tree order).
|
javax.swing.tree.TreePath |
getNextSiblingPath(javax.swing.tree.TreePath path)
Returns the path of the next sibling node.
|
javax.swing.tree.TreePath |
getPreviousPath(javax.swing.tree.TreePath path)
Returns the previous path seeing the data model as a list (tree order).
|
javax.swing.tree.TreePath |
getPreviousSiblingPath(javax.swing.tree.TreePath path)
Returns the path of the previous sibling node.
|
int |
getRowForPath(javax.swing.tree.TreePath path)
Returns the row position of the specified path.
|
javax.swing.tree.RowMapper |
getRowMapper()
Returns the built-in row mapper.
|
int |
getToggleClickCount()
Returns the number of mouse clicks needed to expand or close a node.
|
javax.swing.event.TreeExpansionListener[] |
getTreeExpansionListeners()
Returns all registered "tree expansion" listeners
|
javax.swing.tree.TreeModel |
getTreeModel()
Returns the current data model of this component.
|
int |
getTreeNodeCount()
Returns the number of nodes.
|
javax.swing.tree.TreePath |
getTreePathForRow(int row)
Returns the path of the node at the specified row position.
|
javax.swing.tree.TreeSelectionModel |
getTreeSelectionModel()
Returns the current selection model.
|
javax.swing.event.TreeWillExpandListener[] |
getTreeWillExpandListeners()
Returns all registered tree "tree will expand" listeners
|
boolean |
isEditing()
Informs whether a tree node value is being edited.
|
boolean |
isEditingEnabled()
Informs whether the in place edition is enabled.
|
boolean |
isExpandedNode(javax.swing.tree.TreePath treePath)
Informs whether the specified path is expanded.
|
boolean |
isExpandsSelectedPaths()
Returns the
expandsSelectedPaths property. |
boolean |
isJoystickMode()
Informs whether a joystick is enough to control the component
(some kind of mouse, pointer or stylus not present or not necessary).
|
boolean |
isRootless()
Informs whether this tree has a visible root.
|
boolean |
isSelectionUsesKeyboard()
Returns if the keyboard is used to select items.
|
boolean |
isTreeTable()
Informs whether this tree is a tree-table.
|
void |
removeTreeExpansionListener(javax.swing.event.TreeExpansionListener tel)
Unregisters the specified tree expansion listener.
|
void |
removeTreeWillExpandListener(javax.swing.event.TreeWillExpandListener tel)
Unregisters the specified "tree will expand" listener.
|
void |
setEditingEnabled(boolean value)
Enables or disables temporally the in place edition.
|
void |
setEditorActivatorEvent(java.lang.String eventType)
Sets the event type used to activate the tree node edition process by the user.
|
void |
setExpandsSelectedPaths(boolean newValue)
Sets the
expandsSelectedPaths property. |
void |
setItsNatTreeCellEditor(ItsNatTreeCellEditor editor)
Sets the tree node label editor.
|
void |
setItsNatTreeCellRenderer(ItsNatTreeCellRenderer renderer)
Sets the component renderer.
|
void |
setJoystickMode(boolean value)
Informs whether a joystick is enough to control the component
(some kind of mouse, pointer or stylus not present or not necessary).
|
void |
setSelectionUsesKeyboard(boolean value)
Sets if the keyboard is used to select items.
|
void |
setToggleClickCount(int toggleClickCount)
Sets the number of mouse clicks needed to expand or close a node.
|
void |
setTreeModel(javax.swing.tree.TreeModel dataModel)
Changes the data model of this component.
|
void |
setTreeSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)
Sets the new selection model.
|
void |
startEditingAtPath(javax.swing.tree.TreePath path)
Used to start programmatically a tree node edition process "in place".
|
void |
startEditingAtRow(int row)
Used to start programmatically a tree node edition process "in place".
|
void |
toggleExpansionStateNode(javax.swing.tree.TreePath treePath)
Changes the expansion state of the specified node to the contrary.
|
getElement, getItsNatElementComponentUI
addEventListener, addEventListener, addEventListener, addEventListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, disableEventListener, disableEventListener, dispose, enableEventListener, enableEventListener, getArtifact, getArtifact, getItsNatComponentManager, getItsNatComponentUI, getItsNatDocument, getNode, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, isDisposed, isEnabled, registerArtifact, removeArtifact, removeEventListener, removeEventListener, removeEventListener, removeEventListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, setEnabled, setEventListenerParams, setEventListenerParams, setNode
containsUserValueName, getUserValue, getUserValueNames, removeUserValue, setUserValue
ItsNatTreeUI getItsNatTreeUI()
javax.swing.tree.TreeModel getTreeModel()
setTreeModel(javax.swing.tree.TreeModel)
void setTreeModel(javax.swing.tree.TreeModel dataModel)
Current data model is disconnected from this component, and the new data model is bound to this component, every change is tracked and updates the user interfaces accordingly.
If the specified data model is the same instance as the current data model, then is reset, component listener is removed and added again. Use this technique if you want to add a data model listener to be executed before the default component listener.
dataModel
- the new data model.getTreeModel()
boolean isTreeTable()
The tree-table mode only affects to the layout of tree nodes. If not tree-table (normal) child nodes are contained by the parent tree node markup, in a tree-table layout is as a list, all tree nodes are "top" level nodes as whether they all were roots (only from a layout point of view).
This mode is explicitly defined when the component is created
calling ItsNatComponentManager.createItsNatFreeTree(org.w3c.dom.Element element,boolean,boolean,ItsNatTreeStructure,org.itsnat.core.NameValue[] artifacts)
otherwise is defined by the artifact name "treeTable"
if defined or "treeTable" attribute (ItsNat namespace) if defined
else is false by default.
boolean isRootless()
In a root-less tree the root node has no markup, direct child nodes are top level nodes. This feature may be used to build trees with "multiple roots" visually, this is very useful in vertical tree-based menus where a root node is disturbing.
This mode is explicitly defined when the component is created
calling ItsNatComponentManager.createItsNatFreeTree(org.w3c.dom.Element element,boolean,boolean,ItsNatTreeStructure,org.itsnat.core.NameValue[] artifacts)
otherwise is defined by the artifact name "rootless"
if defined or "rootless" attribute (ItsNat namespace) if defined
else is false by default.
javax.swing.tree.TreeModel createDefaultTreeModel()
int getToggleClickCount()
This number only counts for icon and label parts, the handle ever expands/collapses the node with every click.
Valid numbers: 0,1 and 2. If 0 icon and label do not expand/collapse the node when clicked.
setToggleClickCount(int)
void setToggleClickCount(int toggleClickCount)
toggleClickCount
- number of mouse clicks to expand/collapse a node. Valid numbers: 0,1 and 2.getToggleClickCount()
void addTreeWillExpandListener(javax.swing.event.TreeWillExpandListener tel)
tel
- the listener to register.removeTreeWillExpandListener(javax.swing.event.TreeWillExpandListener)
void removeTreeWillExpandListener(javax.swing.event.TreeWillExpandListener tel)
tel
- the listener to unregister.addTreeWillExpandListener(javax.swing.event.TreeWillExpandListener)
javax.swing.event.TreeWillExpandListener[] getTreeWillExpandListeners()
void addTreeExpansionListener(javax.swing.event.TreeExpansionListener tel)
tel
- the listener to register.removeTreeExpansionListener(javax.swing.event.TreeExpansionListener)
void removeTreeExpansionListener(javax.swing.event.TreeExpansionListener tel)
tel
- the listener to unregister.addTreeExpansionListener(javax.swing.event.TreeExpansionListener)
javax.swing.event.TreeExpansionListener[] getTreeExpansionListeners()
ItsNatTreeStructure getItsNatTreeStructure()
ItsNatTreeCellRenderer getItsNatTreeCellRenderer()
ItsNatComponentManager.createDefaultItsNatTreeCellRenderer()
)setItsNatTreeCellRenderer(ItsNatTreeCellRenderer)
void setItsNatTreeCellRenderer(ItsNatTreeCellRenderer renderer)
renderer
- the new renderer.getItsNatTreeCellRenderer()
ItsNatTreeCellEditor getItsNatTreeCellEditor()
ItsNatComponentManager.createDefaultItsNatTreeCellEditor(ItsNatComponent)
) with a null parameter.setItsNatTreeCellEditor(ItsNatTreeCellEditor)
void setItsNatTreeCellEditor(ItsNatTreeCellEditor editor)
Tree node edition works very much the same as label edition
(see ItsNatLabel.setItsNatLabelEditor(ItsNatLabelEditor)
).
Some differences:
The edition process starts programmatically by calling startEditingAtPath(javax.swing.tree.TreePath)
or startEditingAtRow(int)
.
The edition takes place inside the tree node label element
as returned by ItsNatTreeStructure.getLabelElement(ItsNatTree,int,org.w3c.dom.Element)
.
The new tree node value is set to the data model
calling javax.swing.tree.TreeModel.valueForPathChanged(javax.swing.tree.TreePath,Object)
.
editor
- the new editor. May be null (edition disabled).getItsNatTreeCellEditor()
javax.swing.tree.TreeSelectionModel getTreeSelectionModel()
javax.swing.tree.DefaultTreeSelectionModel
instance.setTreeSelectionModel(javax.swing.tree.TreeSelectionModel)
void setTreeSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)
If the new selection model is the current defined then is "reset", component listener is removed and added again. Use this technique if you want to add a listener to be executed before the default component listener.
The component automatically replaces the current selection model javax.swing.tree.RowMapper
with the internal row mapper (getRowMapper()
) calling
TreeSelectionModel.setRowMapper(RowMapper)
.
selectionModel
- the new selection model.getTreeSelectionModel()
javax.swing.tree.TreePath getPreviousPath(javax.swing.tree.TreePath path)
First tries to return the previous sibling, if no sibling then returns the parent.
getNextPath(javax.swing.tree.TreePath)
,
getPreviousSiblingPath(javax.swing.tree.TreePath)
javax.swing.tree.TreePath getNextPath(javax.swing.tree.TreePath path)
First tries to return the first child, if no child returns the next sibling, if no next sibling returns the next sibling of the parent node, if none then the next sibling of the parent of the parent and so on.
getPreviousPath(javax.swing.tree.TreePath)
,
getNextSiblingPath(javax.swing.tree.TreePath)
javax.swing.tree.TreePath getPreviousSiblingPath(javax.swing.tree.TreePath path)
getNextSiblingPath(javax.swing.tree.TreePath)
javax.swing.tree.TreePath getNextSiblingPath(javax.swing.tree.TreePath path)
getPreviousSiblingPath(javax.swing.tree.TreePath)
javax.swing.tree.TreePath getLastPath()
int getTreeNodeCount()
boolean isExpandsSelectedPaths()
expandsSelectedPaths
property.setExpandsSelectedPaths(boolean)
void setExpandsSelectedPaths(boolean newValue)
expandsSelectedPaths
property. If
true, any time the selection is changed, either via the
TreeSelectionModel
, or the cover methods provided by
this component like expandNode(javax.swing.tree.TreePath)
,
the TreePath
s parents will be
expanded too to make them visible (visible meaning the parent path is
expanded, not necessarily in the visible rectangle of the tree).
If false, when the selection changes the node parents are not expanded.
This is useful if you wish to have your selection model maintain selected paths
that are not always expanded (all parents expanded).newValue
- the new value for expandsSelectedPaths
isExpandsSelectedPaths()
void startEditingAtPath(javax.swing.tree.TreePath path)
path
- the tree node path to edit.startEditingAtRow(int)
,
isEditing()
void startEditingAtRow(int row)
row
- the tree node row to edit.startEditingAtPath(javax.swing.tree.TreePath)
,
isEditing()
boolean isEditing()
startEditingAtPath(javax.swing.tree.TreePath)
,
startEditingAtRow(int)
javax.swing.tree.TreePath getEditingPath()
int getEditingRow()
java.lang.String getEditorActivatorEvent()
If returns null edition activated by events is disabled .
setEditorActivatorEvent(String)
void setEditorActivatorEvent(java.lang.String eventType)
eventType
- the event type used to activate the edition.getEditorActivatorEvent()
boolean isEditingEnabled()
setEditingEnabled(boolean)
void setEditingEnabled(boolean value)
value
- true to enable in place edition.isEditingEnabled()
boolean isExpandedNode(javax.swing.tree.TreePath treePath)
treePath
- the specified path.ItsNatTreeCellUI.isExpanded()
void expandNode(javax.swing.tree.TreePath treePath)
First of all a TreeExpansionEvent
event
is sent to the registered TreeWillExpandListener
listeners,
if expansion request is not vetoed then the node is marked as expanded and previous event is sent again
to the registered TreeExpansionListener
listeners.
treePath
- the node path to expand.collapseNode(javax.swing.tree.TreePath)
,
ItsNatTreeCellUI.expand(boolean)
void collapseNode(javax.swing.tree.TreePath treePath)
Symmetric behavior is applied to collapse request than
expandNode(javax.swing.tree.TreePath)
.
treePath
- the node path to collapse.expandNode(javax.swing.tree.TreePath)
,
ItsNatTreeCellUI.expand(boolean)
void toggleExpansionStateNode(javax.swing.tree.TreePath treePath)
Same behavior as expandNode(javax.swing.tree.TreePath)
and collapseNode(javax.swing.tree.TreePath)
.
treePath
- the node path to change expansion state.void expandPath(javax.swing.tree.TreePath path)
path
- the path to expand.collapsePath(javax.swing.tree.TreePath)
void collapsePath(javax.swing.tree.TreePath path)
path
- the path to expand.expandPath(javax.swing.tree.TreePath)
javax.swing.tree.RowMapper getRowMapper()
This row mapper can not be replaced and is set automatically
to the registered selection model (setTreeSelectionModel(javax.swing.tree.TreeSelectionModel)
).
Current implementation converts a TreePath
to the matched row seeing
the tree as a list (root node is 0), where every node is "visible" (in a server point of view,
the same node in the client may be hidden).
int getRowForPath(javax.swing.tree.TreePath path)
javax.swing.tree.TreePath getTreePathForRow(int row)
Current implementation specifies every node is visible (server point of view) row-path conversion is straightforward seeing the tree as a list.
row
- the specified row position.getRowMapper()
boolean isSelectionUsesKeyboard()
If false ItsNat simulates the CTRL key is ever pressed when an item is selected.
This feature is useful for mobile devices without keyboard and tactile screens to select multiple items (if set to false).
Default value is defined by ItsNatComponentManager.isSelectionOnComponentsUsesKeyboard()
setSelectionUsesKeyboard(boolean)
void setSelectionUsesKeyboard(boolean value)
value
- the new state.isSelectionUsesKeyboard()
boolean isJoystickMode()
If the component is in joystick mode, the handle, icon and label elements of every tree node have an event listener associated. By this way tree nodes are "live" elements and can traversed using a joystick in mobile devices without a mouse, pointer or stylus.
Default value is defined by ItsNatDocument.isJoystickMode()
void setJoystickMode(boolean value)
value
- true to enable joystick mode.isJoystickMode()
Copyright © 2007 Innowhere Software Services S.L. All Rights Reserved.