That was something that was not build in yet. I added this to the tree
component:

        /**
         * Expand or collapse all nodes.
         *
         * @param expand
         *            If true, expand all nodes in the tree. Else collapse all 
nodes
         *            in the tree.
         */
        public void expandAll(boolean expand)
        {
                TreeNode root = (TreeNode)getTreeState().getModel().getRoot();
                expandAll(new TreePath(root), expand);
        }

        private final void expandAll(TreePath parent, boolean expand)
        {
                TreeNode node = (TreeNode)parent.getLastPathComponent();
                if (node.getChildCount() >= 0)
                {
                        for (Enumeration e = node.children(); 
e.hasMoreElements();)
                        {
                                TreeNode n = (TreeNode)e.nextElement();
                                TreePath path = parent.pathByAddingChild(n);
                                expandAll(path, expand);
                        }
                }

                if (expand)
                {
                        expandPath(parent);
                }
                else
                {
                        collapsePath(parent);
                }
        }

        /**
         * Ensures that the node identified by the specified path is expanded 
and
         * viewable. If the last item in the path is a leaf, this will have no
         * effect.
         *
         * @param path
         *            the <code>TreePath</code> identifying a node
         */
        public void expandPath(TreePath path)
        {
                // Only expand if not leaf!
                TreeModel model = getTreeState().getModel();

                if (path != null && model != null &&
!model.isLeaf(path.getLastPathComponent()))
                {
                        setExpandedState(path, true);
                }
        }

        /**
         * Ensures that the node identified by the specified path is collapsed 
and
         * viewable.
         *
         * @param path
         *            the <code>TreePath</code> identifying a node
         */
        public void collapsePath(TreePath path)
        {
                setExpandedState(path, false);
        }

and I added two links that use this in the nested example.

Have fun with it.

Eelco


On 5/29/06, David Leangen <[EMAIL PROTECTED]> wrote:

Hello!

My assumption when using the TreeModel is that the
wicket.markup.html.Tree is analogous to javax.swing.tree.JTree.

Although I'm not so familiar with JTree (or anything Swing for that
matter), there are many examples available out there.


However, there are a few things that are not so obvious to me right now
with the Wicket TreeModel.

1. How do I collapse branches by default?

2. I tried the following, but it did not seem to do anything:
   getTreeState().getSelectionModel().setSelectionMode(
      TreeSelectionModel.SINGLE_TREE_SELECTION );


Any hints would be great!


Thank you!
Dave



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to