• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cloning a TreeNode.........

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi how can i clone a complete TreeNode......?(i Am doing a copy paste on TreeNode)
The node reference returned by such a method is used to paste the node elsewhere, So that if i add that node, i should be able to get the whole children hiearchy with it.......Please help........

there is a clone() in DefaultMutableTreeNode Class, which clones only that particular node, but what i want is the complete children node....
 
don lohith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is important that you check your private messages and follow the instructions in the message from me.

I didn't get you.......
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its high time we had tool tips for the icons!
 
don lohith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its high time we had tool tips for the icons!

Can you please tell me what to do........???
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lohith S:
[qb]Its high time we had tool tips for the icons!

Can you please tell me what to do........???[/QB]



That was not for you. It was for the admins.
We have a strict naming policy here at javaranch. One of the admins has posted you a private message asking you to change your display name from Lohith S.
To read your private messages click on the icon where you see two guys shaking hands in front of a mail envelope.
 
don lohith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That was not for you. It was for the admins.
We have a strict naming policy here at javaranch. One of the admins has posted you a private message asking you to change your display name from Lohith S.


Ok I have changed my display name from Lohith S to Lohith.......

but still i didn't get reply to my problem.........
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lohith:
[qb]

but still i didn't get reply to my problem.........



Have you considered how the DefaultMutableTreeNode is constructed?
Is it a parent child relation ship where the child itself can be a parent for further children? Can you use any existing methods in the DefaultMutableTreeNode to traverse this structure?
There already exists the clone method. Can you override it to get the clone which you want? Would recursion help?

Why dont you try out some code and post it here so people can help you out if you get stuck?

Ok. I almost forgot. Looks like you havent read your private message. Perhaps you were in a hurry.
Whenever you get time, you would do well to read this.

[ January 22, 2008: Message edited by: Maneesh Godbole ]
[ Doh! Edited again. Almost forgot deep clone means something else! ]
[ January 22, 2008: Message edited by: Maneesh Godbole ]
 
don lohith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The clone() method returns a shallow copy of the node, but i want a deepCopy of the node. I am trying to implement copy, paste on my WSDL tree structure node. I have written a TreeNode which extends javax.swing.tree.DefaultMutableTreeNode, here i am pasting cloneNode() method in my TreeNode.java

public TreeNode cloneNode() {
TreeNode newNode = new TreeNode();
newNode = (TreeNode)super.clone();

newNode.complexvect = (Vector)this.complexvect.clone();
if(msg != null){
newNode.msg = (Message)this.msg.clone();
}
newNode.mesname = this.mesname;
newNode.type = this.type;
newNode.myType = this.myType;
newNode.my_host = this.my_host;
newNode.my_port = this.my_port;
newNode.mynill = this.mynill;
newNode.nodeps = (NodeProperties)this.nodeps.clone();
if(ctype != null){
newNode.ctype = (ComplexMessage)this.ctype.clone();
}
newNode.role_flag = this.role_flag;
newNode.propertyName = this.propertyName;
newNode.propertyType = this.propertyType;
newNode.messageType = this.messageType;
newNode.part = this.part;
newNode.description = this.description;
System.out.println("child count...."+this.getChildCount());
for(int i = 0; i < this.getChildCount(); i++){
TreeNode child = (TreeNode)this.getChildAt(i);
newNode.add(child.cloneNode());
}
System.out.println("CloneNode......"+ newNode.getUserObject());
return newNode;
}

but this can be simpler i guess.......with a recursion mechanism....If anybody who has seen the WSDL tree structure can help me better......
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this out. It visits each tree node using recursion.
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic