treetable setCollapsed without calling listener

Hi Gurus

I have a tree table with registered Tree.ExpandListener and Tree.CollapseListener.

I want to implement a scheme where if the user expands one parent, any other parents are automatically collapsed. In a simple world I can make this work by calling tree.setCollapsed(otherParent, true) in the expand listener.

Unfortunately our app requires a bit of work on the expand/collapse, so I’m triggering a background thread on each so the user gets some indication of what’s going on, and I can’t keep track of currentExpandedItem.

Here’s a simplified view of the code:-

abstract class BackgroundTask extends java.util.TimerTask {
    public abstract void doWork();   // this works fine
public void nodeExpand(ExpandEvent event) {
    // start progress indicator
    NodeExpandTask task = new NodeExpandTask(event);

public void nodeCollapse(CollapseEvent event) {
    // start progress indicator
    NodeCollapseTask task = new NodeCollapseTask(event);

class NodeExpandTask extends BackgroundTask {
    public void doWork() {
        try {
            tree.setCollapsed(currentExpandedItem, true);  // triggers a CollapseEvent
            currentExpandedItem = selectedItem;
        } catch (MyException e) {
            tree.setCollapsed(selectedItem, true);
        } finally {
            // stop progress indicator

class NodeCollapseTask extends BackgroundTask {
    public void doWork() {
        // giveBackVariousResources();
        currentExpandedItem = null;     // can't do this

My problem is trying to keep track of which item is currently expanded:-

  • I can’t clear it in NodeCollapseTask, because that will trash the value just been set in ExpandTask.
  • I’d like NodeExpand to wait until the automatic collapse has finished, then set it, but I don’t see how I could do that
  • Is it possible to do some kind of tree.SetCollapsedButDontCallListeners(), i.e. so I can make sure the UI element stays up to date, and do my own processing in my own thread?
  • Or am I missing some obvious solution after staring at it for too long?

One virtual beer and an infinite supply of kudos to anyone who suggests a viable route…!

Alternatively, is there a way for my listener to distinguish between “user clicked collapse” and “application logic sent a collapse event”?
That way, I can do all the processing in the expand background thread, then send a collapse event to the UI component without it generating more background work
Thanks again