de.jreality.ui.treeview
Class AbstractTreeModel

java.lang.Object
  extended by de.jreality.ui.treeview.AbstractTreeModel
All Implemented Interfaces:
TreeModel
Direct Known Subclasses:
SceneTreeModel

public abstract class AbstractTreeModel
extends Object
implements TreeModel

Baseclass for TreeModel implementations. Manages listeners and provides fireXXX methods for notifying them.
The valueForPathChanged method is implemented as no-op which comes handy for immutable trees and trees where the editor<->node communication is already enough.


Method Summary
 void addTreeModelListener(TreeModelListener l)
           
abstract  Object getChild(Object parent, int index)
          Must be implemented by subclasses, return the child of parent at index.
abstract  int getChildCount(Object parent)
          Must be implemented by subclasses, return number of children.
 int getIndexOfChild(Object parent, Object child)
          Defaults to a linear search for the child.
abstract  Object getParent(Object o)
          Must be implemented by subclasses, return the parent of a node.
 TreePath getPathTo(Object o)
          Used by event instance creation.
 Object getRoot()
          Returns the root object specified in the constructor.
 boolean isLeaf(Object node)
          Returns getChildCount(node)==0, should be overridden if the semantics of leaf nodes differs.
 void removeTreeModelListener(TreeModelListener l)
           
 void valueForPathChanged(TreePath path, Object newValue)
          Simply does nothing.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Specified by:
addTreeModelListener in interface TreeModel

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Specified by:
removeTreeModelListener in interface TreeModel

getPathTo

public TreePath getPathTo(Object o)
Used by event instance creation. Calls getParent until the root object is reached. Should be overridden if more efficient methods are available.


getChild

public abstract Object getChild(Object parent,
                                int index)
Must be implemented by subclasses, return the child of parent at index.

Specified by:
getChild in interface TreeModel
See Also:
TreeModel.getChild(Object,int)

getChildCount

public abstract int getChildCount(Object parent)
Must be implemented by subclasses, return number of children.

Specified by:
getChildCount in interface TreeModel
See Also:
TreeModel.getChildCount(Object)

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Defaults to a linear search for the child. Can be overridden if there is a more efficient way of determining the index.

Specified by:
getIndexOfChild in interface TreeModel

getRoot

public Object getRoot()
Returns the root object specified in the constructor.

Specified by:
getRoot in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Returns getChildCount(node)==0, should be overridden if the semantics of leaf nodes differs.

Specified by:
isLeaf in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Simply does nothing. Models that doe not support editing or do not required conversion are not required to override this.

Specified by:
valueForPathChanged in interface TreeModel

getParent

public abstract Object getParent(Object o)
Must be implemented by subclasses, return the parent of a node. This is only used by getPathTo(Object) and therefore does not require a valid implementation if the getPathTo() method is overridden with an implementation that does not call it's super impl.