code: protected void paintItem(final WTree tree, final WTree.ExpandMode mode, final TreeItemModel model, final List<Integer> rowIndex,
  			final XmlStringBuilder xml, final Set<String> selectedRows, final Set<String> expandedRows) {
  
  		String itemId = model.getItemId(rowIndex);
  
  		boolean selected = selectedRows.remove(itemId);
  
  		boolean expandable = model.isExpandable(rowIndex) && model.hasChildren(rowIndex);
  		boolean expanded = expandedRows.remove(itemId);
  
  		TreeItemImage image = model.getItemImage(rowIndex);
  		String url = null;
  		if (image != null) {
  			url = tree.getItemImageUrl(image, itemId);
  		}
  
  		xml.appendTagOpen("ui:treeitem");
  		xml.appendAttribute("id", tree.getItemIdPrefix() + itemId);
  		xml.appendAttribute("label", model.getItemLabel(rowIndex));
  		xml.appendOptionalUrlAttribute("imageUrl", url);
  		xml.appendOptionalAttribute("selected", selected, "true");
  		xml.appendOptionalAttribute("expandable", expandable, "true");
  		xml.appendOptionalAttribute("open", expandable && expanded, "true");
  		xml.appendClose();
  
  		if (expandable && (mode == WTree.ExpandMode.CLIENT || expanded)) {
  			// Get actual child count
  			int children = model.getChildCount(rowIndex);
  			if (children > 0) {
  				for (int i = 0; i < children; i++) {
  					// Add next level
  					List<Integer> nextRow = new ArrayList<>(rowIndex);
  					nextRow.add(i);
  					paintItem(tree, mode, model, nextRow, xml, selectedRows, expandedRows);
  				}
  			}
  
  		}
  
  		xml.appendEndTag("ui:treeitem");
  
  	}
docs: Iterate of over the rows to render the tree items.
  
  @param tree the WTree to render
  @param mode the expand mode
  @param model the tree model
  @param rowIndex the current row index
  @param xml the XML string builder
  @param selectedRows the set of selected rows
  @param expandedRows the set of expanded rows