Xalos – Arbol de informes
para visualizar el arbol de reportes se creo el siguiente codigo:
basicLibraries.loadLibrary("Tools")
if not IsConfigured() then
ologin = loadDialog("xalos","LoginForm")
loadconf
UpdateForm
ologin.execute
else
oMenu = loadDialog("xalos","MenuForm")
oTreeCtrl = oMenu.getControl("TreeControl")
oTreeModel = oTreeCtrl.Model
oTreeModel.SelectionType = 1
'oTreeModel.RootDisplayed = false
'instantiate the MutableTreeDataModel service
oMutableTreeDataModel = createUnoService("com.sun.star.awt.tree.MutableTreeDataModel")
'MutableTreeDataModel implemets XMutableTreeDataModel
'use XMutableTreeNode::createNode(
' [in] any DisplayValue,
' [in] boolean ChildsOnDemand )
'to create the root node
'If you pass to the boolean parameter TRUE as a argument,
'the created node will be treated as a non-leaf (branch) node
'by the XTreeControl , even when it has no child nodes.
'If false, the node will be a leaf.
'The root should obviously be a non-leaf node.
oRootNode = oMutableTreeDataModel.createNode( "Informes", true )
'use XMutableTreeNode::setRoot( [in] XMutableTreeNode RootNode )
'to set this node as the root of the model
oMutableTreeDataModel.setRoot(oRootNode)
' Obtengo los reportes
if loginID > 0 and Connect() then
Dim oSql as String
Dim oRowSet as Object
Dim nRegistros
oSql = "SELECT ptrl.name, p.ad_process_id from xendra.ad_process p join xendra.ad_process_trl ptrl on p.ad_process_id = ptrl.ad_process_id "
oSql = oSql & " WHERE coalesce(jasperreport ,'empty')!='empty' AND p.ad_process_id in "
oSql = oSql & "(select ad_process_id from xendra.ad_process_access where ad_role_id in "
oSql = oSql & "(select ad_role_id from xendra.ad_user_roles where ad_user_id = " & loginID & "))"
oRowSet = createUnoService("com.sun.star.sdb.RowSet")
oRowSet.activeConnection = oConnection
oRowSet.Command = oSql
oRowSet.execute
nRegistros = oRowSet.getPropertyValue("RowCount")
if nRegistros > 0 then
While oRowSet.next()
Dim oNode
oNode = oMutableTreeDataModel.createNode( oRowSet.getString(1), false )
oNode.dataValue = oRowSet.getString(2)
'oRootNode.appendChild( oMutableTreeDataModel.createNode( oRowSet.getString(1), false ) )
oRootNode.appendChild( oNode )
Wend
end if
oRowSet.dispose
else
rem ologin.Model.fromRange.Date = CDateToIso( Date()-30 )
rem ologin.Model.toRange.Date = CDateToIso( Date() )
end if
'now create the children of the root
'Dim oChildNode1
'oChildNode1 = oMutableTreeDataModel.createNode( "Parent 1", true )
'oRootNode.appendChild(oChildNode1)
'Create this child's own children
'In two steps:
' Dim oSubChildNode
' oSubChildNode = oMutableTreeDataModel.createNode(_
' "Child 1", true )
'oChildNode1.appendChild(oSubChildNode)
''In only one:
'Go deeper in the hierarchical structure
'oSubChildNode.appendChild( _
' oMutableTreeDataModel.createNode( _
' "Grandson 1", false ) )
' oSubChildNode.appendChild( _
' oMutableTreeDataModel.createNode( _
' "Grandson 2", false ) )
'In only one:
'oChildNode1.appendChild( oMutableTreeDataModel.createNode( _
' "Child 2", true ) )
'=======================================================================
'As you see, the Data Model always creates the nodes
'(XMutableDataModel::createNode)
'and then you add it to the node you want, taking care that
'the node created and the parent node belong to the same data model
' Dim oChildNode2
' oChildNode2 = oMutableTreeDataModel.createNode( "Parent 2", true )
' oChildNode2.dataValue = "ajua"
' oRootNode.appendChild(oChildNode2)
'
' Dim oChildNode3
' oChildNode3 = oMutableTreeDataModel.createNode( "Parent 3", FALSE )
'oChildNode3.setCollapsedGraphicURL( ANY_DOC )
'oChildNode3.setExpandedGraphicURL( ANY_DOC )
'oChildNode3.setNodeGraphicURL( BASIC_BRAKE )
' oRootNode.appendChild(oChildNode3)
' Dim oChildNode4
' oChildNode4 = oMutableTreeDataModel.createNode( "Parent 4", true )
' oRootNode.appendChild(oChildNode4)
' Dim oChildNode5
' oChildNode5 = oMutableTreeDataModel.createNode( "Parent 5", true )
' oRootNode.appendChild(oChildNode5)
'
' Dim oChildNode6
' oChildNode6 = oMutableTreeDataModel.createNode( "Parent 6", FALSE )
' oRootNode.appendChild(oChildNode6)
' 'Although the API refrence states the following:
' "If you want to add child nodes to your tree on demand
' you can .[..] Make sure the parent node returns true
' for XTreeNode::hasChildsOnDemand() either by implementing
' XTreeNode yourself or, if you use the MutableTreeDataModel ,
' use XMutableTreeNode::setHasChildsOnDemand() ."
'http://api.openoffice.org/docs/common/ref/com/sun/star/awt/tree/TreeControl.html
' Dim bHasChildernOnDemand as Boolean
'in this case hasChildsOnDemand returns FALSE
'bHasChildernOnDemand = oChildNode6.hasChildsOnDemand()
' Dim aChild : aChild = oMutableTreeDataModel.createNode( "Grandson", FALSE )
'BUT the node is appended to this node that has no children on demand
' oChildNode6.appendChild(aChild)
'Should it throw an exception?
'set the data model at the TreeControlModel::DataModel property.
oTreeModel.DataModel = oMutableTreeDataModel
'oTreeCtrl.DefaultExpandedGraphicURL = FOLDER_OPEN
'oTreeCtrl.DefaultCollapsedGraphicURL = FOLDER_CLOSED
Dim oListener,oListener2
oListener = CreateUnoListener("Tree_","com.sun.star.awt.tree.XTreeExpansionListener")
'oListener2 = createUnoListener("Select_","com.sun.star.view.XSelectionChangeListener")
'Xray oListener2
oTreeCtrl.addTreeExpansionListener(oListener)
'oTreeCtrl.addSelectionChangeListener(oListener2)
'oDlg.execute()
oMenu.execute
'oTreeCtrl.removeSelectionChangeListener(oListener2)
oTreeCtrl.removeTreeExpansionListener(oListener)
'oDlg.dispose()
oMenu.dispose
'oMenu.execute
' Dim rBounds as new com.sun.star.awt.Rectangle
' Dim wd as new com.sun.star.awt.WindowDescriptor
' oColumnModel = createUnoService("com.sun.star.awt.grid.DefaultGridColumnModel")
' oColumn1 = createUnoService("com.sun.star.awt.grid.GridColumn")
' oColumn1.Title = "City"
' oColumn1.ColumnWidth = 30
' oColumn2 = createUnoService("com.sun.star.awt.grid.GridColumn")
' oColumn2.Title = "Country"
' oColumn2.ColumnWidth = 50
' oColumnModel.addColumn(oColumn1)
' oColumnModel.addColumn(oColumn2)
' oDataModel = createUnoService("com.sun.star.awt.grid.DefaultGridDataModel")
' For i = 0 To 10
' oDataModel.addRow (""&i, Array(Chr(97+i), Chr(65+i)))
' Next i
' oDialogModel = createUnoService("com.sun.star.awt.UnoControlDialogModel")
' oDialogModel.Title = "GridControl Test"
' oDialogControl = createUnoService("com.sun.star.awt.UnoControlDialog")
' oDialogControl.setModel( oDialogModel )
' oDialogControl.setPosSize( 100, 100, 300, 200, com.sun.star.awt.PosSize.POSSIZE)
' oGridModel = oDialogModel.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
' oGridModel.Name = "MyGrid"
' oGridModel.GridDataModel = oDataModel
' oGridModel.ColumnModel = oColumnModel
' oGridModel.ShowColumnHeader = True
' oGridModel.ShowRowHeader = True
' oGridModel.HScroll = True
' oGridModel.VScroll = True
' oGridModel.Sizeable = True
' oGridControl = createUnoService("com.sun.star.awt.grid.UnoControlGrid")
' oGridControl.setModel(oGridModel)
' oDialogControl.addControl("MyGrid", oGridControl)
' oGridControl.setPosSize(10, 10, 280, 180, com.sun.star.awt.PosSize.POSSIZE)
' oToolkit = createUnoService("com.sun.star.awt.Toolkit")
' rBounds.X = oDialogControl.PosSize.X
' rBounds.Y = oDialogControl.PosSize.Y
' rBounds.Width = oDialogControl.PosSize.Width
' rBounds.Height = oDialogControl.PosSize.Height
'
' wd.Type = com.sun.star.awt.WindowClass.TOP
' wd.Bounds = rBounds
' With com.sun.star.awt.WindowAttribute
' wd.WindowAttributes = .BORDER + .MOVEABLE + .SIZEABLE + .CLOSEABLE
' End With
' wd.WindowServiceName = "window"
' oContWin = oToolkit.createWindow(wd)
' oFrame = createUnoService("com.sun.star.frame.Frame")
' oFrame.initialize(oContWin)
' StarDesktop.getFrames().append(oFrame)
' oFrame.Name = "TestGridFrame"
' oFrame.Title = "TestGridTitle"
' oGridControl.createPeer(oToolkit, oContWin)
' oContWin.setVisible(True)
' oListener = CreateUnoListener("XGridSelection_", "com.sun.star.awt.grid.XGridSelectionListener")
' oGridControl.addSelectionListener(oListener)
end if