}
@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) {
widthString = "width: " + Integer.toString(width - 4); // fixme: 4
} else {
widthString = "100%";
}
writer.writeStyleAttribute(widthString);
if (folder) {
encodeExpandedHidden(writer, node, id, expanded);
}
if (folder && menuMode) {
encodeMenuIcon(facesContext, writer, treeId, id, expanded);
}
encodeIndent(facesContext, writer, menuMode, junctions);
encodeTreeJunction(facesContext, writer, id, treeId, showJunctions, showRootJunction, showRoot, expanded,
folder, depth, hasNextSibling, openSource, closedSource);
encodeTreeIcons(writer, id, treeId, showIcons, folder, source, openSource, closedSource);
encodeLabel(writer, helper, node, marked, treeId);
UIComponent facet = node.getFacet("addendum");
if (facet != null) {
RenderUtil.encode(facesContext, facet);
}
writer.endElement(DIV);
}
if (folder) {
String contentStyle = "display: " + (expanded ? "block" : "none") + ";";
writer.startElement(DIV, null);
writer.writeIdAttribute(id + "-cont");
writer.writeStyleAttribute(contentStyle);
}
if (LOG.isDebugEnabled()) {
String label = (String) node.getAttributes().get(ATTR_LABEL);
int level = modelNode.getLevel();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < level; i++) {
builder.append(" ");
}