0

Problem with adding node to subnode in TREE

asked 2009-10-31 02:27:18 +0800

cros gravatar image cros
153

I have ClientNewComposer.java file --

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.*;
import java.util.*;

public class ClientNewComposer extends GenericForwardComposer {

private Textbox HospitalName, HospitalParent, HospitalType;
private Tree treeClient;
private Label statusBar;
private Label label;
private Label nameHospital;
private Window clientWin;
String strClickedButton;
String idForSelectedNode;
List<SimpleTreeNode> node1_1_childrenHosp = new ArrayList<SimpleTreeNode>();
// List node1_1_parent = new ArrayList<SimpleTreeNode>();
List node1_1_childrenClinic = new ArrayList();
List node1_1_childrenLab = new ArrayList();
List rootChildrenList = new ArrayList();
Set newSetCli = new HashSet();
Set newSetLab = new HashSet();
Set newSetHosp = new HashSet();
private Menuitem menuSaveHospital, menuSave;
private Treechildren childChildren;

@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
public void onClick$menuNew() {
strClickedButton = "New";
}

public void onClick$menuSaveHospital() {

String parentName;
if (strClickedButton != null && strClickedButton == "New") {
parentName = HospitalType.getValue();
} else {
parentName = nameHospital.getValue();
}
Treeitem parent = null;
boolean flag = true;
for (Object treeItem : treeClient.getItems()) {
Treerow treeRow = ((Treeitem) treeItem).getTreerow();
Treecell treeCell = (Treecell) treeRow.getFirstChild();

if ((treeCell.getLabel().trim()).equals(parentName.trim())) {
System.out.println("nside treeCell.getLabel()=parentName");
parent = (Treeitem) treeItem;
break;
} else
flag = false;
}
// my main logic starts here

SimpleTreeNode stn1_1 = null;
SimpleTreeNode stn1_2 = null;
SimpleTreeNode stn1_3 = null;

Treeitem ti = new Treeitem();
Treerow tr = new Treerow();

if (menuSaveHospital.getLabel() == "Add") {
// make Save button enable
menuSave.setDisabled(false);
if (parent == null) {

if (HospitalType.getValue().equals("HOSPITAL")) {
newSetHosp.add(HospitalName.getValue());
node1_1_childrenHosp.addAll(newSetHosp);

// to avoid duplicates
List decorateListHosp = org.apache.commons.collections.list.SetUniqueList
.decorate(node1_1_childrenHosp);

if (node1_1_childrenHosp != null) {

for (int i = 0; i < node1_1_childrenHosp.size(); i++) {
decorateListHosp.add(node1_1_childrenHosp.get(i));
}
}

stn1_1 = new SimpleTreeNode(HospitalType.getValue(),decorateListHosp);
}
if (HospitalType.getValue().equals("CLINIC")) {
newSetCli.add(HospitalName.getValue());
node1_1_childrenClinic.addAll(newSetCli);
// to avoid duplicates
List decorateListCLi = org.apache.commons.collections.list.SetUniqueList
.decorate(node1_1_childrenClinic);

if (decorateListCLi != null) {
for (int i = 0; i < decorateListCLi.size(); i++) {
decorateListCLi.add(decorateListCLi.get(i));
}
}

stn1_2 = new SimpleTreeNode(HospitalType.getValue(),decorateListCLi);
}
if (HospitalType.getValue().equals("LAB")) {
newSetLab.add(HospitalName.getValue());
node1_1_childrenLab.addAll(newSetLab);
// to avoid duplicates
List decorateListLab = org.apache.commons.collections.list.SetUniqueList
.decorate(node1_1_childrenLab);
if (decorateListLab != null) {
for (int i = 0; i < decorateListLab.size(); i++) {
decorateListLab.add(decorateListLab.get(i));
}
}

stn1_3 = new SimpleTreeNode(HospitalType.getValue(),decorateListLab);
}

if (stn1_1 == null) {
// do not do anything
} else {
System.out.println("INside ELse stn1_1 size="+ stn1_1.getData());
rootChildrenList.add(stn1_1);
}
if (stn1_2 == null) {
// do not do anything
} else {
rootChildrenList.add(stn1_2);
}
if (stn1_3 == null) {
// do not do anything
} else {
rootChildrenList.add(stn1_3);
}

}//end of parent=null

if (parent != null) {

if (HospitalType.getValue().equals(parent.getLabel())) {
newSetHosp.add(HospitalName.getValue());
node1_1_childrenHosp.addAll(newSetHosp);
// to avoid duplicates
List decorateListHosp = org.apache.commons.collections.list.SetUniqueList
.decorate(node1_1_childrenHosp);

if (node1_1_childrenHosp != null) {
for (int i = 0; i < node1_1_childrenHosp.size(); i++) {
decorateListHosp.add(node1_1_childrenHosp.get(i));
}
}
stn1_1 = new SimpleTreeNode(HospitalType.getValue(),decorateListHosp);
}

Treechildren treeChildren = parent.getTreechildren();
if (treeChildren == null) {
treeChildren = new Treechildren();
parent.appendChild(treeChildren);
}
tr.appendChild(new Treecell(HospitalName.getValue()));
tr.setParent(ti);
treeChildren.appendChild(ti);
}// end IF

}// end of else if ADD
SimpleTreeNode root = new SimpleTreeNode("ROOT",rootChildrenList);
SimpleTreeModel stm = new SimpleTreeModel(root);
treeClient.setModel(stm);
menuSave.setDisabled(false);

}// end of method onClick$menuSaveHospital()

I have combobox,textbox and Add button on Rigth side...and Tree structure, New button on LEFT.
So when I enter some value e.g : "abhi1" is textfield with combobox value="HOSPITAL", then tree structure is as follows:

HOSPITAL
  - abhi1

But when I try to add some value e.g : "abhi1.1" with combobox value="abhi1", then abhi1.1 is added to "HOSPITAL" and not "abhi1"
It is ---
HOSPITAL
  - abhi1
  - abhi1.1

Where am i going wrong??? Pls help me add new value e.g : "abhi1.1" with combobox value="abhi1" sothat tree structure looks like ---
HOSPITAL
  - abhi1
     - abhi1.1

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2009-11-02 22:37:27 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,

Have you tried to debug your Java code?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-10-31 02:27:18 +0800

Seen: 258 times

Last updated: Nov 02 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More