use of org.alfresco.web.ui.repo.component.UITree in project acs-community-packaging by Alfresco.
the class YahooTreeRenderer method encodeBegin.
@SuppressWarnings("unchecked")
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
// get the root nodes
UITree tree = (UITree) component;
List<TreeNode> rootNodes = tree.getRootNodes();
if (rootNodes != null && rootNodes.size() > 0) {
ResponseWriter out = context.getResponseWriter();
String treeContainerId = component.getClientId(context) + "Container";
// write out the JavaScript specific to the Tree component,
// make sure it's only done once
Object present = context.getExternalContext().getRequestMap().get(TREE_SCRIPTS_WRITTEN);
if (present == null) {
String reqPath = context.getExternalContext().getRequestContextPath();
out.write("<link rel=\"stylesheet\" href=\"");
out.write(reqPath);
out.write("/css/yahoo-tree.css\" type=\"text/css\">");
out.write("<script type=\"text/javascript\" src=\"");
out.write(reqPath);
out.write("/scripts/ajax/yahoo/treeview/treeview-min.js\"></script>");
out.write("<script type=\"text/javascript\" src=\"");
out.write(reqPath);
out.write("/scripts/ajax/yahoo-tree.js\"></script>");
context.getExternalContext().getRequestMap().put(TREE_SCRIPTS_WRITTEN, Boolean.TRUE);
}
// output the div container for the tree
out.write("<div id=\"");
out.write(treeContainerId);
out.write("\"></div>\n");
// generate the startup
out.write("<script type=\"text/javascript\">\n");
out.write("var tree;\n");
if (tree.getRetrieveChildrenUrl() != null) {
out.write("setLoadDataUrl('");
out.write(tree.getRetrieveChildrenUrl());
out.write("');\n");
}
if (tree.getNodeCollapsedUrl() != null) {
out.write("setCollapseUrl('");
out.write(tree.getNodeCollapsedUrl());
out.write("');\n");
}
if (tree.getNodeSelectedCallback() != null) {
out.write("setNodeSelectedHandler('");
out.write(tree.getNodeSelectedCallback());
out.write("');\n");
}
out.write("function initTree() {\n");
out.write(" tree = new YAHOO.widget.TreeView(\"");
out.write(treeContainerId);
out.write("\");\n");
out.write(" var root = tree.getRoot();\n");
if (tree.getNodeExpandedCallback() != null) {
out.write(" tree.subscribe('expand', ");
out.write(tree.getNodeExpandedCallback());
out.write(");\n");
}
if (tree.getNodeCollapsedCallback() != null) {
out.write(" tree.subscribe('collapse', ");
out.write(tree.getNodeCollapsedCallback());
out.write(");\n");
}
// generate script for each root node
this.nodeCounter = 0;
for (TreeNode node : rootNodes) {
generateNode(node, out, null);
}
out.write(" tree.draw();\n");
out.write(" tree.setDynamicLoad(loadDataForNode);\n}\n");
out.write("YAHOO.util.Event.on(window, \"load\", window.initTree);");
out.write("</script>\n");
} else if (logger.isDebugEnabled()) {
logger.debug("There weren't any nodes to render");
}
}
Aggregations