String itemImageValueStyle = " " + style.cellTreeItemImageValue();
String openStyle = " " + style.cellTreeOpenItem();
String topStyle = " " + style.cellTreeTopItem();
String topImageValueStyle = " " + style.cellTreeTopItemImageValue();
boolean isRootNode = nodeView.isRootNode();
SafeHtml openImage = nodeView.tree.getOpenImageHtml(isRootNode);
SafeHtml closedImage = nodeView.tree.getClosedImageHtml(isRootNode);
int imageWidth = nodeView.tree.getImageWidth();
String paddingDirection = LocaleInfo.getCurrentLocale().isRTL() ? "right" : "left";
int paddingAmount = imageWidth * nodeView.depth;
// Create a set of currently open nodes.
Set<Object> openNodes = new HashSet<Object>();
int childCount = nodeView.getChildCount();
int end = start + values.size();
for (int i = start; i < end && i < childCount; i++) {
CellTreeNodeView<?> child = nodeView.getChildNode(i);
// Ignore child nodes that are closed.
if (child.isOpen()) {
openNodes.add(child.getValueKey());
}
}
// Render the child nodes.
ProvidesKey<C> keyProvider = nodeInfo.getProvidesKey();
TreeViewModel model = nodeView.tree.getTreeViewModel();
for (int i = start; i < end; i++) {
C value = values.get(i - start);
Object key = keyProvider.getKey(value);
boolean isOpen = openNodes.contains(key);
// Outer div contains image, value, and children (when open)
StringBuilder outerClasses = new StringBuilder(itemStyle);
if (isOpen) {
outerClasses.append(openStyle);
}
if (isRootNode) {
outerClasses.append(topStyle);
}
boolean isSelected = (selectionModel != null && selectionModel.isSelected(value));
String ariaSelected = String.valueOf(isSelected);
if (isSelected) {
outerClasses.append(selectedStyle);
}
// Inner div contains image and value
StringBuilder innerClasses = new StringBuilder(itemStyle);
innerClasses.append(itemImageValueStyle);
if (isRootNode) {
innerClasses.append(topImageValueStyle);
}
// Add the open/close icon.
SafeHtml image;
if (isOpen) {
image = openImage;
} else if (model.isLeaf(value)) {
image = LEAF_IMAGE;
} else {
image = closedImage;
}
// Render cell contents
SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
Context context = new Context(i, 0, key);
cell.render(context, value, cellBuilder);
SafeStyles innerPadding =
SafeStylesUtils.fromTrustedString("padding-" + paddingDirection + ": " + imageWidth
+ "px;");
SafeHtml innerDiv =
template.innerDiv(innerPadding, innerClasses.toString(), image, itemValueStyle,
cellBuilder.toSafeHtml());
SafeStyles outerPadding =
SafeStylesUtils.fromTrustedString("padding-" + paddingDirection + ": "
+ paddingAmount + "px;");