Search in sources :

Example 11 with TreeNode

use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.

the class CategoryBrowserPluginBean method nodeCollapsed.

/**
 * Sets the state of the node given in the 'nodeRef' parameter to collapsed
 */
public void nodeCollapsed() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    Map params = context.getExternalContext().getRequestParameterMap();
    String nodeRefStr = (String) params.get("nodeRef");
    // work out which list to cache the nodes in
    Map<String, TreeNode> currentNodes = getNodesMap();
    if (nodeRefStr != null && currentNodes != null) {
        TreeNode treeNode = currentNodes.get(nodeRefStr);
        if (treeNode != null) {
            treeNode.setExpanded(false);
            // we need to return something for the client to be happy!
            out.write("<ok/>");
            if (logger.isDebugEnabled())
                logger.debug("Set node " + treeNode + " to collapsed state");
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with TreeNode

use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.

the class YahooTreeRenderer method generateNode.

/**
 * Generates the JavaScript required to create the branch of a tree from
 * the given node.
 *
 * @param node The node to generate
 * @param out Response writer
 * @param parentVarName Name of the parent variable, null if the node has no parent
 */
protected void generateNode(TreeNode node, ResponseWriter out, String parentVarName) throws IOException {
    String currentVarName = getNextVarName();
    // generate the Javascript to create the given node using the
    // appropriate parent variable
    out.write("      var ");
    out.write(currentVarName);
    out.write(" = createYahooTreeNode(");
    if (node.getParent() == null) {
        out.write("root");
    } else {
        out.write(parentVarName);
    }
    out.write(", \"");
    out.write(node.getNodeRef());
    out.write("\", \"");
    out.write(node.getName());
    out.write("\", \"");
    out.write(node.getIcon());
    out.write("\", ");
    out.write(Boolean.toString(node.isExpanded()));
    out.write(", ");
    out.write(Boolean.toString(node.isSelected()));
    out.write(");\n");
    // iterate through the child nodes and generate them
    if (node.isExpanded() && node.getChildren().size() > 0) {
        // order the children
        List<TreeNode> children = node.getChildren();
        if (children.size() > 1) {
            QuickSort sorter = new QuickSort(children, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
            sorter.sort();
        }
        for (TreeNode child : children) {
            generateNode(child, out, currentVarName);
        }
    }
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode)

Aggregations

TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)12 ResponseWriter (javax.faces.context.ResponseWriter)7 IOException (java.io.IOException)6 UserTransaction (javax.transaction.UserTransaction)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 FacesContext (javax.faces.context.FacesContext)5 QuickSort (org.alfresco.web.data.QuickSort)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)2 NavigationBean (org.alfresco.web.bean.NavigationBean)2 CategoryBrowserBean (org.alfresco.web.bean.CategoryBrowserBean)1 CategoryBrowserPluginBean (org.alfresco.web.bean.ajax.CategoryBrowserPluginBean)1 NavigatorPluginBean (org.alfresco.web.bean.ajax.NavigatorPluginBean)1 UITree (org.alfresco.web.ui.repo.component.UITree)1