You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Kai Schubert-Altmann <ka...@hcs77.de> on 2008/06/26 11:44:45 UTC

How to add nodes to a tree using Ajax

Hi,

how can I add nodes to a wicket tree using a AjaxLink?

I tried to add a node to the SimpleTree of this example:
http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1

with this code:

        add(new AjaxLink("addNode")
        {
            public void onClick(AjaxRequestTarget target)
            {
              List list = new ArrayList();
              list.add("new node");
              BaseTreePage.this.add(rootNode,list);
              getTree().updateTree(target);
            }
        });

But the tree will not update itself.

Thanks in advance,
Kai

Re: How to add nodes to a tree using Ajax

Posted by geke <ge...@yahoo.de>.
sorry hier are the file  http://www.nabble.com/file/p18279343/MyTree.java
MyTree.java 

To your point 3:
A possible solution would be:
Catch only the root level and next level from the database, give it into the
tree model and display it.

on click on the plus image you catch the next level and so on.

the plus image can you maybe handle with the onJunctionLinkClicked method.

GeKe



Kai Schubert-Altmann wrote:
> 
> Hello,
> 
> 2. Thanks, but your file contains only an empty class.
> 
> 3. If the tree has ever 2000 nodes, it lasts maybe a little bit to long to
> get all data at once from the database.
> 
> Kai
> 
> 2008/7/4 geke <ge...@yahoo.de>:
> 
>>
>> Hello,
>>
>> to your point 2.
>> You have to build a subclass from LinkTree.
>> A example is in the attachement.
>> http://www.nabble.com/file/p18273760/MyTree.java MyTree.java
>>
>> To point 3.
>>
>> Why you only want to load only the root and reload the next level?
>> In my solution all Node are updated via updateTree().
>>
>> GeKe
>>
>>
>> Kai Schubert-Altmann wrote:
>> >
>> > HI everybody
>> >
>> > I solved the first problem by my own by adding the following method to
>> the
>> > tree:
>> >
>> >   public DefaultMutableTreeNode getSelectedNode() {
>> >     Object selected = null;
>> >     try {
>> >       selected =
>> this.getTreeState().getSelectedNodes().iterator().next();
>> >     } catch (NoSuchElementException nseEx) { }
>> >     return (selected instanceof DefaultMutableTreeNode)?
>> > (DefaultMutableTreeNode)selected : null;
>> >   }
>> >
>> > That worked for me without problems. Or is there an easier way?
>> >
>> > Kai
>> >
>> > 2008/7/3 Kai Schubert-Altmann <ka...@hcs77.de>:
>> >
>> >> Hi,
>> >>
>> >> thanks to both of you! Matejs code worked very fine, so i didn't tried
>> >> gekes version.
>> >>
>> >> But now i have the next three problems/questions:
>> >>
>> >> 1. If i want to add a new node to the selected node, then i have to
>> get
>> >> the
>> >> selected node first. How can i do that?
>> >>
>> >> 2. Can i change the shown icons to custom ones?
>> >>
>> >> 3. Is it possible to load the root element only and reload the next
>> >> level,
>> >> when you click the plus-image?
>> >>
>> >> Kai
>> >>
>> >> 2008/6/27 geke <ge...@yahoo.de>:
>> >>
>> >>
>> >>> try this code:
>> >>>
>> >>> fileTree = new LinkTree();
>> >>>
>> >>> TreeNode existingTreeNode = ...;
>> >>>
>> >>> DefaultMutableTreeNode newTreeNode = new
>> DefaultMutableTreeNode(object);
>> >>> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
>> >>> model.insertNodeInto(newTreeNode, treeNode, 0);
>> >>> fileTree.updateTree(target);
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> Kai Schubert-Altmann wrote:
>> >>> >
>> >>> > Hi,
>> >>> >
>> >>> > how can I add nodes to a wicket tree using a AjaxLink?
>> >>> >
>> >>> > I tried to add a node to the SimpleTree of this example:
>> >>> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
>> >>> >
>> >>> > with this code:
>> >>> >
>> >>> >         add(new AjaxLink("addNode")
>> >>> >         {
>> >>> >             public void onClick(AjaxRequestTarget target)
>> >>> >             {
>> >>> >               List list = new ArrayList();
>> >>> >               list.add("new node");
>> >>> >               BaseTreePage.this.add(rootNode,list);
>> >>> >               getTree().updateTree(target);
>> >>> >             }
>> >>> >         });
>> >>> >
>> >>> > But the tree will not update itself.
>> >>> >
>> >>> > Thanks in advance,
>> >>> > Kai
>> >>> >
>> >>> >
>> >>>
>> >>> --
>> >>> View this message in context:
>> >>>
>> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
>> >>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> >>>
>> >>>
>> >>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>
>> >>>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18273760.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18279343.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to add nodes to a tree using Ajax

Posted by Kai Schubert-Altmann <ka...@hcs77.de>.
Hello,

2. Thanks, but your file contains only an empty class.

3. If the tree has ever 2000 nodes, it lasts maybe a little bit to long to
get all data at once from the database.

Kai

2008/7/4 geke <ge...@yahoo.de>:

>
> Hello,
>
> to your point 2.
> You have to build a subclass from LinkTree.
> A example is in the attachement.
> http://www.nabble.com/file/p18273760/MyTree.java MyTree.java
>
> To point 3.
>
> Why you only want to load only the root and reload the next level?
> In my solution all Node are updated via updateTree().
>
> GeKe
>
>
> Kai Schubert-Altmann wrote:
> >
> > HI everybody
> >
> > I solved the first problem by my own by adding the following method to
> the
> > tree:
> >
> >   public DefaultMutableTreeNode getSelectedNode() {
> >     Object selected = null;
> >     try {
> >       selected =
> this.getTreeState().getSelectedNodes().iterator().next();
> >     } catch (NoSuchElementException nseEx) { }
> >     return (selected instanceof DefaultMutableTreeNode)?
> > (DefaultMutableTreeNode)selected : null;
> >   }
> >
> > That worked for me without problems. Or is there an easier way?
> >
> > Kai
> >
> > 2008/7/3 Kai Schubert-Altmann <ka...@hcs77.de>:
> >
> >> Hi,
> >>
> >> thanks to both of you! Matejs code worked very fine, so i didn't tried
> >> gekes version.
> >>
> >> But now i have the next three problems/questions:
> >>
> >> 1. If i want to add a new node to the selected node, then i have to get
> >> the
> >> selected node first. How can i do that?
> >>
> >> 2. Can i change the shown icons to custom ones?
> >>
> >> 3. Is it possible to load the root element only and reload the next
> >> level,
> >> when you click the plus-image?
> >>
> >> Kai
> >>
> >> 2008/6/27 geke <ge...@yahoo.de>:
> >>
> >>
> >>> try this code:
> >>>
> >>> fileTree = new LinkTree();
> >>>
> >>> TreeNode existingTreeNode = ...;
> >>>
> >>> DefaultMutableTreeNode newTreeNode = new
> DefaultMutableTreeNode(object);
> >>> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
> >>> model.insertNodeInto(newTreeNode, treeNode, 0);
> >>> fileTree.updateTree(target);
> >>>
> >>>
> >>>
> >>>
> >>> Kai Schubert-Altmann wrote:
> >>> >
> >>> > Hi,
> >>> >
> >>> > how can I add nodes to a wicket tree using a AjaxLink?
> >>> >
> >>> > I tried to add a node to the SimpleTree of this example:
> >>> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
> >>> >
> >>> > with this code:
> >>> >
> >>> >         add(new AjaxLink("addNode")
> >>> >         {
> >>> >             public void onClick(AjaxRequestTarget target)
> >>> >             {
> >>> >               List list = new ArrayList();
> >>> >               list.add("new node");
> >>> >               BaseTreePage.this.add(rootNode,list);
> >>> >               getTree().updateTree(target);
> >>> >             }
> >>> >         });
> >>> >
> >>> > But the tree will not update itself.
> >>> >
> >>> > Thanks in advance,
> >>> > Kai
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
> >>> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18273760.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to add nodes to a tree using Ajax

Posted by geke <ge...@yahoo.de>.
Hello,

to your point 2.
You have to build a subclass from LinkTree.
A example is in the attachement. 
http://www.nabble.com/file/p18273760/MyTree.java MyTree.java 

To point 3.

Why you only want to load only the root and reload the next level?
In my solution all Node are updated via updateTree().

GeKe


Kai Schubert-Altmann wrote:
> 
> HI everybody
> 
> I solved the first problem by my own by adding the following method to the
> tree:
> 
>   public DefaultMutableTreeNode getSelectedNode() {
>     Object selected = null;
>     try {
>       selected = this.getTreeState().getSelectedNodes().iterator().next();
>     } catch (NoSuchElementException nseEx) { }
>     return (selected instanceof DefaultMutableTreeNode)?
> (DefaultMutableTreeNode)selected : null;
>   }
> 
> That worked for me without problems. Or is there an easier way?
> 
> Kai
> 
> 2008/7/3 Kai Schubert-Altmann <ka...@hcs77.de>:
> 
>> Hi,
>>
>> thanks to both of you! Matejs code worked very fine, so i didn't tried
>> gekes version.
>>
>> But now i have the next three problems/questions:
>>
>> 1. If i want to add a new node to the selected node, then i have to get
>> the
>> selected node first. How can i do that?
>>
>> 2. Can i change the shown icons to custom ones?
>>
>> 3. Is it possible to load the root element only and reload the next
>> level,
>> when you click the plus-image?
>>
>> Kai
>>
>> 2008/6/27 geke <ge...@yahoo.de>:
>>
>>
>>> try this code:
>>>
>>> fileTree = new LinkTree();
>>>
>>> TreeNode existingTreeNode = ...;
>>>
>>> DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(object);
>>> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
>>> model.insertNodeInto(newTreeNode, treeNode, 0);
>>> fileTree.updateTree(target);
>>>
>>>
>>>
>>>
>>> Kai Schubert-Altmann wrote:
>>> >
>>> > Hi,
>>> >
>>> > how can I add nodes to a wicket tree using a AjaxLink?
>>> >
>>> > I tried to add a node to the SimpleTree of this example:
>>> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
>>> >
>>> > with this code:
>>> >
>>> >         add(new AjaxLink("addNode")
>>> >         {
>>> >             public void onClick(AjaxRequestTarget target)
>>> >             {
>>> >               List list = new ArrayList();
>>> >               list.add("new node");
>>> >               BaseTreePage.this.add(rootNode,list);
>>> >               getTree().updateTree(target);
>>> >             }
>>> >         });
>>> >
>>> > But the tree will not update itself.
>>> >
>>> > Thanks in advance,
>>> > Kai
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18273760.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to add nodes to a tree using Ajax

Posted by Kai Schubert-Altmann <ka...@hcs77.de>.
HI everybody

I solved the first problem by my own by adding the following method to the
tree:

  public DefaultMutableTreeNode getSelectedNode() {
    Object selected = null;
    try {
      selected = this.getTreeState().getSelectedNodes().iterator().next();
    } catch (NoSuchElementException nseEx) { }
    return (selected instanceof DefaultMutableTreeNode)?
(DefaultMutableTreeNode)selected : null;
  }

That worked for me without problems. Or is there an easier way?

Kai

2008/7/3 Kai Schubert-Altmann <ka...@hcs77.de>:

> Hi,
>
> thanks to both of you! Matejs code worked very fine, so i didn't tried
> gekes version.
>
> But now i have the next three problems/questions:
>
> 1. If i want to add a new node to the selected node, then i have to get the
> selected node first. How can i do that?
>
> 2. Can i change the shown icons to custom ones?
>
> 3. Is it possible to load the root element only and reload the next level,
> when you click the plus-image?
>
> Kai
>
> 2008/6/27 geke <ge...@yahoo.de>:
>
>
>> try this code:
>>
>> fileTree = new LinkTree();
>>
>> TreeNode existingTreeNode = ...;
>>
>> DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(object);
>> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
>> model.insertNodeInto(newTreeNode, treeNode, 0);
>> fileTree.updateTree(target);
>>
>>
>>
>>
>> Kai Schubert-Altmann wrote:
>> >
>> > Hi,
>> >
>> > how can I add nodes to a wicket tree using a AjaxLink?
>> >
>> > I tried to add a node to the SimpleTree of this example:
>> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
>> >
>> > with this code:
>> >
>> >         add(new AjaxLink("addNode")
>> >         {
>> >             public void onClick(AjaxRequestTarget target)
>> >             {
>> >               List list = new ArrayList();
>> >               list.add("new node");
>> >               BaseTreePage.this.add(rootNode,list);
>> >               getTree().updateTree(target);
>> >             }
>> >         });
>> >
>> > But the tree will not update itself.
>> >
>> > Thanks in advance,
>> > Kai
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

Re: How to add nodes to a tree using Ajax

Posted by Kai Schubert-Altmann <ka...@hcs77.de>.
Hi,

thanks to both of you! Matejs code worked very fine, so i didn't tried gekes
version.

But now i have the next three problems/questions:

1. If i want to add a new node to the selected node, then i have to get the
selected node first. How can i do that?

2. Can i change the shown icons to custom ones?

3. Is it possible to load the root element only and reload the next level,
when you click the plus-image?

Kai

2008/6/27 geke <ge...@yahoo.de>:

>
> try this code:
>
> fileTree = new LinkTree();
>
> TreeNode existingTreeNode = ...;
>
> DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(object);
> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
> model.insertNodeInto(newTreeNode, treeNode, 0);
> fileTree.updateTree(target);
>
>
>
>
> Kai Schubert-Altmann wrote:
> >
> > Hi,
> >
> > how can I add nodes to a wicket tree using a AjaxLink?
> >
> > I tried to add a node to the SimpleTree of this example:
> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
> >
> > with this code:
> >
> >         add(new AjaxLink("addNode")
> >         {
> >             public void onClick(AjaxRequestTarget target)
> >             {
> >               List list = new ArrayList();
> >               list.add("new node");
> >               BaseTreePage.this.add(rootNode,list);
> >               getTree().updateTree(target);
> >             }
> >         });
> >
> > But the tree will not update itself.
> >
> > Thanks in advance,
> > Kai
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to add nodes to a tree using Ajax

Posted by geke <ge...@yahoo.de>.
try this code:

fileTree = new LinkTree();

TreeNode existingTreeNode = ...;

DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(object);
DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
model.insertNodeInto(newTreeNode, treeNode, 0);
fileTree.updateTree(target);




Kai Schubert-Altmann wrote:
> 
> Hi,
> 
> how can I add nodes to a wicket tree using a AjaxLink?
> 
> I tried to add a node to the SimpleTree of this example:
> http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
> 
> with this code:
> 
>         add(new AjaxLink("addNode")
>         {
>             public void onClick(AjaxRequestTarget target)
>             {
>               List list = new ArrayList();
>               list.add("new node");
>               BaseTreePage.this.add(rootNode,list);
>               getTree().updateTree(target);
>             }
>         });
> 
> But the tree will not update itself.
> 
> Thanks in advance,
> Kai
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to add nodes to a tree using Ajax

Posted by Matej Knopp <ma...@gmail.com>.
Your model is either broken or just doesn't sent the correct
notifications. You can try calling tree.invalidateAll() to make sure
it's rebuilt after you add node.

-Matej

On Thu, Jun 26, 2008 at 11:44 AM, Kai Schubert-Altmann <ka...@hcs77.de> wrote:
> Hi,
>
> how can I add nodes to a wicket tree using a AjaxLink?
>
> I tried to add a node to the SimpleTree of this example:
> http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
>
> with this code:
>
>        add(new AjaxLink("addNode")
>        {
>            public void onClick(AjaxRequestTarget target)
>            {
>              List list = new ArrayList();
>              list.add("new node");
>              BaseTreePage.this.add(rootNode,list);
>              getTree().updateTree(target);
>            }
>        });
>
> But the tree will not update itself.
>
> Thanks in advance,
> Kai
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org