Tree: removing child nodes of a parent

I’m new to vaadin and I’m looking for a way to remove all the child nodes. I tried

public void nodeCollapse(CollapseEvent event) {
    Object o=event.getItemId();
    Collection<?> col=tree.getChildren(o);

and received an UnsupportedOperationException.

I tried using an Iterator and removing one at a time and also received an error. I looked through the forums and couldn’t find the answer. Anyone have a solution to this?

Thanks in advance.


If you are using Java 8, you can try something like:

Collection<?> childrenIDs = tree.getChildren(o);;

If not, maybe something like:

Object toRemove = childrenIDs.toArray();
int size = toRemove.length;

for (int i = 0; i < size; i++) {
[/code]Hope that helps!