xref: /AOO41X/main/qadevOOo/tests/java/mod/_dbaccess/SbaXGridControl.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package mod._dbaccess;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import java.io.PrintWriter;
30*cdf0e10cSrcweir import java.util.Comparator;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import lib.StatusException;
33*cdf0e10cSrcweir import lib.TestCase;
34*cdf0e10cSrcweir import lib.TestEnvironment;
35*cdf0e10cSrcweir import lib.TestParameters;
36*cdf0e10cSrcweir import util.AccessibilityTools;
37*cdf0e10cSrcweir import util.FormTools;
38*cdf0e10cSrcweir import util.SOfficeFactory;
39*cdf0e10cSrcweir import util.WriterTools;
40*cdf0e10cSrcweir import util.utils;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole;
43*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
44*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleAction;
45*cdf0e10cSrcweir import com.sun.star.awt.Point;
46*cdf0e10cSrcweir import com.sun.star.awt.Size;
47*cdf0e10cSrcweir import com.sun.star.awt.XControlModel;
48*cdf0e10cSrcweir import com.sun.star.awt.XDevice;
49*cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit;
50*cdf0e10cSrcweir import com.sun.star.awt.XGraphics;
51*cdf0e10cSrcweir import com.sun.star.awt.XToolkit;
52*cdf0e10cSrcweir import com.sun.star.awt.XWindow;
53*cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
54*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
55*cdf0e10cSrcweir import com.sun.star.container.XNameContainer;
56*cdf0e10cSrcweir import com.sun.star.drawing.XControlShape;
57*cdf0e10cSrcweir import com.sun.star.drawing.XShape;
58*cdf0e10cSrcweir import com.sun.star.form.XBoundComponent;
59*cdf0e10cSrcweir import com.sun.star.form.XGridColumnFactory;
60*cdf0e10cSrcweir import com.sun.star.form.XLoadable;
61*cdf0e10cSrcweir import com.sun.star.lang.XComponent;
62*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
63*cdf0e10cSrcweir import com.sun.star.sdbc.XResultSetUpdate;
64*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
65*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
66*cdf0e10cSrcweir import com.sun.star.uno.XInterface;
67*cdf0e10cSrcweir import com.sun.star.util.URL;
68*cdf0e10cSrcweir import com.sun.star.util.XCloseable;
69*cdf0e10cSrcweir import com.sun.star.view.XControlAccess;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir /**
73*cdf0e10cSrcweir * Test for object which represents the control of the Grid model. <p>
74*cdf0e10cSrcweir * Object implements the following interfaces :
75*cdf0e10cSrcweir * <ul>
76*cdf0e10cSrcweir *  <li> <code>com::sun::star::util::XModifyBroadcaster</code></li>
77*cdf0e10cSrcweir *  <li> <code>com::sun::star::form::XGridFieldDataSupplier</code></li>
78*cdf0e10cSrcweir *  <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
79*cdf0e10cSrcweir *  <li> <code>com::sun::star::form::XGrid</code></li>
80*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XControl</code></li>
81*cdf0e10cSrcweir *  <li> <code>com::sun::star::util::XModeSelector</code></li>
82*cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XElementAccess</code></li>
83*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XWindow</code></li>
84*cdf0e10cSrcweir *  <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li>
85*cdf0e10cSrcweir *  <li> <code>com::sun::star::frame::XDispatch</code></li>
86*cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
87*cdf0e10cSrcweir *  <li> <code>com::sun::star::form::XBoundComponent</code></li>
88*cdf0e10cSrcweir *  <li> <code>com::sun::star::frame::XDispatchProviderInterception</code></li>
89*cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
90*cdf0e10cSrcweir *  <li> <code>com::sun::star::lang::XComponent</code></li>
91*cdf0e10cSrcweir *  <li> <code>com::sun::star::awt::XView</code></li>
92*cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XContainer</code></li>
93*cdf0e10cSrcweir * </ul>
94*cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several
95*cdf0e10cSrcweir * threads concurently.
96*cdf0e10cSrcweir * @see com.sun.star.util.XModifyBroadcaster
97*cdf0e10cSrcweir * @see com.sun.star.form.XGridFieldDataSupplier
98*cdf0e10cSrcweir * @see com.sun.star.view.XSelectionSupplier
99*cdf0e10cSrcweir * @see com.sun.star.form.XGrid
100*cdf0e10cSrcweir * @see com.sun.star.awt.XControl
101*cdf0e10cSrcweir * @see com.sun.star.util.XModeSelector
102*cdf0e10cSrcweir * @see com.sun.star.container.XElementAccess
103*cdf0e10cSrcweir * @see com.sun.star.awt.XWindow
104*cdf0e10cSrcweir * @see com.sun.star.form.XUpdateBroadcaster
105*cdf0e10cSrcweir * @see com.sun.star.frame.XDispatch
106*cdf0e10cSrcweir * @see com.sun.star.container.XEnumerationAccess
107*cdf0e10cSrcweir * @see com.sun.star.form.XBoundComponent
108*cdf0e10cSrcweir * @see com.sun.star.frame.XDispatchProviderInterception
109*cdf0e10cSrcweir * @see com.sun.star.container.XIndexAccess
110*cdf0e10cSrcweir * @see com.sun.star.lang.XComponent
111*cdf0e10cSrcweir * @see com.sun.star.awt.XView
112*cdf0e10cSrcweir * @see com.sun.star.container.XContainer
113*cdf0e10cSrcweir * @see ifc.util._XModifyBroadcaster
114*cdf0e10cSrcweir * @see ifc.form._XGridFieldDataSupplier
115*cdf0e10cSrcweir * @see ifc.view._XSelectionSupplier
116*cdf0e10cSrcweir * @see ifc.form._XGrid
117*cdf0e10cSrcweir * @see ifc.awt._XControl
118*cdf0e10cSrcweir * @see ifc.util._XModeSelector
119*cdf0e10cSrcweir * @see ifc.container._XElementAccess
120*cdf0e10cSrcweir * @see ifc.awt._XWindow
121*cdf0e10cSrcweir * @see ifc.form._XUpdateBroadcaster
122*cdf0e10cSrcweir * @see ifc.frame._XDispatch
123*cdf0e10cSrcweir * @see ifc.container._XEnumerationAccess
124*cdf0e10cSrcweir * @see ifc.form._XBoundComponent
125*cdf0e10cSrcweir * @see ifc.frame._XDispatchProviderInterception
126*cdf0e10cSrcweir * @see ifc.container._XIndexAccess
127*cdf0e10cSrcweir * @see ifc.lang._XComponent
128*cdf0e10cSrcweir * @see ifc.awt._XView
129*cdf0e10cSrcweir * @see ifc.container._XContainer
130*cdf0e10cSrcweir */
131*cdf0e10cSrcweir public class SbaXGridControl extends TestCase {
132*cdf0e10cSrcweir     XTextDocument xTextDoc;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     /**
135*cdf0e10cSrcweir     * Creates Writer document.
136*cdf0e10cSrcweir     */
137*cdf0e10cSrcweir     protected void initialize(TestParameters Param, PrintWriter log) {
138*cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)Param.getMSF());
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         try {
141*cdf0e10cSrcweir             log.println("creating a textdocument");
142*cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc(null);
143*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
144*cdf0e10cSrcweir             // Some exception occures.FAILED
145*cdf0e10cSrcweir             e.printStackTrace(log);
146*cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
147*cdf0e10cSrcweir         }
148*cdf0e10cSrcweir     }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     /**
151*cdf0e10cSrcweir     * Disposes Writer document.
152*cdf0e10cSrcweir     */
153*cdf0e10cSrcweir     protected void cleanup(TestParameters tParam, PrintWriter log) {
154*cdf0e10cSrcweir         //closing the appearing dialog before disposing the document
155*cdf0e10cSrcweir         XInterface toolkit = null;
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir         try {
158*cdf0e10cSrcweir             toolkit = (XInterface) ((XMultiServiceFactory)tParam.getMSF())
159*cdf0e10cSrcweir                                          .createInstance("com.sun.star.awt.Toolkit");
160*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
161*cdf0e10cSrcweir             log.println("Couldn't get toolkit");
162*cdf0e10cSrcweir             e.printStackTrace(log);
163*cdf0e10cSrcweir             throw new StatusException("Couldn't get toolkit", e);
164*cdf0e10cSrcweir         }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
167*cdf0e10cSrcweir                                       XExtendedToolkit.class, toolkit);
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         Object atw = tk.getActiveTopWindow();
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
172*cdf0e10cSrcweir                                                               atw);
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         XInterface button = AccessibilityTools.getAccessibleObjectForRole(xRoot,
177*cdf0e10cSrcweir                                                           AccessibleRole.PUSH_BUTTON);
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         XAccessibleAction action = (XAccessibleAction) UnoRuntime.queryInterface(
180*cdf0e10cSrcweir                                            XAccessibleAction.class, button);
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         try {
183*cdf0e10cSrcweir             action.doAccessibleAction(0);
184*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iob) {
185*cdf0e10cSrcweir             log.println("couldn't close dialog");
186*cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException e) {
187*cdf0e10cSrcweir             log.println("couldn't close dialog");
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         log.println("    disposing xTextDoc ");
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir         try {
193*cdf0e10cSrcweir             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
194*cdf0e10cSrcweir                                         XCloseable.class, xTextDoc);
195*cdf0e10cSrcweir             closer.close(true);
196*cdf0e10cSrcweir         } catch (com.sun.star.util.CloseVetoException e) {
197*cdf0e10cSrcweir             log.println("couldn't close document");
198*cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException e) {
199*cdf0e10cSrcweir             log.println("couldn't close document");
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     /**
204*cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
205*cdf0e10cSrcweir     * For object creation first a
206*cdf0e10cSrcweir     * <code>com.sun.star.form.component.GridControl<code> instance
207*cdf0e10cSrcweir     * is added to the <code>ControlShape</code>. Then this model's
208*cdf0e10cSrcweir     * control is retrieved.
209*cdf0e10cSrcweir     *
210*cdf0e10cSrcweir     *     Object relations created :
211*cdf0e10cSrcweir     * <ul>
212*cdf0e10cSrcweir     *  <li> <code>'GRAPHICS'</code> for
213*cdf0e10cSrcweir     *      {@link ifc.awt_XView} test : <code>XGraphics</code>
214*cdf0e10cSrcweir     *   object different that belong to the object tested.</li>
215*cdf0e10cSrcweir     *  <li> <code>'CONTEXT'</code> for
216*cdf0e10cSrcweir     *      {@link ifc.awt._XControl} </li>
217*cdf0e10cSrcweir     *  <li> <code>'WINPEER'</code> for
218*cdf0e10cSrcweir     *      {@link ifc.awt._XCOntrol} </li>
219*cdf0e10cSrcweir     *  <li> <code>'TOOLKIT'</code> for
220*cdf0e10cSrcweir     *      {@link ifc.awt._XCOntrol} </li>
221*cdf0e10cSrcweir     *  <li> <code>'MODEL'</code> for
222*cdf0e10cSrcweir     *      {@link ifc.awt._XCOntrol} </li>
223*cdf0e10cSrcweir     *  <li> <code>'XWindow.AnotherWindow'</code> for
224*cdf0e10cSrcweir     *      {@link ifc.awt._XWindow} for switching focus.</li>
225*cdf0e10cSrcweir     *  <li> <code>'XDispatch.URL'</code> for
226*cdf0e10cSrcweir     *      {@link ifc.frame._XDispatch} the url which moves
227*cdf0e10cSrcweir     *      DB cursor to the next row (".uno:FormSlots/moveToNext").</li>
228*cdf0e10cSrcweir     *  <li> <code>'XContainer.Container'</code> for
229*cdf0e10cSrcweir     *      {@link ifc.container._XContainer} as the component created
230*cdf0e10cSrcweir     *      doesn't support <code>XContainer</code> itself, but
231*cdf0e10cSrcweir     *      it is supported by its model. So this model is passed.</li>
232*cdf0e10cSrcweir     *  <li> <code>'INSTANCE'</code> for
233*cdf0e10cSrcweir     *      {@link ifc.container._XContainer} the instance to be
234*cdf0e10cSrcweir     *      inserted into collection. Is a column instance.</li>
235*cdf0e10cSrcweir     * </ul>
236*cdf0e10cSrcweir     */
237*cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(TestParameters Param,
238*cdf0e10cSrcweir                                                     PrintWriter log) {
239*cdf0e10cSrcweir         XInterface oObj = null;
240*cdf0e10cSrcweir         XWindowPeer the_win = null;
241*cdf0e10cSrcweir         XToolkit the_kit = null;
242*cdf0e10cSrcweir         XDevice aDevice = null;
243*cdf0e10cSrcweir         XGraphics aGraphic = null;
244*cdf0e10cSrcweir         XPropertySet aControl = null;
245*cdf0e10cSrcweir         XPropertySet aControl2 = null;
246*cdf0e10cSrcweir         XPropertySet aControl3 = null;
247*cdf0e10cSrcweir         XPropertySet aControl4 = null;
248*cdf0e10cSrcweir         XGridColumnFactory columns = null;
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir         //Insert a ControlShape and get the ControlModel
251*cdf0e10cSrcweir         XControlShape aShape = createGrid(xTextDoc, 3000, 4500, 15000, 10000);
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir         XControlModel the_Model = aShape.getControl();
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir         XLoadable formLoader = FormTools.bindForm(xTextDoc);
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         //Try to query XControlAccess
260*cdf0e10cSrcweir         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
261*cdf0e10cSrcweir                                             XControlAccess.class,
262*cdf0e10cSrcweir                                             xTextDoc.getCurrentController());
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         try {
265*cdf0e10cSrcweir             columns = (XGridColumnFactory) UnoRuntime.queryInterface(
266*cdf0e10cSrcweir                               XGridColumnFactory.class, the_Model);
267*cdf0e10cSrcweir             aControl = columns.createColumn("TextField");
268*cdf0e10cSrcweir             aControl.setPropertyValue("DataField", "Identifier");
269*cdf0e10cSrcweir             aControl.setPropertyValue("Label", "Identifier");
270*cdf0e10cSrcweir             aControl2 = columns.createColumn("TextField");
271*cdf0e10cSrcweir             aControl2.setPropertyValue("DataField", "Publisher");
272*cdf0e10cSrcweir             aControl2.setPropertyValue("Label", "Publisher");
273*cdf0e10cSrcweir             aControl3 = columns.createColumn("TextField");
274*cdf0e10cSrcweir             aControl3.setPropertyValue("DataField", "Author");
275*cdf0e10cSrcweir             aControl3.setPropertyValue("Label", "Author");
276*cdf0e10cSrcweir             aControl4 = columns.createColumn("TextField");
277*cdf0e10cSrcweir             aControl4.setPropertyValue("DataField", "Title");
278*cdf0e10cSrcweir             aControl4.setPropertyValue("Label", "Title");
279*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
280*cdf0e10cSrcweir             // Some exception occures.FAILED
281*cdf0e10cSrcweir             log.println("!!! Couldn't create instance : " + e);
282*cdf0e10cSrcweir             throw new StatusException("Can't create column instances.", e);
283*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
284*cdf0e10cSrcweir             // Some exception occures.FAILED
285*cdf0e10cSrcweir             log.println("!!! Couldn't create instance : " + e);
286*cdf0e10cSrcweir             throw new StatusException("Can't create column instances.", e);
287*cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
288*cdf0e10cSrcweir             // Some exception occures.FAILED
289*cdf0e10cSrcweir             log.println("!!! Couldn't create instance : " + e);
290*cdf0e10cSrcweir             throw new StatusException("Can't create column instances.", e);
291*cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
292*cdf0e10cSrcweir             // Some exception occures.FAILED
293*cdf0e10cSrcweir             log.println("!!! Couldn't create instance : " + e);
294*cdf0e10cSrcweir             throw new StatusException("Can't create column instances.", e);
295*cdf0e10cSrcweir         }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         XNameContainer aContainer = (XNameContainer) UnoRuntime.queryInterface(
298*cdf0e10cSrcweir                                             XNameContainer.class, the_Model);
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir         try {
301*cdf0e10cSrcweir             aContainer.insertByName("First", aControl);
302*cdf0e10cSrcweir             aContainer.insertByName("Second", aControl2);
303*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
304*cdf0e10cSrcweir             log.println("!!! Could't insert column Instance");
305*cdf0e10cSrcweir             e.printStackTrace(log);
306*cdf0e10cSrcweir             throw new StatusException("Can't insert columns", e);
307*cdf0e10cSrcweir         }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir         //now get the OGridControl
310*cdf0e10cSrcweir         try {
311*cdf0e10cSrcweir             oObj = the_access.getControl(the_Model);
312*cdf0e10cSrcweir             the_win = the_access.getControl(the_Model).getPeer();
313*cdf0e10cSrcweir             the_kit = the_win.getToolkit();
314*cdf0e10cSrcweir             aDevice = the_kit.createScreenCompatibleDevice(200, 200);
315*cdf0e10cSrcweir             aGraphic = aDevice.createGraphics();
316*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
317*cdf0e10cSrcweir             log.println("Couldn't get GridControl");
318*cdf0e10cSrcweir             e.printStackTrace(log);
319*cdf0e10cSrcweir             throw new StatusException("Couldn't get GridControl", e);
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir         // creating another window
324*cdf0e10cSrcweir         aShape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
325*cdf0e10cSrcweir                                               10000, "TextField");
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir         the_Model = aShape.getControl();
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir         //Try to query XControlAccess
333*cdf0e10cSrcweir         the_access = (XControlAccess) UnoRuntime.queryInterface(
334*cdf0e10cSrcweir                              XControlAccess.class,
335*cdf0e10cSrcweir                              xTextDoc.getCurrentController());
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir         //now get the TextControl
338*cdf0e10cSrcweir         XWindow win = null;
339*cdf0e10cSrcweir         Object cntrl = null;
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir         try {
342*cdf0e10cSrcweir             cntrl = the_access.getControl(the_Model);
343*cdf0e10cSrcweir             win = (XWindow) UnoRuntime.queryInterface(XWindow.class, cntrl);
344*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
345*cdf0e10cSrcweir             log.println("Couldn't get Control");
346*cdf0e10cSrcweir             e.printStackTrace(log);
347*cdf0e10cSrcweir             throw new StatusException("Couldn't get Control", e);
348*cdf0e10cSrcweir         }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir         log.println("creating a new environment for object");
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir         //Relations for XSelectionSupplier
356*cdf0e10cSrcweir         tEnv.addObjRelation("Selections",
357*cdf0e10cSrcweir                             new Object[] {
358*cdf0e10cSrcweir             new Object[] { new Integer(0) }, new Object[] { new Integer(1) }
359*cdf0e10cSrcweir         });
360*cdf0e10cSrcweir         tEnv.addObjRelation("Comparer",
361*cdf0e10cSrcweir                             new Comparator() {
362*cdf0e10cSrcweir             public int compare(Object o1, Object o2) {
363*cdf0e10cSrcweir                 return ((Integer) o1).compareTo((Integer)o2);
364*cdf0e10cSrcweir             }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir             public boolean equals(Object obj) {
367*cdf0e10cSrcweir                 return compare(this, obj) == 0;
368*cdf0e10cSrcweir             }
369*cdf0e10cSrcweir         });
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         //Realtion for XContainer
373*cdf0e10cSrcweir         tEnv.addObjRelation("XContainer.Container", aContainer);
374*cdf0e10cSrcweir         tEnv.addObjRelation("INSTANCE", aControl3);
375*cdf0e10cSrcweir         tEnv.addObjRelation("INSTANCE2", aControl4);
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         //Adding ObjRelation for XView
379*cdf0e10cSrcweir         tEnv.addObjRelation("GRAPHICS", aGraphic);
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir         //Adding ObjRelation for XControl
383*cdf0e10cSrcweir         tEnv.addObjRelation("CONTEXT", xTextDoc);
384*cdf0e10cSrcweir         tEnv.addObjRelation("WINPEER", the_win);
385*cdf0e10cSrcweir         tEnv.addObjRelation("TOOLKIT", the_kit);
386*cdf0e10cSrcweir         tEnv.addObjRelation("MODEL", the_Model);
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         // Adding relation for XWindow
390*cdf0e10cSrcweir         tEnv.addObjRelation("XWindow.AnotherWindow", win);
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir         // Adding relation for XDispatch
393*cdf0e10cSrcweir         URL url = new URL();
394*cdf0e10cSrcweir         url.Complete = ".uno:FormSlots/moveToNext";
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir         //url.Complete = ".uno:GridSlots/RowHeight";
398*cdf0e10cSrcweir         //url.Complete = ".uno:GridSlots/RowHeight" ;
399*cdf0e10cSrcweir         tEnv.addObjRelation("XDispatch.URL", url);
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir         log.println("ImplName: " + utils.getImplName(oObj));
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         FormTools.switchDesignOf((XMultiServiceFactory)Param.getMSF(), xTextDoc);
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir         // adding relation for XUpdateBroadcaster
406*cdf0e10cSrcweir         final XInterface ctrl = oObj;
407*cdf0e10cSrcweir         final XLoadable formLoaderF = formLoader;
408*cdf0e10cSrcweir         final XPropertySet ps = (XPropertySet) UnoRuntime.queryInterface(
409*cdf0e10cSrcweir                                         XPropertySet.class, aControl2);
410*cdf0e10cSrcweir         tEnv.addObjRelation("XUpdateBroadcaster.Checker",
411*cdf0e10cSrcweir                             new ifc.form._XUpdateBroadcaster.UpdateChecker() {
412*cdf0e10cSrcweir             private String lastText = "";
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir             public void update() throws com.sun.star.uno.Exception {
415*cdf0e10cSrcweir                 if (!formLoaderF.isLoaded()) {
416*cdf0e10cSrcweir                     formLoaderF.load();
417*cdf0e10cSrcweir                 }
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir                 lastText = "_" + ps.getPropertyValue("Text");
420*cdf0e10cSrcweir                 ps.setPropertyValue("Text", lastText);
421*cdf0e10cSrcweir             }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir             public void commit() throws com.sun.star.sdbc.SQLException {
424*cdf0e10cSrcweir                 XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface(
425*cdf0e10cSrcweir                                                 XBoundComponent.class, ctrl);
426*cdf0e10cSrcweir                 XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface(
427*cdf0e10cSrcweir                                                   XResultSetUpdate.class,
428*cdf0e10cSrcweir                                                   formLoaderF);
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir                 bound.commit();
431*cdf0e10cSrcweir                 update.updateRow();
432*cdf0e10cSrcweir             }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir             public boolean wasCommited() throws com.sun.star.uno.Exception {
435*cdf0e10cSrcweir                 String getS = (String) ps.getPropertyValue("Text");
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir                 return lastText.equals(getS);
438*cdf0e10cSrcweir             }
439*cdf0e10cSrcweir         });
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir         return tEnv;
442*cdf0e10cSrcweir     } // finish method getTestEnvironment
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     public static XControlShape createGrid(XComponent oDoc, int height,
445*cdf0e10cSrcweir                                            int width, int x, int y) {
446*cdf0e10cSrcweir         Size size = new Size();
447*cdf0e10cSrcweir         Point position = new Point();
448*cdf0e10cSrcweir         XControlShape oCShape = null;
449*cdf0e10cSrcweir         XControlModel aControl = null;
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir         //get MSF
452*cdf0e10cSrcweir         XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
453*cdf0e10cSrcweir                                                XMultiServiceFactory.class,
454*cdf0e10cSrcweir                                                oDoc);
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir         try {
457*cdf0e10cSrcweir             Object oInt = oDocMSF.createInstance(
458*cdf0e10cSrcweir                                   "com.sun.star.drawing.ControlShape");
459*cdf0e10cSrcweir             Object aCon = oDocMSF.createInstance(
460*cdf0e10cSrcweir                                   "com.sun.star.form.component.GridControl");
461*cdf0e10cSrcweir             XPropertySet model_props = (XPropertySet) UnoRuntime.queryInterface(
462*cdf0e10cSrcweir                                                XPropertySet.class, aCon);
463*cdf0e10cSrcweir             model_props.setPropertyValue("DefaultControl",
464*cdf0e10cSrcweir                                          "com.sun.star.form.control.InteractionGridControl");
465*cdf0e10cSrcweir             aControl = (XControlModel) UnoRuntime.queryInterface(
466*cdf0e10cSrcweir                                XControlModel.class, aCon);
467*cdf0e10cSrcweir             oCShape = (XControlShape) UnoRuntime.queryInterface(
468*cdf0e10cSrcweir                               XControlShape.class, oInt);
469*cdf0e10cSrcweir             size.Height = height;
470*cdf0e10cSrcweir             size.Width = width;
471*cdf0e10cSrcweir             position.X = x;
472*cdf0e10cSrcweir             position.Y = y;
473*cdf0e10cSrcweir             oCShape.setSize(size);
474*cdf0e10cSrcweir             oCShape.setPosition(position);
475*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
476*cdf0e10cSrcweir             // Some exception occures.FAILED
477*cdf0e10cSrcweir             System.out.println("Couldn't create Grid" + e);
478*cdf0e10cSrcweir             throw new StatusException("Couldn't create Grid", e);
479*cdf0e10cSrcweir         }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir         oCShape.setControl(aControl);
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir         return oCShape;
484*cdf0e10cSrcweir     } // finish createGrid
485*cdf0e10cSrcweir }