EchoPoint
1.0

echopoint.tree
Class DefaultTreeSelectionModel

java.lang.Object
  extended byechopoint.tree.DefaultTreeSelectionModel
All Implemented Interfaces:
java.io.Serializable, TreeSelectionModel
Direct Known Subclasses:
EmptyTreeSelectionModel

public class DefaultTreeSelectionModel
extends java.lang.Object
implements TreeSelectionModel, java.io.Serializable

Implementation of TreeSelectionModel.

See Also:
Serialized Form

Field Summary
protected  java.beans.PropertyChangeSupport changeSupport
          Used to messaged registered listeners.
protected  int leadIndex
          Index of the lead path in selection.
protected  TreePath leadPath
          Last path that was added.
protected  int leadRow
          Lead row.
protected  nextapp.echo.event.EventListenerList listenerList
          Event listener list.
protected  TreeListSelectionModel listSelectionModel
          Handles maintaining the list selection model.
protected  RowMapper rowMapper
          Provides a row for a given path.
protected  TreePath[] selection
          Paths that are currently selected.
static java.lang.String SELECTION_MODE_PROPERTY
          Property name for selectionMode.
protected  int selectionMode
          Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
 
Fields inherited from interface echopoint.tree.TreeSelectionModel
CONTIGUOUS_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION, SINGLE_TREE_SELECTION
 
Constructor Summary
DefaultTreeSelectionModel()
          Creates a new instance of DefaultTreeSelectionModel that is empty, and having a selection mode of DISCONTIGUOUS_TREE_SELECTION.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void addSelectionPath(TreePath path)
          Adds path to the current selection.
 void addSelectionPaths(TreePath[] paths)
          Adds paths to the current selection.
 void addTreeSelectionListener(TreeSelectionListener x)
          Adds x to the list of listeners that are notified each time the selection changes.
protected  boolean arePathsContiguous(TreePath[] paths)
          Returns true if the paths are contiguous.
protected  boolean canPathsBeAdded(TreePath[] paths)
          Returns true if the paths can be added without breaking the continuity of the model.
protected  boolean canPathsBeRemoved(TreePath[] paths)
          Returns true if the paths can be removed without breaking the continuity of the model.
 void clearSelection()
          Empties the current selection.
protected  void fireValueChanged(TreeSelectionEvent e)
           
 TreePath getLeadSelectionPath()
          Returns the last path that was added.
 int getLeadSelectionRow()
          Returns the lead selection index.
 int getMaxSelectionRow()
          Gets the last selected row.
 int getMinSelectionRow()
          Gets the first selected row.
 RowMapper getRowMapper()
          Returns the RowMapper instance that is able to map a path to a row.
 int getSelectionCount()
          Returns the number of paths that are selected.
 int getSelectionMode()
          Returns the selection mode.
 TreePath getSelectionPath()
          Returns the first path in the selection.
 TreePath[] getSelectionPaths()
          Returns the paths in the selection.
 int[] getSelectionRows()
          Returns all of the currently selected rows.
protected  void insureRowContinuity()
          Useful for CONTIGUOUS_TREE_SELECTION.
protected  void insureUniqueness()
          Insures that all the elements in path are unique.
 boolean isPathSelected(TreePath path)
          Returns true if the path, path, is in the current selection.
 boolean isRowSelected(int row)
          Returns true if the row identitifed by row is selected.
 boolean isSelectionEmpty()
          Returns true if the selection is currently empty.
protected  void notifyPathChange(java.util.Vector changedPaths, TreePath oldLeadSelection)
          Notifies listeners of a change in path. changePaths should contain instances of TreeSpot.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void removeSelectionPath(TreePath path)
          Removes path from the selection.
 void removeSelectionPaths(TreePath[] paths)
          Removes paths from the selection.
 void removeTreeSelectionListener(TreeSelectionListener x)
          Removes x from the list of listeners that are notified each time the selection changes.
 void resetRowSelection()
          Recalculates what rows are selected by asking the RowMapper for the row for each path.
 void setRowMapper(RowMapper newMapper)
          Sets the RowMapper instance.
 void setSelectionMode(int mode)
          Sets the selection model, which must be one of SINGLE_TREE_NONE, SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
 void setSelectionPath(TreePath path)
          Sets the selection to path.
 void setSelectionPaths(TreePath[] pPaths)
          Sets the selection to the paths in paths.
 java.lang.String toString()
          Returns a string that displays and identifies this object's properties.
protected  void updateLeadIndex()
          Updates the leadIndex instance variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SELECTION_MODE_PROPERTY

public static final java.lang.String SELECTION_MODE_PROPERTY
Property name for selectionMode.

See Also:
Constant Field Values

changeSupport

protected java.beans.PropertyChangeSupport changeSupport
Used to messaged registered listeners.


leadIndex

protected int leadIndex
Index of the lead path in selection.


leadPath

protected TreePath leadPath
Last path that was added.


leadRow

protected int leadRow
Lead row.


listenerList

protected nextapp.echo.event.EventListenerList listenerList
Event listener list.


listSelectionModel

protected TreeListSelectionModel listSelectionModel
Handles maintaining the list selection model.


rowMapper

protected transient RowMapper rowMapper
Provides a row for a given path.


selection

protected TreePath[] selection
Paths that are currently selected. Will be null if nothing is currently selected.


selectionMode

protected int selectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

Constructor Detail

DefaultTreeSelectionModel

public DefaultTreeSelectionModel()
Creates a new instance of DefaultTreeSelectionModel that is empty, and having a selection mode of DISCONTIGUOUS_TREE_SELECTION.

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

Specified by:
addPropertyChangeListener in interface TreeSelectionModel
Parameters:
listener - The PropertyChangeListener to be added

addSelectionPath

public void addSelectionPath(TreePath path)
Adds path to the current selection. If path is not currently in the selection the TreeSelectionListeners are notified.

Specified by:
addSelectionPath in interface TreeSelectionModel
Parameters:
path - the new path to add to the current selection.

addSelectionPaths

public void addSelectionPaths(TreePath[] paths)
Adds paths to the current selection. If any of the paths in paths are not currently in the selection the TreeSelectionListeners are notified.

Specified by:
addSelectionPaths in interface TreeSelectionModel
Parameters:
paths - the new paths to add to the current selection.

addTreeSelectionListener

public void addTreeSelectionListener(TreeSelectionListener x)
Adds x to the list of listeners that are notified each time the selection changes.

Specified by:
addTreeSelectionListener in interface TreeSelectionModel
Parameters:
x - the new listener to be added.

arePathsContiguous

protected boolean arePathsContiguous(TreePath[] paths)
Returns true if the paths are contiguous.


canPathsBeAdded

protected boolean canPathsBeAdded(TreePath[] paths)
Returns true if the paths can be added without breaking the continuity of the model.


canPathsBeRemoved

protected boolean canPathsBeRemoved(TreePath[] paths)
Returns true if the paths can be removed without breaking the continuity of the model. This is rather expensive.


clearSelection

public void clearSelection()
Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.

Specified by:
clearSelection in interface TreeSelectionModel

fireValueChanged

protected void fireValueChanged(TreeSelectionEvent e)

getLeadSelectionPath

public TreePath getLeadSelectionPath()
Returns the last path that was added.

Specified by:
getLeadSelectionPath in interface TreeSelectionModel

getLeadSelectionRow

public int getLeadSelectionRow()
Returns the lead selection index. That is the last index that was added.


getMaxSelectionRow

public int getMaxSelectionRow()
Gets the last selected row.


getMinSelectionRow

public int getMinSelectionRow()
Gets the first selected row.


getRowMapper

public RowMapper getRowMapper()
Returns the RowMapper instance that is able to map a path to a row.


getSelectionCount

public int getSelectionCount()
Returns the number of paths that are selected.

Specified by:
getSelectionCount in interface TreeSelectionModel

getSelectionMode

public int getSelectionMode()
Returns the selection mode.

Specified by:
getSelectionMode in interface TreeSelectionModel

getSelectionPath

public TreePath getSelectionPath()
Returns the first path in the selection.

Specified by:
getSelectionPath in interface TreeSelectionModel

getSelectionPaths

public TreePath[] getSelectionPaths()
Returns the paths in the selection.

Specified by:
getSelectionPaths in interface TreeSelectionModel

getSelectionRows

public int[] getSelectionRows()
Returns all of the currently selected rows.


insureRowContinuity

protected void insureRowContinuity()
Useful for CONTIGUOUS_TREE_SELECTION. If the rows that are selected are not contiguous then the selection is reset to be contiguous. Or if the selection mode is single selection and more than one this is selected the selection is reset.


insureUniqueness

protected void insureUniqueness()
Insures that all the elements in path are unique. This does not check for a null selection!


isPathSelected

public boolean isPathSelected(TreePath path)
Returns true if the path, path, is in the current selection.

Specified by:
isPathSelected in interface TreeSelectionModel

isRowSelected

public boolean isRowSelected(int row)
Returns true if the row identitifed by row is selected.


isSelectionEmpty

public boolean isSelectionEmpty()
Returns true if the selection is currently empty.

Specified by:
isSelectionEmpty in interface TreeSelectionModel

notifyPathChange

protected void notifyPathChange(java.util.Vector changedPaths,
                                TreePath oldLeadSelection)
Notifies listeners of a change in path. changePaths should contain instances of TreeSpot.


removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Specified by:
removePropertyChangeListener in interface TreeSelectionModel
Parameters:
listener - The PropertyChangeListener to be removed

removeSelectionPath

public void removeSelectionPath(TreePath path)
Removes path from the selection. If path is in the selection The TreeSelectionListeners are notified.

Specified by:
removeSelectionPath in interface TreeSelectionModel
Parameters:
path - the path to remove from the selection.

removeSelectionPaths

public void removeSelectionPaths(TreePath[] paths)
Removes paths from the selection. If any of the paths in paths are in the selection the TreeSelectionListeners are notified.

Specified by:
removeSelectionPaths in interface TreeSelectionModel
Parameters:
paths - the paths to remove from the selection.

removeTreeSelectionListener

public void removeTreeSelectionListener(TreeSelectionListener x)
Removes x from the list of listeners that are notified each time the selection changes.

Specified by:
removeTreeSelectionListener in interface TreeSelectionModel
Parameters:
x - the listener to remove.

resetRowSelection

public void resetRowSelection()
Recalculates what rows are selected by asking the RowMapper for the row for each path.


setRowMapper

public void setRowMapper(RowMapper newMapper)
Sets the RowMapper instance. This instance is used to determine what row corresponds to what path.


setSelectionMode

public void setSelectionMode(int mode)
Sets the selection model, which must be one of SINGLE_TREE_NONE, SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

Specified by:
setSelectionMode in interface TreeSelectionModel

setSelectionPath

public void setSelectionPath(TreePath path)
Sets the selection to path. If this represents a change, then the TreeSelectionListeners are notified.

Specified by:
setSelectionPath in interface TreeSelectionModel
Parameters:
path - new path to select

setSelectionPaths

public void setSelectionPaths(TreePath[] pPaths)
Sets the selection to the paths in paths. If this represents a change the TreeSelectionListeners are notified. Potentially paths will be held by the reciever, in other words don't change any of the objects in the array once passed in.

Specified by:
setSelectionPaths in interface TreeSelectionModel
Parameters:
pPaths - new selection.

toString

public java.lang.String toString()
Returns a string that displays and identifies this object's properties.

Returns:
a String representation of this object

updateLeadIndex

protected void updateLeadIndex()
Updates the leadIndex instance variable.


EchoPoint
1.0