Package org.primefaces.model

Examples of org.primefaces.model.TreeNode


    String selectionParam = clientId + "_selection";
   
    if(params.containsKey(clientId) && params.containsKey(rowKeyParam) && params.containsKey(actionParam)) {
      String rowKey = params.get(rowKeyParam);
      String event = params.get(actionParam);
      TreeNode root = (TreeNode) tree.getValue();
      TreeNode currentNode = treeExplorer.findTreeNode(rowKey, new TreeModel(root));
     
      switch(TreeNodeEvent.valueOf(event)) {
        case SELECT:
          tree.queueEvent(new NodeSelectEvent(tree, currentNode));
        break;
       
        case EXPAND:
          currentNode.setExpanded(true);
          tree.queueEvent(new NodeExpandEvent(tree, currentNode));
        break;

        case COLLAPSE:
          currentNode.setExpanded(false);
          tree.queueEvent(new NodeCollapseEvent(tree, currentNode));
        break;
      }
    }
   
    //Selection
    if(params.containsKey(selectionParam)) {
      String selectedNodesValue = params.get(selectionParam);
      boolean isSingle = tree.getSelectionMode().equalsIgnoreCase("single");
     
      if(selectedNodesValue.equals("")) {
        if(isSingle)
          tree.setSelection(null);
        else
          tree.setSelection(new TreeNode[0]);
      }
      else {
        String[] selectedRowKeys = selectedNodesValue.split(",");
        TreeModel model = new TreeModel((TreeNode) tree.getValue());
       
        if(isSingle) {
          TreeNode selectedNode = treeExplorer.findTreeNode(selectedRowKeys[0], model);
          tree.setSelection(selectedNode);
         
        } else {
          TreeNode[] selectedNodes = new TreeNode[selectedRowKeys.length];
View Full Code Here


  public void encodePartially(FacesContext facesContext, UIComponent component) throws IOException {
    Tree tree = (Tree) component;
    ResponseWriter writer = facesContext.getResponseWriter();
    Map<String,String> params = facesContext.getExternalContext().getRequestParameterMap();
    String clientId = tree.getClientId(facesContext);
    TreeNode root = (TreeNode) tree.getValue();
   
    String rowKey = params.get(clientId + "_rowKey");
    TreeNode currentNode = treeExplorer.findTreeNode(rowKey, new TreeModel(root));
    int rowIndex = 0;
   
    ServletResponse response = (ServletResponse) facesContext.getExternalContext().getResponse();
    response.setContentType("text/xml");
   
    writer.write("<?xml version=\"1.0\" encoding=\"" + response.getCharacterEncoding() + "\"?>");
    writer.write("<nodes>");
   
    for(Iterator<TreeNode> iterator = currentNode.getChildren().iterator(); iterator.hasNext();) {
      TreeNode child = iterator.next();
      UITreeNode uiTreeNode = tree.getUITreeNodeByType(child.getType());
     
      facesContext.getExternalContext().getRequestMap().put(tree.getVar(), child.getData());
      writer.write("<node>");
     
        writer.write("<content>");
        writer.startCDATA();
        renderChildren(facesContext, uiTreeNode);
        writer.endCDATA();
        writer.write("</content>");
       
        writer.write("<rowKey>" + rowKey + "." + rowIndex + "</rowKey>");
        writer.write("<isLeaf>" + child.isLeaf() + "</isLeaf>");
        if(uiTreeNode.getStyleClass() != null) {
          writer.write("<contentClass>" + uiTreeNode.getStyleClass() + "</contentClass>");
        }
      writer.write("</node>");
     
View Full Code Here

  protected void encodeScript(FacesContext facesContext, Tree tree) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = tree.getClientId(facesContext);
    String formClientId = null;
    String treeVar = createUniqueWidgetVar(facesContext, tree);
    TreeNode root = (TreeNode) tree.getValue();
   
    UIComponent parentForm = ComponentUtils.findParentForm(facesContext, tree);
    if(parentForm != null)
      formClientId = parentForm.getClientId(facesContext);
    else
      throw new FacesException("Tree:" + clientId + " needs to be enclosed in a form");
     
    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);

    //Nodes
    writer.write(treeVar + " = new PrimeFaces.widget.TreeView('" + clientId + "', [\n");
    if(root != null) {
      int rowIndex = 0;
      for(Iterator<TreeNode> iterator = root.getChildren().iterator(); iterator.hasNext();) {
        encodeTreeNode(facesContext, tree, iterator.next(), String.valueOf(rowIndex));
        rowIndex ++;
       
        if(iterator.hasNext())
          writer.write(",");
View Full Code Here

    writer.endElement("thead");
  }
 
  protected void encodeRows(FacesContext facesContext, TreeTable treeTable) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    TreeNode root = (TreeNode) treeTable.getValue();
    String clientId = treeTable.getEscapedClientId(facesContext);
    int rowKey = 0;
   
    writer.startElement("tbody", null);
    writer.writeAttribute("class", TreeTable.DATA_CLASS, null);
   
    if(root != null) {
      for(Iterator<TreeNode> iterator = root.getChildren().iterator(); iterator.hasNext();) {
        encodeTreeNode(facesContext, treeTable, iterator.next(), clientId, String.valueOf(rowKey), null);
        rowKey++;
      }
    }
   
View Full Code Here

    @Mocked DataTable groupsDataTable;


    @Test
    public void testLoadNamespace() throws Exception {
        final TreeNode newContent = new DefaultTreeNode();
        newContent.setSelected(false);
        final TreeNode selectedNode = new DefaultTreeNode();
        selectedNode.setSelected(true);
        final List<Content> contentList = new ArrayList<Content>();
        contentList.add(new Content());
        new NonStrictExpectations() {{
            facesContext.getPartialViewContext(); result = partialViewContext;
            partialViewContext.isAjaxRequest(); result = false;
            theTree.getContentHolder(); result = contentHolder;
            contentHolder.find(new ContentKey(null, "namespace", "namespace")); result = newContent;
            theTree.getSelectedNode(); result = selectedNode;
            pageContent.getNamespace(); result = Namespace.createFromString("net.tralfamadore");
            pageContent.getNamespaceContents(); result = new Vector<BaseContent>();
            theTree.getContentManager(); result = contentManager;
            contentManager.loadContent((Namespace)any); result = contentList;
        }};
        pageContent.setNamespaceContents(new ArrayList<BaseContent>());
        adminController.setIncomingNamespace("namespace");
        adminController.pageContent = new PageContent();
        adminController.pageContent.setTheContent(Namespace.createFromString("net.tralfamadore"));
        adminController.loadNamespace();

        assertTrue(newContent.isSelected());
        assertFalse(selectedNode.isSelected());

        assertEquals(1, pageContent.getNamespaceContents().size());
    }
View Full Code Here

        assertEquals(1, pageContent.getNamespaceContents().size());
    }

    @Test
    public void testLoadTopLevelNamespace() throws Exception {
        final TreeNode newContent = new DefaultTreeNode();
        newContent.setSelected(false);
        final TreeNode selectedNode = new DefaultTreeNode();
        selectedNode.setSelected(true);
        final List<Content> contentList = new ArrayList<Content>();
        contentList.add(new Content());
        new NonStrictExpectations() {{
            facesContext.getPartialViewContext(); result = partialViewContext;
            partialViewContext.isAjaxRequest(); result = false;
            theTree.getContentHolder(); result = contentHolder;
            contentHolder.find(new ContentKey(null, "namespace", "namespace")); result = newContent;
            theTree.getSelectedNode(); result = selectedNode;
            pageContent.getNamespace(); result = Namespace.createFromString("net");
            pageContent.getNamespaceContents(); result = new Vector<BaseContent>();
            theTree.getContentManager(); result = contentManager;
            contentManager.loadContent((Namespace) any); result = contentList;
            contentManager.loadChildNamespaces((Namespace) any); result = Collections.emptyList();
        }};
        pageContent.setNamespaceContents(new ArrayList<BaseContent>());
        adminController.setIncomingNamespace("namespace");
        adminController.pageContent = new PageContent();
        adminController.pageContent.setTheContent(Namespace.createFromString("net"));
        adminController.loadNamespace();

        assertTrue(newContent.isSelected());
        assertFalse(selectedNode.isSelected());

        assertEquals(2, pageContent.getNamespaceContents().size());
    }
View Full Code Here

        assertEquals(2, pageContent.getNamespaceContents().size());
    }

    @Test
    public void testLoadContent() throws Exception {
        final TreeNode newContent = new DefaultTreeNode();
        newContent.setSelected(false);
        final TreeNode selectedNode = new DefaultTreeNode();
        selectedNode.setSelected(true);
        new NonStrictExpectations() {{
            facesContext.getPartialViewContext(); result = partialViewContext;
            partialViewContext.isAjaxRequest(); result = false;
            theTree.getContentHolder(); result = contentHolder;
            contentHolder.find(new ContentKey("content", "namespace", "content")); result = newContent;
            theTree.getSelectedNode(); result = selectedNode;
        }};
        adminController.setIncomingContentName("content");
        adminController.setIncomingNamespace("namespace");
        adminController.loadContent();
        assertTrue(newContent.isSelected());
        assertFalse(selectedNode.isSelected());
    }
View Full Code Here

        }};
    }

    @Test
    public void testLoadStyle() throws Exception {
        final TreeNode newContent = new DefaultTreeNode();
        newContent.setSelected(false);
        final TreeNode selectedNode = new DefaultTreeNode();
        selectedNode.setSelected(true);
        new NonStrictExpectations() {{
            facesContext.getPartialViewContext(); result = partialViewContext;
            partialViewContext.isAjaxRequest(); result = false;
            theTree.getContentHolder(); result = contentHolder;
            contentHolder.find(new ContentKey("style", "namespace", "style")); result = newContent;
            theTree.getSelectedNode(); result = selectedNode;
        }};
        adminController.setIncomingContentName("style");
        adminController.setIncomingNamespace("namespace");
        adminController.loadStyle();
        assertTrue(newContent.isSelected());
        assertFalse(selectedNode.isSelected());
    }
View Full Code Here

    }

    @SuppressWarnings({"unchecked"})
    @Test
    public void testFetchNamespaceContents() throws Exception {
        final TreeNode newContent = new DefaultTreeNode();
        newContent.setSelected(false);
        final TreeNode selectedNode = new DefaultTreeNode();
        selectedNode.setSelected(true);
        final List<Content> contentList = new ArrayList<Content>();
        contentList.add(new Content());
        new NonStrictExpectations() {
            Namespace namespace;
            List<BaseContent> namespaceContents;
            {
                facesContext.getPartialViewContext(); result = partialViewContext;
                partialViewContext.isAjaxRequest(); result = false;
                theTree.getContentHolder(); result = contentHolder;
                contentHolder.find(new ContentKey(null, "namespace", "namespace")); result = newContent;
                newContent.getData(); result = namespace;
                selectedNode.getData(); result = namespace;
                theTree.getSelectedNode(); result = selectedNode;
                pageContent.getNamespaceContents(); result = new Vector<BaseContent>();
                theTree.getContentManager(); result = contentManager;
                contentManager.loadContent((Namespace)any); result = contentList;
View Full Code Here

        defaultGroupPermissionsList.add(groupPermissions);
        return defaultGroupPermissionsList;
    }

    private void loadPage(String type) {
        TreeNode selectedNode = theTree.getSelectedNode();
        TreeNode newContent =  "namespace".equals(type) ?
                contentHolder.find(new ContentKey(null, incomingNamespace, "namespace")) :
                contentHolder.find(new ContentKey(incomingContentName, incomingNamespace, type));

        if(newContent == null) {
            showLoadError(type);
            return;
        }

        newContent.setSelected(true);

        if(selectedNode != null)
            selectedNode.setSelected(false);

        theTree.setSelectedNode(newContent);
        pageContent.setTheContent((BaseContent) newContent.getData());
        theTree.createTreeModel();
    }
View Full Code Here

TOP

Related Classes of org.primefaces.model.TreeNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.