This is great! Thanks!!

BTW, sorry to ask such a basic question... It's about models again.

I noticed that the event is being triggered and the state of the object
is being correctly changed. However, upon the subsequent request, the
changed state was not "persisted" (so to speak) in the model, and the
tree stays unchanged.

This is what I have (largely "inspired" from the examples):

  add
  ( 
      new DataView( "categoryTrees", 
      new TreeCategoryDataProvider( getServiceManager() ) )
      {
          private static final long serialVersionUID = 1L;

          protected void populateItem( final Item item )
          {
             MyTreeNode treeNode = (MyTreeNode)item.getModelObject();
             TreeModel treeModel = convertToTreeModel( treeNode );
             Tree tree = new MeshTree( "categoryTree", treeModel )
             {
                private static final long serialVersionUID = 1L;

                protected String getNodeLabel( DefaultMutableTreeNode
node )
                {
                    final MyTreeNode treeNode =
(MyTreeNode)node.getUserObject();
                    return treeNode.getLabel();
                }
             };

             item.add( tree );
          }
     }
 );


Convert to TreeModel looks like this:

  private TreeModel convertToTreeModel( final MyTreeNode node )
  {
    try
    {
       final DefaultMutableTreeNode rootNode = new
DefaultMutableTreeNode( node );
       List<MyTreeNode> children = null;

       // Get the children from the DB
       children = node.retrieveChildren();
       for( MyTreeNode child : children )
       {
          rootNode.add( new DefaultMutableTreeNode( child ) );
       }

       final TreeModel model = new DefaultTreeModel( rootNode );
       return model;
   }
   catch ( FinderException e )
   {
      throw new RuntimeException( e );
   }
 }



Wondering if you can tell me what I'm doing wrong here...

Thanks so much!




On Mon, 2006-05-29 at 23:02 -0700, Eelco Hillenius wrote:
> 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



-------------------------------------------------------
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