@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
UITreeNode node = (UITreeNode) component;
UITree root = node.findTree();
MixedTreeModel mixedModel = root.getModel();
mixedModel.onEncodeBegin();
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
String treeId = root.getClientId(facesContext);
DefaultMutableTreeNode modelNode = (DefaultMutableTreeNode) node.getValue();
boolean folder = mixedModel.isFolder();
boolean marked = node.isMarked();
String id = node.getClientId(facesContext);
boolean menuMode = root.getMode().equals("menu");
boolean showIcons = root.isShowIcons();
boolean showJunctions = root.isShowJunctions();
boolean showRootJunction = root.isShowRootJunction();
boolean showRoot = root.isShowRoot();
int depth = mixedModel.getDepth();
boolean isRoot = mixedModel.isRoot();
boolean expanded = node.isExpanded() || (isRoot && !showRoot);
boolean hasNextSibling = mixedModel.hasCurrentNodeNextSibling();
List<Boolean> junctions = mixedModel.getJunctions();
if (!showRoot && junctions.size() > 0) {
junctions.remove(0);
}
String source;
String openSource = null;
String closedSource;
String image = ComponentUtil.getStringAttribute(node, "image");
if (image != null) { // application image
closedSource = ResourceManagerUtil.getImageWithPath(facesContext, image);
} else { // theme image
closedSource = ResourceManagerUtil.getImageWithPath(facesContext, CLOSED_FOLDER);
}
if (folder) {
if (image != null) { // application image
openSource = ResourceManagerUtil.getImageWithPath(facesContext,
ResourceUtils.addPostfixToFilename(image, "open"), true);
} else { // theme image
openSource = ResourceManagerUtil.getImageWithPath(facesContext, OPEN_FOLDER);
}
source = expanded ? openSource : closedSource;
} else {
if (image != null) { // application image
source = ResourceManagerUtil.getImageWithPath(facesContext,
ResourceUtils.addPostfixToFilename(image, "leaf"), true);
} else { // theme image
source = ResourceManagerUtil.getImageWithPath(facesContext, LEAF);
}
if (source == null) {
source = closedSource;
}
}
CommandRendererHelper helper = new CommandRendererHelper(facesContext, node);
if (showRoot || !isRoot) {
writer.startElement(DIV, null);
// div id
writer.writeIdAttribute(id);
// div class (css)
StyleClasses styleClasses = StyleClasses.ensureStyleClasses(node);
styleClasses.updateClassAttributeAndMarkup(node, "treeNode");
if ("menu".equals(root.getMode())) {
styleClasses.addClass("treeNode", "menu");
if (marked) {
styleClasses.addClass("treeNode", "marker");
}
}
styleClasses.addMarkupClass(node, "treeNode");
writer.writeClassAttribute(styleClasses);
// div style (width)
Integer width = null;
HtmlStyleMap style = (HtmlStyleMap) root.getAttributes().get(ATTR_STYLE);
if (style != null) {
width = style.getInt("width");
}
String widthString;
if (width != null) {