Class DOMTreeModel
- All Implemented Interfaces:
TreeModel
,EventListener
This implementation is for generic DOM representations. It does not have any X3D specific handling. That is left to derived classes.
The model is specifically tailored to display DOM objects. The model is configured so that it should always ask if it allows children as some DOM nodes cannot have children. If the Document allows events then this will automatically add listeners and build the correct tree as the underlying DOM changes.
Each of the objects represented by this model will be the DOMTreeNode class. Building of these objects is lazy for memory consumption purposes. We do not build the child DOMTreeNode object until we have to.
The tree will also show attribute information as nodes in the tree. In order to maintain consistency, we will need to make sure that the indexes are always in the same order. To do this, we always put the attributes first and follow with child nodes.
To keep itself consistent, we only register a listener at the root of the document. This is for node add, remove and attribute modified. Because events bubble for these types, there is no need to register an event listener on every single node instance. We just listen at the document root for the events that bubble up to us.
- Version:
- $Revision: 1.3 $
- Author:
- Justin Couch
-
Constructor Summary
ConstructorsConstructorDescriptionDOMTreeModel
(Node root) Create a new tree model that represents the given document root. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a tree listener to this model.Get the child of the given parent at that index.int
getChildCount
(Object parent) Get the number of children the given parent contains.int
getIndexOfChild
(Object parent, Object child) Get the index of the given child in the parent node.getRoot()
Get the object that represents the root of this tree model.void
handleEvent
(Event evt) Handle an incoming event.boolean
Check to see if the given node is a leaf node.void
Remove the tree listener from this model.void
valueForPathChanged
(TreePath path, Object value) Notification that the UI has changed the value to the destination object to the new value.
-
Constructor Details
-
DOMTreeModel
Create a new tree model that represents the given document root.- Parameters:
root
- The DOM node representing the root of the tree
-
-
Method Details
-
getChild
-
getChildCount
Get the number of children the given parent contains. The number is both child elements and attributes as this tree will show both.- Specified by:
getChildCount
in interfaceTreeModel
- Parameters:
parent
- The parent to quiz for the number of children- Returns:
- The number of children of that parent
-
getIndexOfChild
Get the index of the given child in the parent node.- Specified by:
getIndexOfChild
in interfaceTreeModel
- Parameters:
parent
- The parent node to check forchild
- The child to find the index of- Returns:
- The position of the child in the parent
-
getRoot
-
isLeaf
-
valueForPathChanged
Notification that the UI has changed the value to the destination object to the new value. In this case, the value is always a string and only useful if the destination object is an Attribute. Adding and removing of whole subsections of the tree is not supported here.- Specified by:
valueForPathChanged
in interfaceTreeModel
- Parameters:
path
- The path to the object that changedvalue
- The new value for the Node
-
addTreeModelListener
Add a tree listener to this model. Only one instance of the listener can be added at a time. A second call to add the same instance will silently ignore the request.- Specified by:
addTreeModelListener
in interfaceTreeModel
- Parameters:
l
- The listener to be added
-
removeTreeModelListener
Remove the tree listener from this model. If the instance is not known about the request is silently ignored.- Specified by:
removeTreeModelListener
in interfaceTreeModel
- Parameters:
l
- The listener to be removed
-
handleEvent
Handle an incoming event. This will be for node insert/remove or attribute modified. Will cause the appropriate tree model event to be fired.- Specified by:
handleEvent
in interfaceEventListener
- Parameters:
evt
- The event to be processed
-