diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2022-11-06 16:46:10 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2022-11-06 17:37:10 +0100 |
commit | 26511a8961bc229c5685a913cc846398a97a5489 (patch) | |
tree | efc9c1fce78ebedf5a999f2d52165311a51c7b37 /wizards | |
parent | 9d42a2c29d195cdd4cb48acc8a65f5ca7df896c1 (diff) |
ScriptForge - (SF_Datasheet) Filter, OrderBy properties
For homogeneity with the Form service,
the
ApplyFilter()
OrderBy()
methods are replaced by the
Filter
OrderBy
updatable properties respectively.
Functionally there is no change.
This substitution is valid both for Basic and
Python user scripts.
Change-Id: I63a1d5c4554437b6a2cd634677e6eee246cb59ab
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142355
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 12 | ||||
-rw-r--r-- | wizards/source/sfdatabases/SF_Datasheet.xba | 221 |
2 files changed, 120 insertions, 113 deletions
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 24a4aac8d70f..b3b79132d4b2 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1778,16 +1778,13 @@ class SFDatabases: servicename = 'SFDatabases.Datasheet' servicesynonyms = ('datasheet', 'sfdatabases.datasheet') serviceproperties = dict(ColumnHeaders = False, CurrentColumn = False, CurrentRow = False, - DatabaseFileName = False, LastRow = False, ParentDatabase = False, Source = False, - SourceType = False, XComponent = False, XControlModel = False, - XTabControllerModel = False) + DatabaseFileName = False, Filter = True, LastRow = False, OrderBy = True, + ParentDatabase = False, Source = False, SourceType = False, XComponent = False, + XControlModel = False, XTabControllerModel = False) def Activate(self): return self.ExecMethod(self.vbMethod, 'Activate') - def ApplyFilter(self, filter = ''): - return self.ExecMethod(self.vbMethod, 'ApplyFilter', filter) - def CloseDatasheet(self): return self.ExecMethod(self.vbMethod, 'CloseDatasheet') @@ -1803,9 +1800,6 @@ class SFDatabases: def GoToCell(self, row = 0, column = 0): return self.ExecMethod(self.vbMethod, 'GoToCell', row, column) - def OrderBy(self, order = ''): - return self.ExecMethod(self.vbMethod, 'OrderBy', order) - def RemoveMenu(self, menuheader): return self.ExecMethod(self.vbMethod, 'RemoveMenu', menuheader) diff --git a/wizards/source/sfdatabases/SF_Datasheet.xba b/wizards/source/sfdatabases/SF_Datasheet.xba index f085ac510a60..a7835e21ffbc 100644 --- a/wizards/source/sfdatabases/SF_Datasheet.xba +++ b/wizards/source/sfdatabases/SF_Datasheet.xba @@ -129,6 +129,20 @@ Property Get DatabaseFileName() As String End Property ' SFDatabases.SF_Datasheet.DatabaseFileName REM ----------------------------------------------------------------------------- +Property Get Filter() As Variant +''' The Filter is a SQL WHERE clause without the WHERE keyword + Filter = _PropertyGet("Filter") +End Property ' SFDatabases.SF_Datasheet.Filter (get) + +REM ----------------------------------------------------------------------------- +Property Let Filter(Optional ByVal pvFilter As Variant) +''' Set the updatable property Filter +''' Table and field names may be surrounded by square brackets +''' When the argument is the zero-length string, the actual filter is removed + _PropertySet("Filter", pvFilter) +End Property ' SFDatabases.SF_Datasheet.Filter (let) + +REM ----------------------------------------------------------------------------- Property Get LastRow() As Long ''' Returns the total number of rows ''' The process may imply to move the cursor to the last available row. @@ -137,6 +151,20 @@ Property Get LastRow() As Long End Property ' SFDatabases.SF_Datasheet.LastRow REM ----------------------------------------------------------------------------- +Property Get OrderBy() As Variant +''' The Order is a SQL ORDER BY clause without the ORDER BY keywords + OrderBy = _PropertyGet("OrderBy") +End Property ' SFDocuments.SF_Form.OrderBy (get) + +REM ----------------------------------------------------------------------------- +Property Let OrderBy(Optional ByVal pvOrderBy As Variant) +''' Set the updatable property OrderBy +''' Table and field names may be surrounded by square brackets +''' When the argument is the zero-length string, the actual sort is removed + _PropertySet("OrderBy", pvOrderBy) +End Property ' SFDocuments.SF_Form.OrderBy (let) + +REM ----------------------------------------------------------------------------- Property Get ParentDatabase() As Object ''' Returns the database instance to which the datasheet belongs Set ParentDatabase = _PropertyGet("ParentDatabase") @@ -210,56 +238,6 @@ Catch: End Sub ' SFDatabases.SF_Datasheet.Activate REM ----------------------------------------------------------------------------- -Public Function ApplyFilter(Optional ByVal Filter As Variant) As Boolean -''' Apply the given filter to the actual datasheet -''' Args: -''' Filter: a SQL WHERE clause without the WHERE keyword -''' Table and field names may be surrounded by square brackets -''' When the argument is the zero-length string or absent, the actual filter is removed -''' Returns: -''' True when successful -''' Examples: -''' oSheet.ApplyFilter("[ShipCountry]='USA'") - -Dim bApply As Boolean ' Return value -Dim sFilter As String ' Filter after replacement of square brackets by real delimiter -Const cstThisSub = "SFDatabases.Datasheet.ApplyFilter" -Const cstSubArgs = "[Filter=""""]" - - If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch - bApply = False - -Check: - If IsMissing(Filter) Or IsEmpty(Filter) Then Filter = "" - If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then - If Not _IsStillAlive() Then GoTo Finally - If Not ScriptForge.SF_Utils._Validate(Filter, "Filter", V_STRING) Then GoTo Catch - End If - -Try: - With _TabControllerModel - If Len(Filter) > 0 Then - .Filter = _ParentDatabase._ReplaceSquareBrackets(Filter) - .ApplyFilter = True - .reload() - Else - .Filter = "" - .ApplyFilter = False - .reload() - End If - End With - - bApply = True - -Finally: - ApplyFilter = bApply - SF_Utils._ExitFunction(cstThisSub) - Exit Function -Catch: - GoTo Finally -End Function ' SFDatabases.SF_Datasheet.ApplyFilter - -REM ----------------------------------------------------------------------------- Public Function CloseDatasheet() As Boolean ''' Close the actual datasheet ''' Args: @@ -567,69 +545,17 @@ Public Function Methods() As Variant Methods = Array( _ "Activate" _ - , "ApplyFilter" _ , "CloseDatasheet" _ , "CreateMenu" _ , "GetText" _ , "GetValue" _ , "GoToCell" _ - , "OrderBy" _ , "RemoveMenu" _ ) End Function ' SFDatabases.SF_Datasheet.Methods REM ----------------------------------------------------------------------------- -Public Function OrderBy(Optional ByVal Order As Variant) As Boolean -''' Sort the actual datasheet based on the given ordering instructions -''' Args: -''' Order: a SQL ORDER BY clause without the ORDER BY keywords -''' Table and field names may be surrounded by square brackets -''' When the argument is the zero-length string or absent, the actual sort is removed -''' Returns: -''' True when successful -''' Examples: -''' oSheet.OrderBy("[ShipCountry] DESC, [EmployeeID]") - -Dim bOrder As Boolean ' Return value -Dim sOrder As String ' Order after replacement of square brackets by real delimiter -Const cstThisSub = "SFDatabases.Datasheet.OrderBy" -Const cstSubArgs = "[Order=""""]" - - If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch - bOrder = False - -Check: - If IsMissing(Order) Or IsEmpty(Order) Then Order = "" - If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then - If Not _IsStillAlive() Then GoTo Finally - If Not ScriptForge.SF_Utils._Validate(Order, "Order", V_STRING) Then GoTo Catch - End If - -Try: - With _TabControllerModel - If Len(Order) > 0 Then - .Order = _ParentDatabase._ReplaceSquareBrackets(Order) - .ApplyFilter = True - .reload() - Else - .Order = "" - .ApplyFilter = False - .reload() - End If - End With - - bOrder = True - -Finally: - OrderBy = bOrder - SF_Utils._ExitFunction(cstThisSub) - Exit Function -Catch: - GoTo Finally -End Function ' SFDatabases.SF_Datasheet.OrderBy - -REM ----------------------------------------------------------------------------- Public Function Properties() As Variant ''' Return the list or properties of the Model class as an array @@ -638,7 +564,9 @@ Public Function Properties() As Variant , "CurrentColumn" _ , "CurrentRow" _ , "DatabaseFileName" _ + , "Filter" _ , "LastRow" _ + , "OrderBy" _ , "ParentDatabase" _ , "Source" _ , "SourceType" _ @@ -712,6 +640,38 @@ Catch: GoTo Finally End Function ' SFDatabases.SF_Datasheet.RemoveMenu +REM ----------------------------------------------------------------------------- +Public Function SetProperty(Optional ByVal PropertyName As Variant _ + , Optional ByRef Value As Variant _ + ) As Boolean +''' Set a new value to the given property +''' Args: +''' PropertyName: the name of the property as a string +''' Value: its new value +''' Exceptions +''' ARGUMENTERROR The property does not exist + +Const cstThisSub = "SFDatabases.Datasheet.SetProperty" +Const cstSubArgs = "PropertyName, Value" + + If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + SetProperty = False + +Check: + If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch + End If + +Try: + SetProperty = _PropertySet(PropertyName, Value) + +Finally: + SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDatabases.SF_Datasheet.SetProperty + REM =========================================================== PRIVATE FUNCTIONS REM ----------------------------------------------------------------------------- @@ -828,6 +788,8 @@ Const cstSubArgs = "" _PropertyGet = _TabControllerModel.Row Case "DatabaseFileName" _PropertyGet = ScriptForge.SF_FileSystem._ConvertFromUrl(_BaseFileName) + Case "Filter" + _PropertyGet = _TabControllerModel.Filter Case "LastRow" With _TabControllerModel If .IsRowCountFinal Then @@ -843,6 +805,8 @@ Const cstSubArgs = "" End If End If End With + Case "OrderBy" + _PropertyGet = _TabControllerModel.Order Case "ParentDatabase" Set _PropertyGet = _ParentDatabase Case "Source" @@ -867,13 +831,62 @@ Catch: End Function ' SFDatabases.SF_Datasheet._PropertyGet REM ----------------------------------------------------------------------------- +Private Function _PropertySet(Optional ByVal psProperty As String _ + , Optional ByVal pvValue As Variant _ + ) As Boolean +''' Set the new value of the named property +''' Args: +''' psProperty: the name of the property +''' pvValue: the new value of the given property +''' Returns: +''' True if successful + +Dim bSet As Boolean ' Return value +Dim cstThisSub As String +Const cstSubArgs = "Value" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + bSet = False + + cstThisSub = "SFDatabases.Datasheet.set" & psProperty + ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) + If Not _IsStillAlive() Then GoTo Finally + + bSet = True + Select Case UCase(psProperty) + Case UCase("Filter") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Filter", V_STRING) Then GoTo Finally + With _TabControllerModel + If Len(pvValue) > 0 Then .Filter = _ParentDatabase._ReplaceSquareBrackets(pvValue) Else .Filter = "" + .ApplyFilter = ( Len(pvValue) > 0 ) + .reload() + End With + Case UCase("OrderBy") + If Not ScriptForge.SF_Utils._Validate(pvValue, "OrderBy", V_STRING) Then GoTo Finally + With _TabControllerModel + If Len(pvValue) > 0 Then .Order = _ParentDatabase._ReplaceSquareBrackets(pvValue) Else .Order = "" + .reload() + End With + Case Else + bSet = False + End Select + +Finally: + _PropertySet = bSet + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDatabases.SF_Datasheet._PropertySet + +REM ----------------------------------------------------------------------------- Private Function _Repr() As String ''' Convert the Datasheet instance to a readable string, typically for debugging purposes (DebugPrint ...) ''' Args: ''' Return: -''' "[DATASHEET]: A readable string" +''' "[DATASHEET]: tablename,base file url" - _Repr = "[DATASHEET]: A readable string" + _Repr = "[DATASHEET]: " & _Command & "," & _BaseFileName End Function ' SFDatabases.SF_Datasheet._Repr |