How to make the edit window get focus after user selection of XUI tree node

Nice teamwork by Mark Padilla, Rob In der Maur, Clay Helberg, and Tung Fu Last Updated: 2006-06-18

The desired effect is that the user selects a node from the tree, the editor window navigates to the selected element and the cursor is left in the element so the user can start typing without any additional navigation/focus keystrokes.

JavaScript XUI dialog code:

var sectionTree = xuidoc.getElementById("epspec_sections"); function handletreeSelect(e) { // get selected tree node sel = xuidoc.getElementById("epspec_sections").getElementsByAttribute("selected", "true", 1); if (sel.length > 0) { targetnode = actdoc.getElementsByAttribute("id", sel.item(0).getAttribute("appdata"), 1).item(0); if (targetnode != null) { if (targetnode.getNodeName == "bp_instructions") { targetnode = targetnode.getElementsByTagName("enter_response").item(0); }      Acl.execute("goto_oid('"+targetnode.firstOID+"');"); Acl.execute("epspec_func::focusEdit"); }  }   e.stopPropagation; }

ACL code (note the timer callback, which works around a feature):

package epspec_func; function timer_cb { local win = current_window; local i, arr[]; local count = window_list(arr, 'edit', current_window); for (i = 1; i <= count; i++) { if (window_get(arr[i], 'docmapview') == 0) { win = arr[i]; break; }  }   window_activate(win); return 0; # cancel the timer } function focusEdit { timer_add_callback(1, 'timer_cb'); }