getWidget().body.clear();
// clear out any references to nodes that no longer are attached
getWidget().clearNodeToKeyMap();
tooltipMap.clear();
TreeNode childTree = null;
UIDL childUidl = null;
for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
childUidl = (UIDL) i.next();
if ("actions".equals(childUidl.getTag())) {
updateActionMap(childUidl);
continue;
} else if ("-ac".equals(childUidl.getTag())) {
getWidget().updateDropHandler(childUidl);
continue;
}
childTree = getWidget().new TreeNode();
getConnection().getVTooltip().connectHandlersToWidget(childTree);
updateNodeFromUIDL(childTree, childUidl, 1);
getWidget().body.add(childTree);
childTree.addStyleDependentName("root");
childTree.childNodeContainer.addStyleDependentName("root");
}
if (childTree != null && childUidl != null) {
boolean leaf = !childUidl.getTag().equals("node");
childTree.addStyleDependentName(leaf ? "leaf-last" : "last");
childTree.childNodeContainer.addStyleDependentName("last");
}
final String selectMode = uidl.getStringAttribute("selectmode");
getWidget().selectable = !"none".equals(selectMode);
getWidget().isMultiselect = "multi".equals(selectMode);
if (getWidget().isMultiselect) {
Roles.getTreeRole().setAriaMultiselectableProperty(
getWidget().getElement(), true);
if (BrowserInfo.get().isTouchDevice()) {
// Always use the simple mode for touch devices that do not have
// shift/ctrl keys (#8595)
getWidget().multiSelectMode = MultiSelectMode.SIMPLE;
} else {
getWidget().multiSelectMode = MultiSelectMode.valueOf(uidl
.getStringAttribute("multiselectmode"));
}
} else {
Roles.getTreeRole().setAriaMultiselectableProperty(
getWidget().getElement(), false);
}
getWidget().selectedIds = uidl.getStringArrayVariableAsSet("selected");
// Update lastSelection and focusedNode to point to *actual* nodes again
// after the old ones have been cleared from the body. This fixes focus
// and keyboard navigation issues as described in #7057 and other
// tickets.
if (getWidget().lastSelection != null) {
getWidget().lastSelection = getWidget().getNodeByKey(
getWidget().lastSelection.key);
}
if (getWidget().focusedNode != null) {
Set<String> selectedIds = getWidget().selectedIds;
// If the focused node is not between the selected nodes, we need to
// refresh the focused node to prevent an undesired scroll. #12618.
if (!selectedIds.isEmpty()
&& !selectedIds.contains(getWidget().focusedNode.key)) {
String keySelectedId = selectedIds.iterator().next();
TreeNode nodeToSelect = getWidget().getNodeByKey(keySelectedId);
getWidget().setFocusedNode(nodeToSelect);
} else {
getWidget().setFocusedNode(
getWidget().getNodeByKey(getWidget().focusedNode.key));