/// <summary>
        /// Rebuilds the tree from scratch.
        /// </summary>
        public void RebuildTree(bool saveState)
        {
            // store old tree state
            if (project != null && saveState)
            {
                PluginData.GetPrefs(project).ExpandedPaths = ExpandedPaths;
                PluginData.Save();
            }

            foreach (GenericNode node in Nodes)
            {
                node.Dispose();
            }

            BeginUpdate();

            SelectedNodes = null;
            Nodes.Clear();
            nodeMap.Clear();
            ShowRootLines = false;

            if (project == null)
            {
                EndUpdate();
                return;
            }

            // create the top-level project node
            ProjectNode projectNode = new ProjectNode(project);

            Nodes.Add(projectNode);
            projectNode.Refresh(true);
            projectNode.Expand();

            ArrayList classpaths = new ArrayList();

            if (Settings.ShowProjectClasspaths)
            {
                classpaths.AddRange(project.Classpaths);
            }

            if (Settings.ShowGlobalClasspaths)
            {
                classpaths.AddRange(Settings.GlobalClasspaths.Split(';'));
            }

            // add classpaths at the top level also
            foreach (string classpath in classpaths)
            {
                string absolute = classpath;

                if (!Path.IsPathRooted(absolute))
                {
                    absolute = project.GetAbsolutePath(classpath);
                }

                if (absolute.StartsWith(project.Directory))
                {
                    continue;
                }

                ClasspathNode cpNode = new ClasspathNode(project, absolute, classpath);
                Nodes.Add(cpNode);
                cpNode.Refresh(true);
                ShowRootLines = true;
            }

            // restore tree state
            if (project != null && Settings.RestoreTreeState)
            {
                ExpandedPaths = PluginData.GetPrefs(project).ExpandedPaths;
            }

            // scroll to the top
            projectNode.EnsureVisible();
            SelectedNode = projectNode;
            Win32.Scrolling.scrollToLeft(this);

            EndUpdate();
        }