Class GTreeSelectionModel

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, javax.swing.tree.TreeSelectionModel

    public class GTreeSelectionModel
    extends javax.swing.tree.DefaultTreeSelectionModel
    This class was created so that GTree users can know the origin of tree selections. This is useful in determining if the tree selection event occurred because the user clicked in the tree, or if an API method was called (or by an event internal to, or trigged by the GTree).

    As an example usage, imagine an event cycle, where a change in the tree selection causes a change in some other GUI component and changes in the other GUI component cause a change in the tree selection. In this scenario, to avoid bouncing back and forth, the TreeSelectionListener can check if the tree selection change was caused by the user or by an API call responding to the change in the other GUI component, thereby breaking the cycle.

    With this selection model the user can check the origin of the event with a call to:

                    public void valueChanged(GTreeSelectionEvent e) {
                            if ( e.getEventOrigin() == EventOrigin.USER_GENERATED ) {
                                    // respond to user selection
                            }
                    }
     
    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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addGTreeSelectionListener​(GTreeSelectionListener listener)  
      void clearSelection()  
      protected void fireValueChanged​(javax.swing.event.TreeSelectionEvent e)  
      void removeGTreeSelectionListener​(GTreeSelectionListener listener)  
      void removeSelectionPaths​(javax.swing.tree.TreePath[] paths)  
      void setSelectionPaths​(javax.swing.tree.TreePath[] paths, GTreeSelectionEvent.EventOrigin origin)  
      void userRemovedSelectionPath​(javax.swing.tree.TreePath path)
      This method allows the GTree's JTree to tell this selection model when a selection has been removed due to the user clicking.
      • Methods inherited from class javax.swing.tree.DefaultTreeSelectionModel

        addPropertyChangeListener, addSelectionPath, addSelectionPaths, addTreeSelectionListener, arePathsContiguous, canPathsBeAdded, canPathsBeRemoved, clone, getLeadSelectionPath, getLeadSelectionRow, getListeners, getMaxSelectionRow, getMinSelectionRow, getPropertyChangeListeners, getRowMapper, getSelectionCount, getSelectionMode, getSelectionPath, getSelectionPaths, getSelectionRows, getTreeSelectionListeners, insureRowContinuity, insureUniqueness, isPathSelected, isRowSelected, isSelectionEmpty, notifyPathChange, removePropertyChangeListener, removeSelectionPath, removeTreeSelectionListener, resetRowSelection, setRowMapper, setSelectionMode, setSelectionPath, setSelectionPaths, toString, updateLeadIndex
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • GTreeSelectionModel

        public GTreeSelectionModel()
    • Method Detail

      • removeGTreeSelectionListener

        public void removeGTreeSelectionListener​(GTreeSelectionListener listener)
      • fireValueChanged

        protected void fireValueChanged​(javax.swing.event.TreeSelectionEvent e)
        Overrides:
        fireValueChanged in class javax.swing.tree.DefaultTreeSelectionModel
      • clearSelection

        public void clearSelection()
        Specified by:
        clearSelection in interface javax.swing.tree.TreeSelectionModel
        Overrides:
        clearSelection in class javax.swing.tree.DefaultTreeSelectionModel
      • removeSelectionPaths

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

        public final void userRemovedSelectionPath​(javax.swing.tree.TreePath path)
        This method allows the GTree's JTree to tell this selection model when a selection has been removed due to the user clicking.

        Implementation Note: this method is needed because removeSelectionPaths(TreePath[]) marks all events as GTreeSelectionEvent.EventOrigin.INTERNAL_GENERATED. Our intention is to mark any tree housekeeping as internal, with user operations being marked appropriately.

        Parameters:
        path - the path that is to be removed