Tree2 -

Olá pessoal,

Estou utilizando o componente Tree2 em um projeto. Estou carregando os nós da árvore com os objetos de um arquivo xml.

Está tudo dando certo, mas quando utilizo xmls muito grandes estou tendo problemas com estouro de memória.

Preciso de uma maneira de não carregar toda a árvore de uma só vez e sim por partes.

Segue o código:

public class CatalogoBean {
	
	private String nome;
	private String tipo;
	private String caminhoXml;

	private TreeNode treeData;

	public String getNome(){
		return nome;
	}
	
	public String getTipo(){
		return tipo;
	}
	public TreeNode getTreeData(){
		return treeData;
	}
	public void setTreeData(TreeNode paramTreeData){
		treeData = paramTreeData;
	}
	
	public void setNome(String paramNome){
		nome = paramNome;
	}

	public void setTipo(String paramTipo){
		tipo = paramTipo;
	}
	public String getCaminhoXml(){
		return caminhoXml;
	}
	
	public void setCaminhoXml(String anycaminhoXml){
		caminhoXml = anycaminhoXml;
	}
	
		
     /**
       * Método que obtém o caminho do xml
       */
	public String visualizar(){

		    String resultado="falha";
		   File hbXmlFile = new File(caminhoXml);
		   if(hbXmlFile.exists()){
		    createH(hbXmlFile);

			resultado="sucesso";
		   }
		   else
			   resultado="falha";
			
		   return resultado;	
	}	


     /**
	   * Método que faz o parse do xml dado como parametro e chama o método apresentaCatalogo
	   * 
	   */
	public CatalogoSistemaDocument createH(File f){
	
			//cria uma variável CatalogoSistemaDocument para receber o arquivo xml
			CatalogoSistemaDocument pod = null;

			try{
				pod	= CatalogoSistemaDocument.Factory.parse(f);
			}catch(XmlException e){
			e.printStackTrace();
			}catch(IOException e){
			e.printStackTrace();			
			}
			treeData = new LazyTreeNodeBase("foo-folder", "Catalogo", false);
		
			apresentaCatalogo(f, pod.getCatalogoSistema().getElementos(),null);
			
			return pod;
	}
	
			
    /**
	  * Método que apresenta, de maneira flat, os campos presentes na hierarquia
	  * de um catálogo criado. A análise é realizada de maneira recursiva.
	  */
	public void apresentaCatalogo (File f, Elementos elementosLoop,TreeNodeBase noPai){
			
			int i=0;
			
			
			// cria uma instância de Elemento na qual é atribuída a raiz do documento
			Elemento elemArray[] = elementosLoop.getElementoArray();
	

			//percorrendo todos os <elemento> (internos) filhos que existem no elemento raiz
	
			for (i=0; i<elemArray.length; i++) {
				


		   	//coletando uma possível classe sendo representada pelo elemento sendo analisado.

							
				if(elemArray[i].getElementos() != null){
			
					TreeNodeBase authorNode = new TreeNodeBase ("declaracao", elemArray[i].getNome(), false);
			 		treeData.getChildren().add(authorNode);
		
			   		
                                      //desce na hierarquia para a apresentação dos atributos folha.
			 		apresentaCatalogo(f, elemArray[i].getElementos(),authorNode);		


				}
				else {

					//coleta o elemento filho e apresenta como filho
					TreeNodeBase noFilho= new TreeNodeBase ("document", elemArray[i].getNome(), false);
					noPai.getChildren().add(noFilho);

				}

			
			}
	}
}

Esta é a página que faz a apresentação da árvore.

<%@ page contentType="text/html; charset=Cp1252" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
 
<f:view>
 <html>
	
	<head>
		<meta http-equiv="Content-Type"
			content="text/html;charset=windows-1252"/>
		<title>CatalogoTree</title>
	</head>
  
  <body>
   <h:form>
		
	<t:tree2 id="serverTree"
			value="#{CatalogoBean.treeData}"
			
			var="node" varNodeToggler="t" preserveToggle="true" clientSideToggle="false">
		
		<f:facet name="document">
		<h:panelGroup>
			
				<t:graphicImage value="/images/document.png" border="0"/>
				
				<h:outputText onclick="true" rendered="true" value="#{node.description}"/>
				<h:outputText onclick="true" value="(#{node.childCount})" styleClass="childCount" />
					
		</h:panelGroup>
		</f:facet>	
		
		<f:facet name="declaracao">
		<h:panelGroup>
			<h:commandLink immediate="true" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}" action="#{CatalogoBean.selectedNode}" actionListener="#{t.setNodeSelected}">
			
			<t:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0">
			</t:graphicImage>
			
			<t:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0">
			</t:graphicImage>			
			
			<h:outputText onclick="true" rendered="true" value="#{node.description}" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}"  />
			<h:outputText onclick="true" value="(#{node.childCount})" styleClass="childCount" />
			  </h:commandLink>
					
		</h:panelGroup>
		</f:facet>	
		
		<f:facet name="foo-folder">
		<h:panelGroup>
		
		    <t:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0">
			</t:graphicImage>
			
			<t:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0">
			</t:graphicImage>			
			
			<h:outputText onclick="true" rendered="true" value="#{node.description}" styleClass="node-Folder" />
			<h:outputText onclick="true" value="(#{node.childCount})" styleClass="childCount" />
		
		</h:panelGroup>
		</f:facet>
			 	
	</t:tree2>	
	
	<h:outputLink value="inicio.jsf">
	  <f:verbatim>Voltar</f:verbatim>
	</h:outputLink>

  </h:form>
  </body>	
 </html>
</f:view>  

Alguém pode me ajudar??

Achei neste site: http://wiki.apache.org/myfaces/Tree2 os tópicos: “Lazy loading child nodes from backend when expanding a tree node” e “Alternative Tree2 Lazy Loading Method…by jtmille3” mas ainda não consegui resolver.

Obrigada