wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Cloning a TreeNode......... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cloning a TreeNode........." Watch "Cloning a TreeNode........." New topic
Author

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

don lohith
Greenhorn

Joined: Oct 24, 2007
Posts: 16
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

Joined: Oct 24, 2007
Posts: 16
It is important that you check your private messages and follow the instructions in the message from me.

I didn't get you.......
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Its high time we had tool tips for the icons!


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
don lohith
Greenhorn

Joined: Oct 24, 2007
Posts: 16
Its high time we had tool tips for the icons!

Can you please tell me what to do........???
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

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

Joined: Oct 24, 2007
Posts: 16


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

Joined: Jul 26, 2007
Posts: 10172
    
    8

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

Joined: Oct 24, 2007
Posts: 16
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
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Check this out. It visits each tree node using recursion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cloning a TreeNode.........
 
Similar Threads
Fail to create generic array?
Trees in Java
Using TreeModel: How to implement editing!!??
Cloning a complete TreeNode
TreeNode ClassCastException?