Skip to main content
13-Aquamarine
December 8, 2022
Solved

How to fill XUI Treecontrol

  • December 8, 2022
  • 1 reply
  • 1564 views

Hello,

I have created an XUI dialog box with a tree control. I would like to know how to fill a tree control with ACL code.

I want to fill the treecontrol with an xml node (and child nodes).

David

Best answer by ClayHelberg

You will need to generate the <treenode> elements and append them to the <treecontrol> in your code. I don't have ACL code for this, but here's an example that uses Javascript to walk the doc structure recursively and build a tree:

// walks the document and creates a corresponding tree structure in the dialog
function populateTree(branch,oid) {
 var doc = branch.ownerDocument;
 var newbranch = doc.createElement("treenode");
 newbranch.setAttribute("label",Acl.eval("oid_name('" + oid + "')"));
 newbranch.setAttribute("appdata",oid);
 newbranch.setAttribute("id",oid_xmlname(oid));
 var nkids = Acl.eval("oid_children('" + oid + "')");
 for (var i=1; (i &lt;= nkids); i++) {
 populateTree(newbranch,Acl.eval("oid_child('" + oid + "'," + i + ")"));
 }
 branch.appendChild(newbranch);
}

// converts an oid to a valid XML name string
function oid_xmlname(oid) {
 var name = oid.replace("(","").replace(")","").replace(",",".").replace(",",".");
 return "_" + name;
}

 Conversion to ACL (if needed) is left as an exercise for the reader. 😉

1 reply

18-Opal
April 20, 2023

You will need to generate the <treenode> elements and append them to the <treecontrol> in your code. I don't have ACL code for this, but here's an example that uses Javascript to walk the doc structure recursively and build a tree:

// walks the document and creates a corresponding tree structure in the dialog
function populateTree(branch,oid) {
 var doc = branch.ownerDocument;
 var newbranch = doc.createElement("treenode");
 newbranch.setAttribute("label",Acl.eval("oid_name('" + oid + "')"));
 newbranch.setAttribute("appdata",oid);
 newbranch.setAttribute("id",oid_xmlname(oid));
 var nkids = Acl.eval("oid_children('" + oid + "')");
 for (var i=1; (i &lt;= nkids); i++) {
 populateTree(newbranch,Acl.eval("oid_child('" + oid + "'," + i + ")"));
 }
 branch.appendChild(newbranch);
}

// converts an oid to a valid XML name string
function oid_xmlname(oid) {
 var name = oid.replace("(","").replace(")","").replace(",",".").replace(",",".");
 return "_" + name;
}

 Conversion to ACL (if needed) is left as an exercise for the reader. 😉

dgopois13-AquamarineAuthor
13-Aquamarine
April 21, 2023

Hello,

Thanks for your response.

 

Maybe the code in the file "C:\Program Files\PTC\Arbortext Editor\packages\tools\_applicability_dlg.acl" can also help.

 

David