`Jtree` and `TreeModel`: is order of `getChildCount` and `getChild` guaranteed?

24 Views Asked by At

Is it safe to assume that TreeModel.getChild is always called for the last parent checked by getChildCount? In other words, JTree doesn't cache number of children, and the order is always the following:

getChildCount(Foo)
getChild(Foo, 1)
getChild(Foo, 2)

getChildCount(Bar)
getChild(Bar, 1)
getChild(Bar, 2)

..and never

getChildCount(Foo)
getChildCount(Bar)
getChild(Foo, 1)
getChild(Foo, 2)
getChild(Bar, 1)
getChild(Bar, 2)

My model wraps thing that provides a list of a children. Unfortunately, each call might return different list. I want to cache the last result i.e (code isn't real of course)

getChildCount(parent) {
  this.parent = parent
  this.children = foo.getList(parent)
  return this.children.size()
}
//
getChild(parent, index) {
  assert(this.parent == parent)
  return children[index]
}

Or is it completely wrong, and JTree is free to cache anything and I should explicitly notify TreeModelListener about any change?

0

There are 0 best solutions below