org.apache.xmlbeans.samples.xmltree
final class: XmlModel [javadoc |
source]
java.lang.Object
org.apache.xmlbeans.samples.xmltree.XmlModel
All Implemented Interfaces:
TreeModel
Defines a data model for the XmlTree. Through the data model, the tree can
retrieve information about the underlying hierarchical data, including the
root of the hierarchy, children of specified nodes, and so on. This data
model interacts with the underlying XML data through
XmlEntry
instances (known as "user objects" in the context of JTree data models). The
XmlEntry class knows how to retrieve XML-specific hierarchical information as
it is represented by the XmlObject XMLBeans type. In other words, from the
tree's perspective, XmlEntry wraps XmlObject.
Constructor: |
public XmlModel(XmlEntry entry) {
m_rootEntry = entry;
}
Creates a new instance of the model using entry as a root
node. Parameters:
entry - The root node.
|
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.xmlbeans.samples.xmltree.XmlModel Detail: |
public void addTreeModelListener(TreeModelListener treeModelListener) {
m_treeModelListeners.addElement(treeModelListener);
}
|
public Object getChild(Object node,
int index) {
XmlEntry entry = (XmlEntry) node;
return entry.getChild(index);
}
Gets the child of node at index. |
public int getChildCount(Object node) {
XmlEntry entry = (XmlEntry) node;
return entry.getChildCount();
}
Gets the number of children that node has. |
public int getIndexOfChild(Object parentNode,
Object childNode) {
int childIndex = 0;
XmlEntry parent = (XmlEntry) parentNode;
XmlEntry[] children = parent.getChildren();
for (int i = 0; i < children.length; i++)
{
if (children[i].equals(childNode))
{
childIndex = i;
}
}
return childIndex;
}
Gets the index of childNode as a child of parentNode. |
public Object getRoot() {
return m_rootEntry;
}
Gets the root of this model. |
public boolean isLeaf(Object node) {
XmlEntry entry = (XmlEntry) node;
return entry.getChildCount() == 0;
}
Determines whether node has any children, returning
true if it doesn't. |
public void removeTreeModelListener(TreeModelListener treeModelListener) {
m_treeModelListeners.removeElement(treeModelListener);
}
Removes a listener added by addTreeModelListener. |
public void valueForPathChanged(TreePath treePath,
Object newValue) {
System.out.println("Path changing: " + treePath.toString() + "; "
+ newValue.toString());
}
Called when the user has altered the value for the item identified by
treePath to newValue. |