content: /*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package com.github.adminfaces.showcase.bean;
  
  import com.github.adminfaces.showcase.service.DocumentService;
  import java.io.Serializable;
  import javax.annotation.PostConstruct;
  import javax.faces.application.FacesMessage;
  import javax.faces.context.FacesContext;
  import javax.inject.Inject;
  import javax.inject.Named;
  import org.omnifaces.cdi.ViewScoped;
  import org.primefaces.model.TreeNode;
  
  /**
   *
   * @author rmpestano
   */
  @Named
  @ViewScoped
  public class TreeMB implements Serializable {
  
      private TreeNode root;
  
      private TreeNode root2;
  
      private TreeNode selectedNode;
  
      private TreeNode[] selectedNodes;
  
      @Inject
      private DocumentService service;
  
      @PostConstruct
      public void init() {
          root = service.createDocuments();
          root2 = service.createDocuments();
      }
  
      public TreeNode getRoot() {
          return root;
      }
  
      public TreeNode getRoot2() {
          return root2;
      }
  
      public TreeNode getSelectedNode() {
          return selectedNode;
      }
  
      public void setSelectedNode(TreeNode selectedNode) {
          this.selectedNode = selectedNode;
      }
  
      public TreeNode[] getSelectedNodes() {
          return selectedNodes;
      }
  
      public void setSelectedNodes(TreeNode[] selectedNodes) {
          this.selectedNodes = selectedNodes;
      }
  
      public void setService(DocumentService service) {
          this.service = service;
      }
  
      public void displaySelectedSingle() {
          if (selectedNode != null) {
              FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", selectedNode.getData().toString());
              FacesContext.getCurrentInstance().addMessage(null, message);
          }
      }
  
      public void displaySelectedMultiple(TreeNode[] nodes) {
          if (nodes != null && nodes.length > 0) {
              StringBuilder builder = new StringBuilder();
  
              for (TreeNode node : nodes) {
                  builder.append(node.getData().toString());
                  builder.append("<br />");
              }
  
              FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", builder.toString());
              FacesContext.getCurrentInstance().addMessage(null, message);
          }
      }
  
  }
  