Before all I'm sorry for my bad english and tell me if anything is not understandable.
I have 2 Jtree. Each tree apparently has the same information. The only thing that changes in them are the names of the properties that has each node.
Eg JTree1 has an ID and a ParentID. These properties have as a name and value. Name: ID_Tree1. Value: TESTID1 / / Name: ParentID_Tree1. Value: TESTPID1 In JTree2 has the same values as in the JTree1 but the names are different.
There is a moment in which I transfer a node from JTree1 to JTree2 to create it. The transfer/creation is correct but when I read the nodes, it has a different property name architecture(Jtree1 arch.) and can't be read because need to have the JTree2 architecture. I have the function changeAttributesNamesFromDOORSToTC() to solve the problem because it just change the name to the correct name and understandable for JTree2
The real problem: The function make the change in the node of JTree2 but at the same time it change the values name of the same node in JTree1. It makes reference data instead of assignments I think.
How can I solve this!?
Thanks!
JTree treeDOORSCode; //JTree1
JTree treeTCCode; //JTree2
Main Code:
//ACTUAL NODE
DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) CurrentSelection.getLastPathComponent();
NodeClass actualNode = (NodeClass)selectedTreeNode.getUserObject();
//ACTUAL PARENT NODE
DefaultMutableTreeNode selectedParentTreeNode = (DefaultMutableTreeNode) selectedTreeNode.getParent();
NodeClass parentNode = (NodeClass) selectedParentTreeNode.getUserObject();
DefaultMutableTreeNode parent = findNode(NodeClass.getNodeParentIdentifierAttrDOORS(parentNode), treeTCCode);
//NEW NODE
DefaultMutableTreeNode newSelectedTreeNode = selectedTreeNode;
//NEW PART
NodeClass newNode = new NodeClass();
newNode = insertNodeInfo(actualNode);
//Create the Model and insert the node
DefaultTreeModel treeModelTC = (DefaultTreeModel)treeTCCode.getModel();
treeModelTC.insertNodeInto(newSelectedTreeNode, parent, 0);
//NEW PART
newNode .changeAttributesNamesFromDOORSToTC();
newSelectedTreeNode.setUserObject(newNode);
Function which change the attr Name values:
public void changeAttributesNamesFromDOORSToTC(){
for (int i = 0; i < this.attributes.size(); i++) {
if (this.attributes.get(i).attributeName.equals(DOORS_ID)){
if (this.tag.equals(TYPE_NAME_CASE)){
this.attributes.get(i).attributeName = TC_IDCASE;
}
if (this.tag.equals(TYPE_NAME_FOLDER)){
this.attributes.get(i).attributeName = TC_IDFOLDER;
}
if (this.tag.equals(TYPE_NAME_FEATURE)){
this.attributes.get(i).attributeName = TC_IDFEATURE;
}
}
if (this.attributes.get(i).attributeName.equals(DOORS_PARENTID)){
this.attributes.get(i).attributeName = TC_PARENTID;
}
if (this.attributes.get(i).attributeName.equals(DOORS_SRS)){
this.attributes.get(i).attributeName = TC_SRS;
}
}
}
Attributes Class:
NodeAttributesClass (String attributeName, String attributeValue)
{
this.attributeName = attributeName;
this.attributeValue = attributeValue;
}
Let me know if need more info!