Class MaskTreeModel

java.lang.Object
uk.ac.starlink.vo.MaskTreeModel
All Implemented Interfaces:
TreeModel

public class MaskTreeModel extends Object implements TreeModel
Wrapper tree model that includes only a selection of the nodes in the base model. The selection is controlled by a supplied Mask object.

It's intended for use with a static base model. It ought to work for a base model which sends TreeModelEvents, but that hasn't been tested, and it doesn't translate the events very cleverly to downstream listeners.

Since:
17 Mar 2015
Author:
Mark Taylor
  • Constructor Details

    • MaskTreeModel

      public MaskTreeModel(TreeModel base, boolean includeDescendants)
      Constructor.
      Parameters:
      base - underlying tree model
      includeDescendants - if true, all descendants of an included node are automatically included
  • Method Details

    • getRoot

      public Object getRoot()
      Specified by:
      getRoot in interface TreeModel
    • isLeaf

      public boolean isLeaf(Object node)
      Specified by:
      isLeaf in interface TreeModel
    • getChildCount

      public int getChildCount(Object parent)
      Specified by:
      getChildCount in interface TreeModel
    • getChild

      public Object getChild(Object parent, int index)
      Specified by:
      getChild in interface TreeModel
    • getIndexOfChild

      public int getIndexOfChild(Object parent, Object child)
      Specified by:
      getIndexOfChild in interface TreeModel
    • valueForPathChanged

      public void valueForPathChanged(TreePath path, Object newValue)
      Specified by:
      valueForPathChanged in interface TreeModel
    • addTreeModelListener

      public void addTreeModelListener(TreeModelListener lnr)
      Specified by:
      addTreeModelListener in interface TreeModel
    • removeTreeModelListener

      public void removeTreeModelListener(TreeModelListener lnr)
      Specified by:
      removeTreeModelListener in interface TreeModel
    • getBaseModel

      public TreeModel getBaseModel()
      Returns the underlying, unmasked, model.
      Returns:
      base tree model
    • setBaseModel

      public void setBaseModel(TreeModel base)
      Sets the underlying, unmasked, model.
      Parameters:
      base - new base model
    • getMask

      public MaskTreeModel.Mask getMask()
      Returns the currently active mask.
      Returns:
      mask, may be null for full inclusion
    • setMask

      public void setMask(MaskTreeModel.Mask mask)
      Sets the mask for defning inclusion of nodes in the base model. A null mask is used for full inclusion (and will be more efficient than one for which isIncluded always returns true).

      If the supplied mask matches the previously installed one by equality, no action is performed. So it's not essential that mask implementations implement equals/hashCode, but it may be beneficial.

      Parameters:
      mask - new mask, or null for full inclusion
    • getNodeCount

      public int getNodeCount()
      Returns the total number of nodes in this model.
      Returns:
      node count