Packageorg.aswing.tree
Interfacepublic interface TreeSelectionModel
ImplementorsDefaultTreeSelectionModel

This interface represents the current state of the selection for the tree component. For information and examples of using tree selection models, see How to Use Trees in The Java Tutorial.

The state of the tree selection is characterized by a set of TreePaths, and optionally a set of integers. The mapping from TreePath to integer is done by way of an instance of RowMapper. It is not necessary for a TreeSelectionModel to have a RowMapper to correctly operate, but without a RowMapper getSelectionRows will return null.

A TreeSelectionModel can be configured to allow only one path (SINGLE_TREE_SELECTION) a number of continguous paths (CONTIGUOUS_TREE_SELECTION) or a number of discontiguous paths (DISCONTIGUOUS_TREE_SELECTION). A RowMapper is used to determine if TreePaths are contiguous. In the absence of a RowMapper CONTIGUOUS_TREE_SELECTION and DISCONTIGUOUS_TREE_SELECTION behave the same, that is they allow any number of paths to be contained in the TreeSelectionModel.

For a selection model of CONTIGUOUS_TREE_SELECTION any time the paths are changed (setSelectionPath, addSelectionPath ...) the TreePaths are again checked to make they are contiguous. A check of the TreePaths can also be forced by invoking resetRowSelection. How a set of discontiguous TreePaths is mapped to a contiguous set is left to implementors of this interface to enforce a particular policy.

Implementations should combine duplicate TreePaths that are added to the selection. For example, the following code

    var paths:Array = [ treePath, treePath ];
    treeSelectionModel.setSelectionPaths(paths);
  
should result in only one path being selected: treePath, and not two copies of treePath.

The lead TreePath is the last path that was added (or set). The lead row is then the row that corresponds to the TreePath as determined from the RowMapper.

(Fully quoted from java swing's tree doc)



Public Methods
 MethodDefined by
  
addPropertyChangeListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Adds a PropertyChangeListener to the listener list.
TreeSelectionModel
  
addSelectionPath(path:TreePath, programmatic:Boolean = true):void
Adds path to the current selection.
TreeSelectionModel
  
addSelectionPaths(paths:Array, programmatic:Boolean = true):void
Adds paths(TreePath[]) to the current selection.
TreeSelectionModel
  
addTreeSelectionListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.
TreeSelectionModel
  
clearSelection(programmatic:Boolean = true):void
Empties the current selection.
TreeSelectionModel
  
Returns the last path that was added.
TreeSelectionModel
  
Returns the lead selection index.
TreeSelectionModel
  
Returns the largest value obtained from the RowMapper for the current set of selected TreePaths.
TreeSelectionModel
  
Returns the smallest value obtained from the RowMapper for the current set of selected TreePaths.
TreeSelectionModel
  
Returns the RowMapper instance that is able to map a TreePath to a row.
TreeSelectionModel
  
Returns the number of paths that are selected.
TreeSelectionModel
  
Returns the current selection mode, one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
TreeSelectionModel
  
Returns the first path in the selection.
TreeSelectionModel
  
Returns the paths(TreePath[]) in the selection.
TreeSelectionModel
  
Returns all of the currently selected rows.
TreeSelectionModel
  
isPathSelected(path:TreePath):Boolean
Returns true if the path, path, is in the current selection.
TreeSelectionModel
  
isRowSelected(row:int):Boolean
Returns true if the row identified by row is selected.
TreeSelectionModel
  
isSelectionEmpty():Boolean
Returns true if the selection is currently empty.
TreeSelectionModel
  
removePropertyChangeListener(listener:Function):void
Removed a propertyChangeListener.
TreeSelectionModel
  
removeSelectionPath(path:TreePath, programmatic:Boolean = true):void
Removes path from the selection.
TreeSelectionModel
  
removeSelectionPaths(paths:Array, programmatic:Boolean = true):void
Removes paths(TreePath[]) from the selection.
TreeSelectionModel
  
removeTreeSelectionListener(listener:Function):void
Removed a treeSelectionListener.
TreeSelectionModel
  
Updates this object's mapping from TreePaths to rows.
TreeSelectionModel
  
setRowMapper(newMapper:RowMapper):void
Sets the RowMapper instance.
TreeSelectionModel
  
setSelectionMode(mode:int):void
Sets the selection model, which must be one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
TreeSelectionModel
  
setSelectionPath(path:TreePath, programmatic:Boolean = true):void
Sets the selection to path.
TreeSelectionModel
  
setSelectionPaths(paths:Array, programmatic:Boolean = true):void
Sets the selection to path(TreePath[]) .
TreeSelectionModel
Method detail
addPropertyChangeListener()method
public function addPropertyChangeListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void

Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired when the selection mode changes. Parameters

listener:Function — the propertyChangeListener to be added
 
priority:int (default = 0) — the priority
 
useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak.

See also

addSelectionPath()method 
public function addSelectionPath(path:TreePath, programmatic:Boolean = true):void

Adds path to the current selection. If path is not currently in the selection the TreeSelectionListeners are notified. This has no effect if path is null.

Parameters
path:TreePath — the new path to add to the current selection.
 
programmatic:Boolean (default = true) — indicate if this is a programmatic change.
addSelectionPaths()method 
public function addSelectionPaths(paths:Array, programmatic:Boolean = true):void

Adds paths(TreePath[]) to the current selection. If any of the paths in paths are not currently in the selection the TreeSelectionListeners are notified. This has no effect if paths is null.

Parameters
paths:Array — the new paths to add to the current selection.
 
programmatic:Boolean (default = true) — indicate if this is a programmatic change.
addTreeSelectionListener()method 
public function addTreeSelectionListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void

Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.

Parameters
listener:Function — the new listener to be added
 
priority:int (default = 0) — the priority
 
useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak.

See also

clearSelection()method 
public function clearSelection(programmatic:Boolean = true):void

Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.

Parameters
programmatic:Boolean (default = true) — indicate if this is a programmatic change.
getLeadSelectionPath()method 
public function getLeadSelectionPath():TreePath

Returns the last path that was added. This may differ from the leadSelectionPath property maintained by the JTree.

Returns
TreePath
getLeadSelectionRow()method 
public function getLeadSelectionRow():int

Returns the lead selection index. That is the last index that was added.

Returns
int
getMaxSelectionRow()method 
public function getMaxSelectionRow():int

Returns the largest value obtained from the RowMapper for the current set of selected TreePaths. If nothing is selected, or there is no RowMapper, this will return -1.

Returns
int
getMinSelectionRow()method 
public function getMinSelectionRow():int

Returns the smallest value obtained from the RowMapper for the current set of selected TreePaths. If nothing is selected, or there is no RowMapper, this will return -1.

Returns
int
getRowMapper()method 
public function getRowMapper():RowMapper

Returns the RowMapper instance that is able to map a TreePath to a row.

Returns
RowMapper
getSelectionCount()method 
public function getSelectionCount():int

Returns the number of paths that are selected.

Returns
int
getSelectionMode()method 
public function getSelectionMode():int

Returns the current selection mode, one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

Returns
int
getSelectionPath()method 
public function getSelectionPath():TreePath

Returns the first path in the selection. How first is defined is up to implementors, and may not necessarily be the TreePath with the smallest integer value as determined from the RowMapper.

Returns
TreePath
getSelectionPaths()method 
public function getSelectionPaths():Array

Returns the paths(TreePath[]) in the selection. This will return null (or an empty array) if nothing is currently selected.

Returns
Array
getSelectionRows()method 
public function getSelectionRows():Array

Returns all of the currently selected rows. This will return null (or an empty array) if there are no selected TreePaths or a RowMapper has not been set.

Returns
Array
isPathSelected()method 
public function isPathSelected(path:TreePath):Boolean

Returns true if the path, path, is in the current selection.

Parameters
path:TreePath

Returns
Boolean
isRowSelected()method 
public function isRowSelected(row:int):Boolean

Returns true if the row identified by row is selected.

Parameters
row:int

Returns
Boolean
isSelectionEmpty()method 
public function isSelectionEmpty():Boolean

Returns true if the selection is currently empty.

Returns
Boolean
removePropertyChangeListener()method 
public function removePropertyChangeListener(listener:Function):void

Removed a propertyChangeListener.

Parameters
listener:Function — the listener to be removed.
removeSelectionPath()method 
public function removeSelectionPath(path:TreePath, programmatic:Boolean = true):void

Removes path from the selection. If path is in the selection The TreeSelectionListeners are notified. This has no effect if path is null.

Parameters
path:TreePath — the path to remove from the selection.
 
programmatic:Boolean (default = true) — indicate if this is a programmatic change.
removeSelectionPaths()method 
public function removeSelectionPaths(paths:Array, programmatic:Boolean = true):void

Removes paths(TreePath[]) from the selection. If any of the paths in paths are in the selection, the TreeSelectionListeners are notified. This method has no effect if paths is null.

Parameters
paths:Array — the path to remove from the selection.
 
programmatic:Boolean (default = true) — indicate if this is a programmatic change.
removeTreeSelectionListener()method 
public function removeTreeSelectionListener(listener:Function):void

Removed a treeSelectionListener.

Parameters
listener:Function — the listener to be removed.
resetRowSelection()method 
public function resetRowSelection():void

Updates this object's mapping from TreePaths to rows. This should be invoked when the mapping from TreePaths to integers has changed (for example, a node has been expanded).

You do not normally have to call this; JTree and its associated listeners will invoke this for you. If you are implementing your own view class, then you will have to invoke this.

setRowMapper()method 
public function setRowMapper(newMapper:RowMapper):void

Sets the RowMapper instance. This instance is used to determine the row for a particular TreePath.

Parameters
newMapper:RowMapper
setSelectionMode()method 
public function setSelectionMode(mode:int):void

Sets the selection model, which must be one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

This may change the selection if the current selection is not valid for the new mode. For example, if three TreePaths are selected when the mode is changed to SINGLE_TREE_SELECTION, only one TreePath will remain selected. It is up to the particular implementation to decide what TreePath remains selected. Parameters

mode:int
setSelectionPath()method 
public function setSelectionPath(path:TreePath, programmatic:Boolean = true):void

Sets the selection to path. If this represents a change, then the TreeSelectionListeners are notified. If path is null, this has the same effect as invoking clearSelection.

Parameters
path:TreePath — new path to select.
 
programmatic:Boolean (default = true) — indicate if this is a programmatic change.
setSelectionPaths()method 
public function setSelectionPaths(paths:Array, programmatic:Boolean = true):void

Sets the selection to path(TreePath[]) . If this represents a change, then the TreeSelectionListeners are notified. If paths is null, this has the same effect as invoking clearSelection.

Parameters
paths:Array — new selection.
 
programmatic:Boolean (default = true) — indicate if this is a programmatic change.