String parentClientId = null;
if (parent != null && parent instanceof UITreeOldNode) { // if not the root node
parentClientId = treeNode.getParent().getClientId(facesContext);
}
UITreeOld root = treeNode.findTreeRoot();
String rootId = root.getClientId(facesContext);
String jsClientId = TreeOldRenderer.createJavascriptVariable(clientId);
String jsParentClientId = TreeOldRenderer.createJavascriptVariable(
parentClientId);
// rootId = HtmlUtils.createJavascriptVariable(rootId);
TreeState treeState = root.getState();
if (treeState == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No treeState found. clientId=" + clientId);
}
} else {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode.getValue();
ResponseWriter writer = facesContext.getResponseWriter();
String debuging = null;
writer.writeText(" var ", null);
writer.writeText(jsClientId, null);
writer.writeText(" = new TreeOldNode('", null);
// label
Object name = treeNode.getAttributes().get(TobagoConstants.ATTR_NAME);
if (LOG.isDebugEnabled()) {
debuging += name + " : ";
}
if (name != null) {
writer.writeText(StringEscapeUtils.escapeJavaScript(name.toString()), null);
} else {
LOG.warn("name = null");
}
writer.writeText("',", null);
// tip
Object tip = treeNode.getAttributes().get(TobagoConstants.ATTR_TIP);
if (tip != null) {
tip = StringEscapeUtils.escapeJavaScript(tip.toString());
writer.writeText("'", null);
writer.writeText((String) tip, null);
writer.writeText("','", null);
} else {
writer.writeText("null,'", null);
}
// id
writer.writeText(clientId, null);
writer.writeText("','", null);
writer.writeText(root.getMode(), null);
writer.writeText("',", null);
// is folder
writer.writeText(component.getChildCount() > 0, null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowIcons()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowJunctions()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowRootJunction()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowRoot()), null);
writer.writeText(",'", null);
writer.writeText(rootId, null);
writer.writeText("',", null);
String selectable = ComponentUtil.getStringAttribute(root,
TobagoConstants.ATTR_SELECTABLE);
if (selectable != null
&& (!(selectable.equals("multi") || selectable.equals("multiLeafOnly")
|| selectable.equals("single") || selectable.equals("singleLeafOnly")
|| selectable.equals("sibling") || selectable.equals("siblingLeafOnly")))) {
selectable = null;
}
if (selectable != null) {
writer.writeText("'", null);
writer.writeText(selectable, null);
writer.writeText("'", null);
} else {
writer.writeText("false", null);
}
writer.writeText(",", null);
writer.writeText(Boolean.toString(ComponentUtil.getBooleanAttribute(root,
TobagoConstants.ATTR_MUTABLE)), null);
writer.writeText(",'", null);
writer.writeText(
ComponentUtil.findPage(facesContext, component).getFormId(facesContext), null);
writer.writeText("',", null);
if (component.getChildCount() == 0
|| (selectable != null && !selectable.endsWith("LeafOnly"))) {
boolean selected = treeState.isSelected(node);
writer.writeText(Boolean.toString(selected), null);
if (LOG.isDebugEnabled()) {
debuging += selected ? "S" : "-";
}
} else {
writer.writeText("false", null);
if (LOG.isDebugEnabled()) {
debuging += "-";
}
if (treeState.isSelected(node)) {
LOG.warn("Ignore selected FolderNode in LeafOnly selection tree!");
}
}
writer.writeText(",", null);
writer.writeText(Boolean.toString(treeState.isMarked(node)), null);
writer.writeText(",", null);
// expanded
boolean expanded = treeState.isExpanded(node);
writer.writeText(Boolean.toString(expanded), null);
if (LOG.isDebugEnabled()) {
debuging += expanded ? "E" : "-";
}
writer.writeText(",", null);
// required
writer.writeText(Boolean.toString(root.isRequired()), null);
writer.writeText(",", null);
// disabled
writer.writeText(ComponentUtil.getBooleanAttribute(treeNode,
TobagoConstants.ATTR_DISABLED), null);
// resources
writer.writeText(",treeResourcesHelp", null);
writer.writeText(",", null);
// action (obsolete)
writer.writeText("null", null);
writer.writeText(",", null);
// onclick (treeNodeCommand)
String treeNodeCommandClientId = root.getClientId(facesContext);
String treeNodeCommandJsClientId = TreeOldRenderer.createJavascriptVariable(treeNodeCommandClientId);
writer.writeText(treeNodeCommandJsClientId + "_treeNodeCommand", null);
writer.writeText(",", null);
// parent
if (jsParentClientId != null) {
writer.writeText(jsParentClientId, null);
} else {
writer.writeText("null", null);
}
writer.writeText(",", null);
// icon (not implemented)
writer.writeText("null", null);
writer.writeText(",", null);
// open folder icon (not implemented)
writer.writeText("null", null);
writer.writeText(",'", null);
// width
Integer width = null;
HtmlStyleMap style = (HtmlStyleMap) root.getAttributes().get(ATTR_STYLE);
if (style != null) {
width = style.getInt("width");
}
if (width != null) {
writer.writeText(width - 4, null); // fixme: 4
} else {
writer.writeText("100%", null);
}
writer.writeText("',", null);
// tabIndex
if (root.getTabIndex() != null) {
writer.writeText(root.getTabIndex(), null);
} else {
writer.writeText("null", null);
}
writer.writeText(");\n", null);