Access the visible selection of the data table in Base?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
joesch
Posts: 53
Joined: Mon Apr 20, 2020 9:49 am
Location: Germany, near Berlin

Access the visible selection of the data table in Base?

Post by joesch »

Hello,

I am displaying a data table in Base as follows:

Code: Select all

Sub datentabelle_anzeigen()

	Dim URL as New com.sun.star.util.URL
	Dim Args(5) as New com.sun.star.beans.PropertyValue
	Dim Dispatch As Object
	
	DatabaseContext1 = createUnoService("com.sun.star.sdb.DatabaseContext")
	Datenquelle1=DatabaseContext1.getByName(ThisDatabaseDocument.URL)
	Verbindung = Datenquelle1.GetConnection("","")

	sql="Select * FROM ""SampleTable"""
	
    URL.Complete = ".component:DB/DataSourceBrowser"
    Dispatch = StarDesktop.queryDispatch(URL,"_Blank",8)

    Args(0).Name = "ActiveConnection"
    Args(0).Value = Verbindung
    Args(1).Name = "CommandType"
    Args(1).Value = 2
    Args(2).Name = "Command"
    Args(2).Value = sql
    Args(3).Name = "ShowMenu"
    Args(3).Value = True
    Args(4).Name = "ShowTreeView"
    Args(4).Value = False
    Args(5).Name = "ShowTreeViewButton"
    Args(5).Value = False

    Dispatch.dispatch(URL, Args)
End Sub
When this table is displayed, I can use the mouse to select individual fields or data rows (records), for example.

How can I, by means of macro, access these selection?
At least I want to determine the index of the data row in which the cursor (or the selection) is currently located.


greetings,
joesch
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Access the visible selection of the data table in Base?

Post by Villeroy »

Instead of a data table I used a form with a table control:

Code: Select all

Sub button_MriFormController(e)
frm = e.Source.Model.Parent
fc = getFormController(frm)
'mri fc
  oCurrentControl = fc.CurrentControl
  nCurrentColumnPosition = oCurrentControl.getCurrentColumnPosition() '0-based
'mri frm
  r = frm.Row ' 1-based
  Msgbox "Row: "& r & Chr(10) & "Colummnm: "& nCurrentColumnPosition
End Sub

Function getDataForm(byval m)
do until m.supportsService("com.sun.star.form.component.DataForm")
	m = m.getParent()
loop
getDataForm = m
End Function

Function getFormDocument(byval m)
do until m.supportsService("com.sun.star.document.OfficeDocument")
	m = m.getParent()
loop
getFormDocument = m
End Function

Function getFormController(oFormModel)
	doc = getFormDocument(oFormModel)
	view = doc.getCurrentController()
	getFormController = view.getFormController(oFormModel)
End Function
I hope this helps a little bit.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
joesch
Posts: 53
Joined: Mon Apr 20, 2020 9:49 am
Location: Germany, near Berlin

Re: Access the visible selection of the data table in Base?

Post by joesch »

Thank you ... but ...

Yes, I am very familiar with this way.
The problem is that it is very slow (*) to load large amounts of data into this control and therefore I came up with the alternative to display the table directly, which is considerably faster.


(*)
In the concrete case I need to load 1500 records with 218 columns. I am also familiar with this (viewtopic.php?f=21&t=1645), but it is unfortunately also slow with large amounts of data.




greetings,
joesch
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Access the visible selection of the data table in Base?

Post by Villeroy »

The table has implementation name "org.openoffice.comp.dbu.ODatasourceBrowser" and looks pretty much like a FormController.
It has CurrentControl.CurrentColumnPosition.
Its Model has a RowSet.Row.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
joesch
Posts: 53
Joined: Mon Apr 20, 2020 9:49 am
Location: Germany, near Berlin

Re: Access the visible selection of the data table in Base?

Post by joesch »

Thank you for this hint.

The following works for me (column 0 contains a unique ID):

Code: Select all

On Error Resume Next
	
alles = StarDesktop.getComponents
elemente = alles.createEnumeration
Do While elemente.hasmoreElements
  aktuell = elemente.NextElement
  If aktuell.Identifier = "com.sun.star.sdb.TableDataView" Then
    Msgbox aktuell.CurrentControl.getByIndex(0).Text
  End If
Loop

greetings,
joesch
Post Reply