1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="beans_XMultiPropertySet" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35Dim nCB1Val As Integer, nCB2Val As Integer
36
37
38Sub RunTest()
39
40'*************************************************************************
41' INTERFACE:
42' com.sun.star.beans.XMultiPropertySet
43'*************************************************************************
44On Error Goto ErrHndl
45    Dim bOK As Boolean
46    Dim oPropertySetInfo As Object
47    Dim oProperties As Variant
48    Dim aProp(0 to 1) As new com.sun.star.beans.PropertyValue
49    Dim cType As String
50    Dim oListener1 As Object, oListener2 As Object
51    Dim n As Integer, nMem As Integer, nIndex As Integer
52    Dim m As Integer
53    Dim bFound As Boolean
54    Dim nCount As Integer
55    Dim bBoolean As Boolean
56    Dim nInteger As Integer
57    Dim nLong As Long
58    Dim nSingle As Single
59    Dim nDouble As Double
60    Dim vMemVal As Variant
61    Dim nCB1ValMem As Integer
62    Dim nCB2ValMem As Integer
63
64    bOK = true
65    bFound = false
66    nCB1Val = 0
67    nCB2Val = 0
68    m = 0
69    oPropertySetInfo = oObj.GetPropertySetInfo
70    oProperties = oPropertySetInfo.Properties
71    nCount = uBound(oProperties)
72    Out.Log("The Object has " + nCount + " properties"
73
74    Out.Log("Create linsteners...")
75    oListener1 = createUNOListener("CB1_","com.sun.star.beans.XPropertiesChangeListener")
76    oListener2 = createUNOListener("CB2_","com.sun.star.beans.XPropertiesChangeListener")
77    Out.Log("oListener1 and oListener2 created"
78
79    'create sequences of Propertie-Names and Values
80    'fist get the amount of valid properties
81    for n = 0 to (nCount)
82        'look for readonly-properties
83        If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.READONLY) = 0 Then
84            'look for MAYBEVOID-Properties
85            If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.MAYBEVOID) = 0 Then
86                'is the Property testable
87                m = m + 1
88            End If
89        End If
90    next n
91
92    Out.Log("Amount of testable properites (without readonly and MAYBEVOID) is " + m)
93
94    'now store the names in sProperites
95    Dim searchProperties(0 to m-1) As String
96    m = 0
97    for n = 0 to (nCount)
98    'kick off readonly-properties
99        If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.READONLY) = 0 Then
100        'kick off MYBEVOID-Properties
101            If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.MAYBEVOID) = 0 Then
102                searchProperties(m) = oProperties(n).Name
103                Out.Log("" + m + " " + searchProperties(m) + " " + oObj.getPropertySetInfo.getPropertyByName(searchProperties(m)).Type.Name + " " + n)
104                Dim pVal As Variant
105
106                pVal = oObj.getPropertyValue(searchProperties(m))
107                oObj.setPropertyValues(Array(searchProperties(m)), Array(pVal))
108                m = m + 1
109            End If
110        End If
111    next n
112    nCount = m - 1
113
114    Dim sProperties(0 to nCount) As String
115    Dim vValues(0 to nCount) As Variant
116    For n = 0 to nCount
117        sProperties(n) = searchProperties(n)
118    next n
119
120    vValues() = oObj.getPropertyValues(sProperties())
121
122    'add ChangeListener
123    oObj.addPropertiesChangeListener(sProperties(),oListener1)
124    oObj.addPropertiesChangeListener(sProperties(),oListener2)
125    Out.Log("oListener1 and oListener2 added to object")
126
127    nIndex = 0
128    nMem = nIndex
129    'find at first a Boolean Value, if not available a String Property
130    While (NOT bFound) AND ((nCount &gt;= nIndex))
131        'get the property-type
132        cType = oObj.getPropertySetInfo.getPropertyByName(sProperties(nIndex)).Type.Name
133        If cType = "boolean" Then ' it is a Boolean Proerty
134            bFound = true
135            nMem = nIndex
136        else
137            If cType = "string" Then ' it is a String Property
138                nMem = nIndex
139            end if
140        end if
141        nIndex = nIndex + 1
142    Wend
143
144    nIndex = nIndex - 1
145    Out.Log("Property to change is: """ + sProperties(nIndex) + """ Type: """ + oObj.getPropertySetInfo.getPropertyByName(sProperties(nIndex)).Type.Name + """")
146    nIndex = nMem
147
148    'memory the old Value
149    vMemVal = vValues(nIndex)
150
151    'change a value of a property, hopefully a boolean or string property
152    select case VarType(vValues(nIndex)
153        case 11 'boolean
154            bBoolean = NOT vValues(nIndex)
155            vValues(nIndex) = bBoolean
156        case 2 'integer
157            nInteger = vValues(nIndex) + 1
158            vValues(nIndex) = nInteger
159        case 3 'long
160            nLong = vValues(nIndex) + 1
161            vValues(nIndex) = nLong
162        case 4 'single
163            nSingle = vValues(nIndex) + 1
164            vValues(nIndex) = nSingle
165        case 5 'double
166            nDouble = vValues(nIndex) + 1
167            vValues(nIndex) = nDouble
168        case 8 'string
169            vValues(nIndex) = vValues(nIndex) + cIfcShortName
170    end select
171
172    Test.StartMethod("getPropertySetInfo()")
173    bOK = bOK AND (uBound(oProperties) &gt; 0)
174    Test.MethodTested("getPropertySetInfo()", bOK)
175
176    Test.StartMethod("getPropertyValues()")
177    bOK = bOK AND (uBound(vValues()) &gt; 0)
178    Test.MethodTested("getPropertyValues()", bOK)
179
180    Test.StartMethod("setPropertyValues()")
181    oObj.setPropertyValues(sProperties(), vValues())
182    vValues() = oObj.getPropertyValues(sProperties())
183    bOK = bOK AND (vValues(nIndex) &lt;&gt; vMemVal)
184    Test.MethodTested("setPropertyValues()", bOK)
185
186    Test.StartMethod("addPropertiesChangeListener()")
187    bOK = (nCB1Val &gt;= 1) AND (nCB2Val &gt;= 1)
188    nCB1ValMem = nCB1Val
189    nCB2ValMem = nCb2Val
190    Test.MethodTested("addPropertiesChangeListener()", bOK)
191
192    'fire !!!
193    Out.Log("Try to fire property change event...")
194    oObj.firePropertiesChangeEvent(sProperties(),oListener1)
195    oObj.firePropertiesChangeEvent(sProperties(),oListener2)
196
197    Test.StartMethod("firePropertiesChangeEvent()")
198    bOK = (nCB1Val &gt;= nCB1ValMem) AND (nCB2Val &gt;= nCB2ValMem)
199    Test.MethodTested("firePropertiesChangeEvent()", bOK)
200    nCB1ValMem = nCB1Val
201    nCB2ValMem = nCb2Val
202
203
204    'remove one Listener and fire
205    Test.StartMethod("removePropertiesChangeListener()")
206    oObj.removePropertiesChangeListener(oListener1)
207    Out.Log("oListener1 removed")
208    select case VarType(vValues(nIndex)
209        case 11 'boolean
210            bBoolean = NOT vValues(nIndex)
211            vValues(nIndex) = bBoolean
212        case 2 'integer
213            nInteger = vValues(nIndex) + 1
214            vValues(nIndex) = nInteger
215        case 3 'long
216            nLong = vValues(nIndex) + 1
217            vValues(nIndex) = nLong
218        case 4 'single
219            nSingle = vValues(nIndex) + 1
220            vValues(nIndex) = nSingle
221        case 5 'double
222            nDouble = vValues(nIndex) + 1
223            vValues(nIndex) = nDouble
224        case 8 'string
225            vValues(nIndex) = vValues(nIndex) + cIfcShortName
226    end select
227
228    Out.Log("The property '" + sProperties(nIndex) + "' was changed")
229
230    oObj.setPropertyValues(sProperties(), vValues())
231
232    bOK = (nCB1Val = nCB1ValMem) AND (nCB2Val &gt;= nCB2ValMem)
233    Test.MethodTested("removePropertiesChangeListener()", bOK)
234
235    'remove the last Listener
236    oObj.removePropertiesChangeListener(oListener2)
237    Out.Log("oListener2 removed")
238
239
240Exit Sub
241ErrHndl:
242    Test.Exception()
243    bOK = false
244    resume next
245End Sub
246'callback routine called firePropertiesChangeEvent
247Sub CB1_propertiesChange
248    Out.Log("CallBack for Listener 1 was called.")
249    nCB1Val = nCB1Val + 1
250end Sub
251
252Sub CB2_propertiesChange
253    Out.Log("CallBack for Listener 2 was called.")
254    nCB2Val = nCB2Val + 1
255end Sub
256</script:module>
257