REM  *****  BASIC  *****

'Variables generales
	
	'Control de arbol
	Private PlanCuentasDlg As Object
	Public PreViewControl As Object
	Private TreeDataModel As Object
	Private TreeModel As Object


Sub PlanDeCuentas()

'Variables Treecontrol
	Dim iRoot As Object
	Dim iParent As Object
	Dim iChild As Object
	Dim iLevel As Integer
	
'Cargando la libreria de diálogos
	DialogLibraries.LoadLibrary("Dialogos")

'Accediendo el diálogo
	PlanCuentasDlg = createUnoDialog(DialogLibraries.Dialogos.PlanCuentas)

'Accediendo al modelo de datos
	TreeDataModel = createUnoService("com.sun.star.awt.tree.MutableTreeDataModel")
	
'Creando el root
	iRoot = TreeDataModel.createNode("Root", True)
	
'Se ubica en iRoot en el Root del arbol
	TreeDataModel.setRoot(iRoot)
	
'Creando un un Parent con 4 Children
	iParent = TreeDataModel.createNode("1 - ACTIVOS", True)
	
	'Agregando 4 children al parent
	For iLevel = 1 To 4
		iParent.appendChild(TreeDataModel.createNode("ACTIVOS - " & iLevel, True))
	Next
	
		'Se agrega 3 GrandChildren al Child 3. El índex inicia en 0
	
			'Accediendo al Child3
			iChild = iParent.getChildAt(2)
		
			For iLevel = 1 To 3
				iChild.appendChild(TreeDataModel.createNode("GrandChild - " & iLevel, True))
			Next
		
				'Se agrega 2 Great GrandChildren to GrandChild1
		
				'Accediendo al Child 3
				iChild = iParent.getChildAt(2)
		
				'Accediendo al GrandChild 1
				iChild = iChild.getChildAt(0)
		
				For iLevel = 1 To 3
					iChild.appendChild(TreeDataModel.createNode("GreatGrandChild - " & iLevel, True))
				Next
				
'Se agrega el parent al root
	iRoot.appendChild(iParent)
	
'Agregando datos al Child1
	iChild = iParent.getChildAt(0)
		iChild.dataValue = "Some data for Child1"
	

'Ensamblando el arbol

	'Vinculando el control de vista previa
	PreViewControl = PlanCuentasDlg.getControl("PreView")
	
	'Accediendo al modelo del control
	TreeModel = PreViewControl.Model()
	
	'Vinculando el DataModel
	TreeModel.DataModel = TreeDataModel
