2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod
._dbaccess
;
20 import java
.io
.PrintWriter
;
21 import java
.util
.Comparator
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.FormTools
;
29 import util
.SOfficeFactory
;
30 import util
.WriterTools
;
33 import com
.sun
.star
.accessibility
.AccessibleRole
;
34 import com
.sun
.star
.accessibility
.XAccessible
;
35 import com
.sun
.star
.accessibility
.XAccessibleAction
;
36 import com
.sun
.star
.awt
.Point
;
37 import com
.sun
.star
.awt
.Size
;
38 import com
.sun
.star
.awt
.XControlModel
;
39 import com
.sun
.star
.awt
.XDevice
;
40 import com
.sun
.star
.awt
.XExtendedToolkit
;
41 import com
.sun
.star
.awt
.XGraphics
;
42 import com
.sun
.star
.awt
.XToolkit
;
43 import com
.sun
.star
.awt
.XWindow
;
44 import com
.sun
.star
.awt
.XWindowPeer
;
45 import com
.sun
.star
.beans
.XPropertySet
;
46 import com
.sun
.star
.container
.XNameContainer
;
47 import com
.sun
.star
.drawing
.XControlShape
;
48 import com
.sun
.star
.form
.XBoundComponent
;
49 import com
.sun
.star
.form
.XGridColumnFactory
;
50 import com
.sun
.star
.form
.XLoadable
;
51 import com
.sun
.star
.lang
.XComponent
;
52 import com
.sun
.star
.lang
.XMultiServiceFactory
;
53 import com
.sun
.star
.sdbc
.XResultSetUpdate
;
54 import com
.sun
.star
.text
.XTextDocument
;
55 import com
.sun
.star
.uno
.UnoRuntime
;
56 import com
.sun
.star
.uno
.XInterface
;
57 import com
.sun
.star
.util
.URL
;
58 import com
.sun
.star
.util
.XCloseable
;
59 import com
.sun
.star
.view
.XControlAccess
;
63 * Test for object which represents the control of the Grid model. <p>
64 * Object implements the following interfaces :
66 * <li> <code>com::sun::star::util::XModifyBroadcaster</code></li>
67 * <li> <code>com::sun::star::form::XGridFieldDataSupplier</code></li>
68 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
69 * <li> <code>com::sun::star::form::XGrid</code></li>
70 * <li> <code>com::sun::star::awt::XControl</code></li>
71 * <li> <code>com::sun::star::util::XModeSelector</code></li>
72 * <li> <code>com::sun::star::container::XElementAccess</code></li>
73 * <li> <code>com::sun::star::awt::XWindow</code></li>
74 * <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li>
75 * <li> <code>com::sun::star::frame::XDispatch</code></li>
76 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
77 * <li> <code>com::sun::star::form::XBoundComponent</code></li>
78 * <li> <code>com::sun::star::frame::XDispatchProviderInterception</code></li>
79 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
80 * <li> <code>com::sun::star::lang::XComponent</code></li>
81 * <li> <code>com::sun::star::awt::XView</code></li>
82 * <li> <code>com::sun::star::container::XContainer</code></li>
84 * This object test <b> is NOT </b> designed to be run in several
85 * threads concurrently.
86 * @see com.sun.star.util.XModifyBroadcaster
87 * @see com.sun.star.form.XGridFieldDataSupplier
88 * @see com.sun.star.view.XSelectionSupplier
89 * @see com.sun.star.form.XGrid
90 * @see com.sun.star.awt.XControl
91 * @see com.sun.star.util.XModeSelector
92 * @see com.sun.star.container.XElementAccess
93 * @see com.sun.star.awt.XWindow
94 * @see com.sun.star.form.XUpdateBroadcaster
95 * @see com.sun.star.frame.XDispatch
96 * @see com.sun.star.container.XEnumerationAccess
97 * @see com.sun.star.form.XBoundComponent
98 * @see com.sun.star.frame.XDispatchProviderInterception
99 * @see com.sun.star.container.XIndexAccess
100 * @see com.sun.star.lang.XComponent
101 * @see com.sun.star.awt.XView
102 * @see com.sun.star.container.XContainer
103 * @see ifc.util._XModifyBroadcaster
104 * @see ifc.form._XGridFieldDataSupplier
105 * @see ifc.view._XSelectionSupplier
106 * @see ifc.form._XGrid
107 * @see ifc.awt._XControl
108 * @see ifc.util._XModeSelector
109 * @see ifc.container._XElementAccess
110 * @see ifc.awt._XWindow
111 * @see ifc.form._XUpdateBroadcaster
112 * @see ifc.frame._XDispatch
113 * @see ifc.container._XEnumerationAccess
114 * @see ifc.form._XBoundComponent
115 * @see ifc.frame._XDispatchProviderInterception
116 * @see ifc.container._XIndexAccess
117 * @see ifc.lang._XComponent
118 * @see ifc.awt._XView
119 * @see ifc.container._XContainer
121 public class SbaXGridControl
extends TestCase
{
122 XTextDocument xTextDoc
;
125 * Creates Writer document.
128 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
129 SOfficeFactory SOF
= SOfficeFactory
.getFactory(Param
.getMSF());
131 log
.println("creating a textdocument");
132 xTextDoc
= SOF
.createTextDoc(null);
136 * Disposes Writer document.
139 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
140 //closing the appearing dialog before disposing the document
141 XInterface toolkit
= null;
144 toolkit
= (XInterface
) tParam
.getMSF()
145 .createInstance("com.sun.star.awt.Toolkit");
146 } catch (com
.sun
.star
.uno
.Exception e
) {
147 log
.println("Couldn't get toolkit");
148 e
.printStackTrace(log
);
149 throw new StatusException("Couldn't get toolkit", e
);
152 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
153 XExtendedToolkit
.class, toolkit
);
155 Object atw
= tk
.getActiveTopWindow();
157 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
160 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
162 XInterface button
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
163 AccessibleRole
.PUSH_BUTTON
);
165 XAccessibleAction action
= UnoRuntime
.queryInterface(
166 XAccessibleAction
.class, button
);
169 action
.doAccessibleAction(0);
170 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iob
) {
171 log
.println("couldn't close dialog");
172 } catch (com
.sun
.star
.lang
.DisposedException e
) {
173 log
.println("couldn't close dialog");
176 log
.println(" disposing xTextDoc ");
179 XCloseable closer
= UnoRuntime
.queryInterface(
180 XCloseable
.class, xTextDoc
);
182 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
183 log
.println("couldn't close document");
184 } catch (com
.sun
.star
.lang
.DisposedException e
) {
185 log
.println("couldn't close document");
190 * Creating a TestEnvironment for the interfaces to be tested.
191 * For object creation first a
192 * <code>com.sun.star.form.component.GridControl<code> instance
193 * is added to the <code>ControlShape</code>. Then this model's
194 * control is retrieved.
196 * Object relations created :
198 * <li> <code>'GRAPHICS'</code> for
199 * {@link ifc.awt._XView} test : <code>XGraphics</code>
200 * object different that belong to the object tested.</li>
201 * <li> <code>'CONTEXT'</code> for
202 * {@link ifc.awt._XControl} </li>
203 * <li> <code>'WINPEER'</code> for
204 * {@link ifc.awt._XControl} </li>
205 * <li> <code>'TOOLKIT'</code> for
206 * {@link ifc.awt._XControl} </li>
207 * <li> <code>'MODEL'</code> for
208 * {@link ifc.awt._XControl} </li>
209 * <li> <code>'XWindow.AnotherWindow'</code> for
210 * {@link ifc.awt._XWindow} for switching focus.</li>
211 * <li> <code>'XDispatch.URL'</code> for
212 * {@link ifc.frame._XDispatch} the url which moves
213 * DB cursor to the next row (".uno:FormSlots/moveToNext").</li>
214 * <li> <code>'XContainer.Container'</code> for
215 * {@link ifc.container._XContainer} as the component created
216 * doesn't support <code>XContainer</code> itself, but
217 * it is supported by its model. So this model is passed.</li>
218 * <li> <code>'INSTANCE'</code> for
219 * {@link ifc.container._XContainer} the instance to be
220 * inserted into collection. Is a column instance.</li>
224 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
225 PrintWriter log
) throws Exception
{
226 XInterface oObj
= null;
227 XWindowPeer the_win
= null;
228 XToolkit the_kit
= null;
229 XDevice aDevice
= null;
230 XGraphics aGraphic
= null;
231 XPropertySet aControl
= null;
232 XPropertySet aControl2
= null;
233 XPropertySet aControl3
= null;
234 XPropertySet aControl4
= null;
235 XGridColumnFactory columns
= null;
237 //Insert a ControlShape and get the ControlModel
238 XControlShape aShape
= createGrid(xTextDoc
, 3000, 4500, 15000, 10000);
240 XControlModel the_Model
= aShape
.getControl();
242 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
244 XLoadable formLoader
= FormTools
.bindForm(xTextDoc
);
246 //Try to query XControlAccess
247 XControlAccess the_access
= UnoRuntime
.queryInterface(
248 XControlAccess
.class,
249 xTextDoc
.getCurrentController());
251 columns
= UnoRuntime
.queryInterface(
252 XGridColumnFactory
.class, the_Model
);
253 aControl
= columns
.createColumn("TextField");
254 aControl
.setPropertyValue("DataField", "Identifier");
255 aControl
.setPropertyValue("Label", "Identifier");
256 aControl2
= columns
.createColumn("TextField");
257 aControl2
.setPropertyValue("DataField", "Publisher");
258 aControl2
.setPropertyValue("Label", "Publisher");
259 aControl3
= columns
.createColumn("TextField");
260 aControl3
.setPropertyValue("DataField", "Author");
261 aControl3
.setPropertyValue("Label", "Author");
262 aControl4
= columns
.createColumn("TextField");
263 aControl4
.setPropertyValue("DataField", "Title");
264 aControl4
.setPropertyValue("Label", "Title");
266 XNameContainer aContainer
= UnoRuntime
.queryInterface(
267 XNameContainer
.class, the_Model
);
269 aContainer
.insertByName("First", aControl
);
270 aContainer
.insertByName("Second", aControl2
);
272 //now get the OGridControl
273 oObj
= the_access
.getControl(the_Model
);
274 the_win
= the_access
.getControl(the_Model
).getPeer();
275 the_kit
= the_win
.getToolkit();
276 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
277 aGraphic
= aDevice
.createGraphics();
280 // creating another window
281 aShape
= FormTools
.createControlShape(xTextDoc
, 3000, 4500, 15000,
284 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
286 the_Model
= aShape
.getControl();
289 //Try to query XControlAccess
290 the_access
= UnoRuntime
.queryInterface(
291 XControlAccess
.class,
292 xTextDoc
.getCurrentController());
294 //now get the TextControl
298 cntrl
= the_access
.getControl(the_Model
);
299 win
= UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
301 log
.println("creating a new environment for object");
303 TestEnvironment tEnv
= new TestEnvironment(oObj
);
306 //Relations for XSelectionSupplier
307 tEnv
.addObjRelation("Selections",
309 new Object
[] { Integer
.valueOf(0) }, new Object
[] { Integer
.valueOf(1) }
311 tEnv
.addObjRelation("Comparer",
312 new Comparator
<Integer
>() {
313 public int compare(Integer o1
, Integer o2
) {
314 return o1
.compareTo(o2
);
319 //Relation for XContainer
320 tEnv
.addObjRelation("XContainer.Container", aContainer
);
321 tEnv
.addObjRelation("INSTANCE", aControl3
);
322 tEnv
.addObjRelation("INSTANCE2", aControl4
);
325 //Adding ObjRelation for XView
326 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
329 //Adding ObjRelation for XControl
330 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
331 tEnv
.addObjRelation("WINPEER", the_win
);
332 tEnv
.addObjRelation("TOOLKIT", the_kit
);
333 tEnv
.addObjRelation("MODEL", the_Model
);
336 // Adding relation for XWindow
337 tEnv
.addObjRelation("XWindow.AnotherWindow", win
);
339 // Adding relation for XDispatch
341 url
.Complete
= ".uno:FormSlots/moveToNext";
344 //url.Complete = ".uno:GridSlots/RowHeight";
345 //url.Complete = ".uno:GridSlots/RowHeight" ;
346 tEnv
.addObjRelation("XDispatch.URL", url
);
348 log
.println("ImplName: " + utils
.getImplName(oObj
));
350 FormTools
.switchDesignOf(Param
.getMSF(), xTextDoc
);
352 // adding relation for XUpdateBroadcaster
353 final XInterface ctrl
= oObj
;
354 final XLoadable formLoaderF
= formLoader
;
355 final XPropertySet ps
= UnoRuntime
.queryInterface(
356 XPropertySet
.class, aControl2
);
357 tEnv
.addObjRelation("XUpdateBroadcaster.Checker",
358 new ifc
.form
._XUpdateBroadcaster
.UpdateChecker() {
359 private String lastText
= "";
361 public void update() throws com
.sun
.star
.uno
.Exception
{
362 if (!formLoaderF
.isLoaded()) {
366 lastText
= "_" + ps
.getPropertyValue("Text");
367 ps
.setPropertyValue("Text", lastText
);
370 public void commit() throws com
.sun
.star
.sdbc
.SQLException
{
371 XBoundComponent bound
= UnoRuntime
.queryInterface(
372 XBoundComponent
.class, ctrl
);
373 XResultSetUpdate update
= UnoRuntime
.queryInterface(
374 XResultSetUpdate
.class,
381 public boolean wasCommited() throws com
.sun
.star
.uno
.Exception
{
382 String getS
= (String
) ps
.getPropertyValue("Text");
384 return lastText
.equals(getS
);
389 } // finish method getTestEnvironment
391 public static XControlShape
createGrid(XComponent oDoc
, int height
,
392 int width
, int x
, int y
) throws Exception
{
393 Size size
= new Size();
394 Point position
= new Point();
395 XControlShape oCShape
= null;
396 XControlModel aControl
= null;
399 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(
400 XMultiServiceFactory
.class,
403 Object oInt
= oDocMSF
.createInstance(
404 "com.sun.star.drawing.ControlShape");
405 Object aCon
= oDocMSF
.createInstance(
406 "com.sun.star.form.component.GridControl");
407 XPropertySet model_props
= UnoRuntime
.queryInterface(
408 XPropertySet
.class, aCon
);
409 model_props
.setPropertyValue("DefaultControl",
410 "com.sun.star.form.control.InteractionGridControl");
411 aControl
= UnoRuntime
.queryInterface(
412 XControlModel
.class, aCon
);
413 oCShape
= UnoRuntime
.queryInterface(
414 XControlShape
.class, oInt
);
415 size
.Height
= height
;
419 oCShape
.setSize(size
);
420 oCShape
.setPosition(position
);
422 oCShape
.setControl(aControl
);
425 } // finish createGrid