/**
   * Assigns the tree viewer that I control.
   *
   * @param tree my tree viewer
   */
  void setTreeViewer(final TreeViewer tree) {
    if (this.tree != null) {
      this.tree.removeSelectionChangedListener(this);
    }

    this.tree = tree;

    if (this.tree != null) {
      this.tree.addSelectionChangedListener(this);

      this.tree.setInput(workspace.getWorkingSets());

      if (!workspace.getWorkingSets().isEmpty()) {
        tree.getTree()
            .getDisplay()
            .asyncExec(
                new Runnable() {

                  public void run() {
                    Object initialSelection;

                    ITreeContentProvider content = (ITreeContentProvider) tree.getContentProvider();

                    if ((initialWorkingSet != null)
                        && Arrays.asList(content.getElements(tree.getInput()))
                            .contains(initialWorkingSet)) {
                      initialSelection = initialWorkingSet;
                    } else {
                      // we have a most-recently-used working set. Just
                      // take the first in tree order
                      initialSelection = tree.getTree().getItem(0).getData();
                    }

                    Object[] children = content.getChildren(initialSelection);
                    IStructuredSelection sel;

                    if ((children == null) || (children.length == 0)) {
                      // Shouldn't happen: there should at least be the
                      // read-only config.
                      // Can only select the initial working set
                      sel = new StructuredSelection(initialSelection);
                    } else {
                      Object[] toSort = new Object[children.length];
                      System.arraycopy(children, 0, toSort, 0, children.length);
                      tree.getComparator().sort(tree, toSort);
                      sel = new StructuredSelection(toSort[0]);
                    }

                    // make the selection
                    tree.setSelection(sel, true);
                  }
                });
      }
    }
  }
  /**
   * Updates the display to reflect potential changes in project activation and the resulting
   * changes in working-set config activation, if any.
   */
  private void updateForActivation() {
    // update all working-set configs that intersect this config
    Collection<IWorkingSetProxy.ISnapshot> unaffectedWorkingSets =
        new java.util.HashSet<IWorkingSetProxy.ISnapshot>(workspace.getWorkingSets());

    for (IProject project : currentConfig.getWorkingSet().resolveProjects()) {
      for (Iterator<IWorkingSetProxy.ISnapshot> iter = unaffectedWorkingSets.iterator();
          iter.hasNext(); ) {
        IWorkingSetProxy.ISnapshot next = iter.next();

        if (next.resolveProjects().contains(project)) {
          iter.remove();

          if (next.updateActiveConfigurations()) {
            // major change. Refresh it altogether
            tree.refresh(next);
          } else {
            // lighter-weight updates of its configs
            for (IWorkingSetConfiguration config : next.getConfigurations()) {
              tree.update(config, null);
            }
          }
        }
      }
    }

    updateButtons();
  }