com.jidesoft.swing
Class CheckBoxTreeSelectionModel

java.lang.Object
  extended by javax.swing.tree.DefaultTreeSelectionModel
      extended by com.jidesoft.swing.CheckBoxTreeSelectionModel
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.event.TreeModelListener, javax.swing.tree.TreeSelectionModel

public class CheckBoxTreeSelectionModel
extends javax.swing.tree.DefaultTreeSelectionModel
implements javax.swing.event.TreeModelListener

CheckBoxTreeSelectionModel is a selection _model based on DefaultTreeSelectionModel and use in CheckBoxTree to keep track of the checked tree paths.

Author:
Santhosh Kumar T
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.tree.DefaultTreeSelectionModel
changeSupport, leadIndex, leadPath, leadRow, listenerList, listSelectionModel, rowMapper, selection, SELECTION_MODE_PROPERTY, selectionMode
 
Fields inherited from interface javax.swing.tree.TreeSelectionModel
CONTIGUOUS_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION, SINGLE_TREE_SELECTION
 
Constructor Summary
CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model)
           
CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model, boolean digIn)
           
 
Method Summary
 void addSelectionPaths(javax.swing.tree.TreePath[] paths)
          Overrides the method in DefaultTreeSelectionModel to consider digIn mode.
 javax.swing.tree.TreeModel getModel()
           
 boolean isDigIn()
          Gets the dig-in mode.
 boolean isPartiallySelected(javax.swing.tree.TreePath path)
          Tests whether there is any unselected node in the subtree of given path.
 boolean isPathSelected(javax.swing.tree.TreePath path, boolean digIn)
          Tells whether given path is selected.
 boolean isRowSelected(int row)
           
 boolean isSingleEventMode()
           
protected  void notifyPathChange(javax.swing.tree.TreePath[] changedPaths, boolean isNew, javax.swing.tree.TreePath oldLeadSelection)
          Notifies listeners of a change in path.
protected  void notifyPathChange(java.util.Vector changedPaths, javax.swing.tree.TreePath oldLeadSelection)
           
 void removeSelectionPaths(javax.swing.tree.TreePath[] paths)
           
 void removeSelectionPaths(javax.swing.tree.TreePath[] paths, boolean doFireEvent)
           
 void setBatchMode(boolean batchMode)
           
 void setDigIn(boolean digIn)
          Sets the dig-in mode.
 void setModel(javax.swing.tree.TreeModel model)
           
 void setSelectionPaths(javax.swing.tree.TreePath[] pPaths)
          Overrides the method in DefaultTreeSelectionModel to consider digIn mode.
 void setSingleEventMode(boolean singleEventMode)
          Single event mode is a mode that always fires only one event when you select or deselect a tree node.
 void treeNodesChanged(javax.swing.event.TreeModelEvent e)
           
 void treeNodesInserted(javax.swing.event.TreeModelEvent e)
           
 void treeNodesRemoved(javax.swing.event.TreeModelEvent e)
           
 void treeStructureChanged(javax.swing.event.TreeModelEvent e)
           
 
Methods inherited from class javax.swing.tree.DefaultTreeSelectionModel
addPropertyChangeListener, addSelectionPath, addTreeSelectionListener, arePathsContiguous, canPathsBeAdded, canPathsBeRemoved, clearSelection, clone, fireValueChanged, getLeadSelectionPath, getLeadSelectionRow, getListeners, getMaxSelectionRow, getMinSelectionRow, getPropertyChangeListeners, getRowMapper, getSelectionCount, getSelectionMode, getSelectionPath, getSelectionPaths, getSelectionRows, getTreeSelectionListeners, insureRowContinuity, insureUniqueness, isPathSelected, isSelectionEmpty, removePropertyChangeListener, removeSelectionPath, removeTreeSelectionListener, resetRowSelection, setRowMapper, setSelectionMode, setSelectionPath, toString, updateLeadIndex
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CheckBoxTreeSelectionModel

public CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model)

CheckBoxTreeSelectionModel

public CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model,
                                  boolean digIn)
Method Detail

getModel

public javax.swing.tree.TreeModel getModel()

setModel

public void setModel(javax.swing.tree.TreeModel model)

isDigIn

public boolean isDigIn()
Gets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node will check all the children. Correspondingly, getSelectionPaths() will only return the parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently

Returns:
true or false.

setDigIn

public void setDigIn(boolean digIn)
Sets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node will check all the children. Correspondingly, getSelectionPaths() will only return the parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently

Parameters:
digIn - true to enable dig-in mode. False to disable it.

isPartiallySelected

public boolean isPartiallySelected(javax.swing.tree.TreePath path)
Tests whether there is any unselected node in the subtree of given path.

Parameters:
path - check if the path is partially selected.
Returns:
true if partially. Otherwise false.

isRowSelected

public boolean isRowSelected(int row)
Specified by:
isRowSelected in interface javax.swing.tree.TreeSelectionModel
Overrides:
isRowSelected in class javax.swing.tree.DefaultTreeSelectionModel

isPathSelected

public boolean isPathSelected(javax.swing.tree.TreePath path,
                              boolean digIn)
Tells whether given path is selected. if dig is true, then a path is assumed to be selected, if one of its ancestor is selected.

Parameters:
path - check if the path is selected.
digIn - whether we will check its descendants.
Returns:
true if the path is selected.

notifyPathChange

protected void notifyPathChange(java.util.Vector changedPaths,
                                javax.swing.tree.TreePath oldLeadSelection)
Overrides:
notifyPathChange in class javax.swing.tree.DefaultTreeSelectionModel

setSelectionPaths

public void setSelectionPaths(javax.swing.tree.TreePath[] pPaths)
Overrides the method in DefaultTreeSelectionModel to consider digIn mode.

Specified by:
setSelectionPaths in interface javax.swing.tree.TreeSelectionModel
Overrides:
setSelectionPaths in class javax.swing.tree.DefaultTreeSelectionModel
Parameters:
pPaths - the tree paths to be selected.

addSelectionPaths

public void addSelectionPaths(javax.swing.tree.TreePath[] paths)
Overrides the method in DefaultTreeSelectionModel to consider digIn mode.

Specified by:
addSelectionPaths in interface javax.swing.tree.TreeSelectionModel
Overrides:
addSelectionPaths in class javax.swing.tree.DefaultTreeSelectionModel
Parameters:
paths - the tree paths to be added to selection paths.

removeSelectionPaths

public void removeSelectionPaths(javax.swing.tree.TreePath[] paths)
Specified by:
removeSelectionPaths in interface javax.swing.tree.TreeSelectionModel
Overrides:
removeSelectionPaths in class javax.swing.tree.DefaultTreeSelectionModel

removeSelectionPaths

public void removeSelectionPaths(javax.swing.tree.TreePath[] paths,
                                 boolean doFireEvent)

isSingleEventMode

public boolean isSingleEventMode()

setSingleEventMode

public void setSingleEventMode(boolean singleEventMode)
Single event mode is a mode that always fires only one event when you select or deselect a tree node.

Taking this tree as an example,

 A -- a
   |- b
   |- c
 
Case 1: Assuming b and c are selected at this point, you click on a.

Case 2: Assuming none of the nodes are selected, you click on A. In this case, both modes result in the same behavior.

Case 3: Assuming b and c are selected and now you click on A. As you can see, single event mode will always fire the event on the nodes you select. However it doesn't reflect what really happened inside the selection model. So if you want to get a complete picture of the selection state inside selection model, you should use DefaultTreeSelectionModel.getSelectionPaths() to find out. In non-single event mode, the events reflect what happened inside the selection model. So you can get a complete picture of the exact state without asking the selection model. The downside is it will generate too many events. With this option, you can decide which mode you want to use that is the best for your case.

By default, singleEventMode is set to false to be compatible with the older versions that don't have this option.

Parameters:
singleEventMode - true or false.

notifyPathChange

protected void notifyPathChange(javax.swing.tree.TreePath[] changedPaths,
                                boolean isNew,
                                javax.swing.tree.TreePath oldLeadSelection)
Notifies listeners of a change in path. changePaths should contain instances of PathPlaceHolder.

Parameters:
changedPaths - the paths that are changed.
isNew - is it a new path.
oldLeadSelection - the old selection.

setBatchMode

public void setBatchMode(boolean batchMode)

treeNodesChanged

public void treeNodesChanged(javax.swing.event.TreeModelEvent e)
Specified by:
treeNodesChanged in interface javax.swing.event.TreeModelListener

treeNodesInserted

public void treeNodesInserted(javax.swing.event.TreeModelEvent e)
Specified by:
treeNodesInserted in interface javax.swing.event.TreeModelListener

treeNodesRemoved

public void treeNodesRemoved(javax.swing.event.TreeModelEvent e)
Specified by:
treeNodesRemoved in interface javax.swing.event.TreeModelListener

treeStructureChanged

public void treeStructureChanged(javax.swing.event.TreeModelEvent e)
Specified by:
treeStructureChanged in interface javax.swing.event.TreeModelListener


Copyright © 2008. All Rights Reserved.