Search in sources :

Example 6 with TreeNode

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

the class UICategoryBrowser method encodeBegin.

/*
    * (non-Javadoc)
    * 
    * @see org.alfresco.web.ui.repo.component.UINavigator#encodeBegin(javax.faces.context.FacesContext)
    */
@Override
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    // TODO: pull width and height from user preferences and/or the main config,
    // if present override below using the style attribute
    ResponseWriter out = context.getResponseWriter();
    CategoryBrowserPluginBean categoryBrowserPluginBean = (CategoryBrowserPluginBean) FacesHelper.getManagedBean(context, CategoryBrowserPluginBean.BEAN_NAME);
    CategoryBrowserBean categoryBrowserBean = (CategoryBrowserBean) FacesHelper.getManagedBean(context, CategoryBrowserBean.BEAN_NAME);
    List<TreeNode> rootNodes = null;
    rootNodes = categoryBrowserPluginBean.getCategoryRootNodes();
    // order the root nodes by the tree label
    if (rootNodes != null && rootNodes.size() > 1) {
        QuickSort sorter = new QuickSort(rootNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    // main container div
    out.write("<div id=\"category-navigator\" class=\"navigator\">");
    // Subcategories parameter
    String includeSub = Application.getMessage(context, "category_browser_plugin_include_subcategories");
    out.write("<input type='checkbox' id='" + SUBCATEGORIES_PARAM + "' name='" + SUBCATEGORIES_PARAM + "' value=1 " + (categoryBrowserBean.isIncludeSubcategories() ? "checked" : "") + "/>");
    out.write("<label for='" + SUBCATEGORIES_PARAM + "'>" + includeSub + "</label>");
    // generate the javascript method to capture the tree node click events
    out.write("<script type=\"text/javascript\">");
    out.write("function treeNodeSelected(nodeRef) {");
    out.write(Utils.generateFormSubmit(context, this, getClientId(context), "nodeRef", true, null));
    out.write("}</script>");
    // generate the active panel containing the tree
    out.write("<div class=\"navigatorPanelBody\">");
    UITree tree = (UITree) context.getApplication().createComponent(UITree.COMPONENT_TYPE);
    tree.setId("tree");
    tree.setRootNodes(rootNodes);
    tree.setRetrieveChildrenUrl(AJAX_URL_START + ".retrieveChildren?");
    tree.setNodeCollapsedUrl(AJAX_URL_START + ".nodeCollapsed?");
    tree.setNodeSelectedCallback("treeNodeSelected");
    tree.setNodeCollapsedCallback("informOfCollapse");
    Utils.encodeRecursive(context, tree);
    out.write("</div>");
    out.write("</div>");
}
Also used : CategoryBrowserPluginBean(org.alfresco.web.bean.ajax.CategoryBrowserPluginBean) QuickSort(org.alfresco.web.data.QuickSort) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) CategoryBrowserBean(org.alfresco.web.bean.CategoryBrowserBean)

Example 7 with TreeNode

use of org.alfresco.web.ui.repo.component.UITree.TreeNode 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");
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) UITree(org.alfresco.web.ui.repo.component.UITree)

Example 8 with TreeNode

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

the class NavigatorPluginBean method getCompanyHomeRootNodes.

// ------------------------------------------------------------------------------
// Bean getters and setters
/**
 * Returns the root nodes for the company home panel.
 * <p>
 * As the user expands and collapses nodes in the client this
 * cache will be updated with the appropriate nodes and states.
 * </p>
 *
 * @return List of root nodes for the company home panel
 */
public List<TreeNode> getCompanyHomeRootNodes() {
    if (this.companyHomeRootNodes == null) {
        this.companyHomeRootNodes = new ArrayList<TreeNode>();
        this.companyHomeNodes = new HashMap<String, TreeNode>();
        UserTransaction tx = null;
        try {
            FacesContext fc = FacesContext.getCurrentInstance();
            tx = Repository.getUserTransaction(fc, true);
            tx.begin();
            // query for the child nodes of company home
            NodeRef root = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
            List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(root, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            for (ChildAssociationRef ref : childRefs) {
                NodeRef child = ref.getChildRef();
                if (isAddableChild(child)) {
                    TreeNode node = createTreeNode(child);
                    this.companyHomeRootNodes.add(node);
                    this.companyHomeNodes.put(node.getNodeRef(), node);
                }
            }
            tx.commit();
        } catch (Throwable err) {
            Utils.addErrorMessage("NavigatorPluginBean exception in getCompanyHomeRootNodes()", err);
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    return this.companyHomeRootNodes;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) IOException(java.io.IOException)

Example 9 with TreeNode

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

the class NavigatorPluginBean method retrieveChildren.

// ------------------------------------------------------------------------------
// AJAX handler methods
/**
 * Retrieves the child folders for the noderef given in the
 * 'noderef' parameter and caches the nodes against the area in
 * the 'area' parameter.
 */
public void retrieveChildren() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        Map params = context.getExternalContext().getRequestParameterMap();
        String nodeRefStr = (String) params.get("nodeRef");
        String area = (String) params.get("area");
        if (logger.isDebugEnabled())
            logger.debug("retrieveChildren: area = " + area + ", nodeRef = " + nodeRefStr);
        // work out which list to cache the nodes in
        Map<String, TreeNode> currentNodes = getNodesMapForArea(area);
        if (nodeRefStr != null && currentNodes != null) {
            // get the given node's details
            NodeRef parentNodeRef = new NodeRef(nodeRefStr);
            TreeNode parentNode = currentNodes.get(parentNodeRef.toString());
            parentNode.setExpanded(true);
            if (logger.isDebugEnabled())
                logger.debug("retrieving children for noderef: " + parentNodeRef);
            // remove any existing children as the latest ones will be added below
            parentNode.removeChildren();
            // get all the child folder objects for the parent
            List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            List<TreeNode> sortedNodes = new ArrayList<TreeNode>();
            for (ChildAssociationRef ref : childRefs) {
                NodeRef nodeRef = ref.getChildRef();
                if (isAddableChild(nodeRef)) {
                    // build the XML representation of the child node
                    TreeNode childNode = createTreeNode(nodeRef);
                    parentNode.addChild(childNode);
                    currentNodes.put(childNode.getNodeRef(), childNode);
                    sortedNodes.add(childNode);
                }
            }
            // order the tree nodes by the tree label
            if (sortedNodes.size() > 1) {
                QuickSort sorter = new QuickSort(sortedNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            }
            // generate the XML representation
            StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><nodes>");
            for (TreeNode childNode : sortedNodes) {
                xml.append(childNode.toXML());
            }
            xml.append("</nodes>");
            // send the generated XML back to the tree
            out.write(xml.toString());
            if (logger.isDebugEnabled())
                logger.debug("returning XML: " + xml.toString());
        }
        // commit the transaction
        tx.commit();
    } catch (Throwable err) {
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickSort(org.alfresco.web.data.QuickSort) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with TreeNode

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

the class NavigatorPluginBean method getGuestHomeRootNodes.

/**
 * Returns the root nodes for the guest home panel.
 * <p>
 * As the user expands and collapses nodes in the client this
 * cache will be updated with the appropriate nodes and states.
 * </p>
 *
 * @return List of root nodes for the guest home panel
 */
public List<TreeNode> getGuestHomeRootNodes() {
    if (this.guestHomeRootNodes == null) {
        this.guestHomeRootNodes = new ArrayList<TreeNode>();
        this.guestHomeNodes = new HashMap<String, TreeNode>();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
            tx.begin();
            // query for the child nodes of the guest home space
            NavigationBean navBean = getNavigationBean();
            if (navBean != null) {
                NodeRef root = navBean.getGuestHomeNode().getNodeRef();
                List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(root, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
                for (ChildAssociationRef ref : childRefs) {
                    NodeRef child = ref.getChildRef();
                    if (isAddableChild(child)) {
                        TreeNode node = createTreeNode(child);
                        this.guestHomeRootNodes.add(node);
                        this.guestHomeNodes.put(node.getNodeRef(), node);
                    }
                }
            }
            tx.commit();
        } catch (Throwable err) {
            Utils.addErrorMessage("NavigatorPluginBean exception in getGuestHomeRootNodes()", err);
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    return this.guestHomeRootNodes;
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) IOException(java.io.IOException)

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