PDA

View Full Version : Setting an ID for a tree item created from a BaseTreeModel


zakabog
11-26-2008, 01:56 PM
I'm trying to figure out how to set a TreeItem's ID. I create the tree and fill it with BaseTreeModels (it's the only way I've found for populating a tree.) I can set the text of the item but I can't figure out how to set the ID. Below is the code I have to create the items, as you can see I tried

companyFolder.set("id", companyID);thinking that might do it but it doesn't work.


if (companies != null) {
for(int i = 0; i < companies.getLength(); i++) {
if (companies.item(i).toString() != null) {
Node companyNode = companies.item(i);
Element company = (Element) companyNode;

String companyID = company.getElementsByTagName("companyid").item(0).getChildNodes().item(0).getNodeValue();
String companyName = company.getElementsByTagName("name").item(0).getChildNodes().item(0).getNodeValue();

if (companyName != null) {
BaseTreeModel companyFolder = new BaseTreeModel();
companyFolder.set("name", companyName);
companyFolder.set("id", companyID);

String[] subFolders = {"Moderators", "Users", "Conferences"};
NavTree.store.add(companyFolder, false);

for (int j = 0; j < subFolders.length; j++) {
BaseTreeModel subFolder = new BaseTreeModel();
subFolder.set("name", subFolders[j]);
NavTree.store.add(companyFolder, subFolder, false);
}
}
}
}
}

zakabog
11-26-2008, 04:25 PM
Okay I got it (sort of) I had to get the model from the TreeItem (later in my code) then do get("id").