Search in sources :

Example 1 with CategoryBrowserPluginBean

use of org.alfresco.web.bean.ajax.CategoryBrowserPluginBean 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)

Aggregations

ResponseWriter (javax.faces.context.ResponseWriter)1 CategoryBrowserBean (org.alfresco.web.bean.CategoryBrowserBean)1 CategoryBrowserPluginBean (org.alfresco.web.bean.ajax.CategoryBrowserPluginBean)1 QuickSort (org.alfresco.web.data.QuickSort)1 TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)1