1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFormController.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.awt
.XControl
;
36 import com
.sun
.star
.awt
.XWindow
;
37 import com
.sun
.star
.form
.XFormController
;
38 import com
.sun
.star
.form
.XFormControllerListener
;
39 import com
.sun
.star
.lang
.EventObject
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
43 * Testing <code>com.sun.star.form.XFormController</code>
46 * <li><code> getCurrentControl()</code></li>
47 * <li><code> addActivateListener()</code></li>
48 * <li><code> removeActivateListener()</code></li>
50 * This test needs the following object relations :
52 * <li> <code>'otherWindow'</code>
53 * (of type <code>com.sun.star.awt.XWindow</code>):
54 * The another window is used to activate it, causing deactivating
55 * of the component tested. </li>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.form.XFormController
60 public class _XFormController
extends MultiMethodTest
{
62 public static XFormController oObj
= null;
63 XWindow otherWind
= null;
66 * Listener which determines and stores events occured.
68 protected class MyListener
implements XFormControllerListener
{
69 public boolean activated
= false ;
70 public boolean deactivated
= false ;
71 public void disposing ( EventObject oEvent
) {}
78 public void formActivated(EventObject ev
) {
82 public void formDeactivated(EventObject ev
) {
87 MyListener listener
= new MyListener() ;
90 * Adds a listener, then switches focus between two windows.
91 * The current controller must be deactivated and activated.<p>
93 * Has <b> OK </b> status if listener <code>deactivate</code>
94 * and <code>activate</code> methods was called. <p>
96 public void _addActivateListener() {
97 requiredMethod("getCurrentControl()");
98 oObj
.addActivateListener(listener
) ;
100 XWindow wind
= (XWindow
)UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
103 XWindow otherWind
= (XWindow
)tEnv
.getObjRelation("otherWindow");
104 otherWind
.setFocus();
106 log
.println("activated = " + listener
.activated
+
107 ", deactivated = " + listener
.deactivated
) ;
109 tRes
.tested("addActivateListener()",
110 listener
.deactivated
&& listener
.activated
) ;
114 * Removes the litener added before, then switches focus between two windows.
116 * Has <b> OK </b> status if no listener methods were called. <p>
118 public void _removeActivateListener() {
119 requiredMethod("addActivateListener()") ;
121 oObj
.removeActivateListener(listener
);
122 log
.println("ActiveListener removed");
125 XWindow wind
= (XWindow
)UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
128 XWindow otherWind
= (XWindow
)tEnv
.getObjRelation("otherWindow");
129 otherWind
.setFocus();
131 log
.println("activated = " + listener
.activated
+
132 ", deactivated = " + listener
.deactivated
) ;
134 tRes
.tested("removeActivateListener()",
135 !listener
.activated
&& !listener
.deactivated
);
141 * Retrieves current control and searches for it among child controls.
143 * Has <b>OK</b> status if the current control was found among component
146 public void _getCurrentControl() {
147 cntrl
= oObj
.getCurrentControl();
148 XControl
[] children
= oObj
.getControls() ;
151 for(int i
= 0; i
< children
.length
; i
++) {
152 if (children
[i
].equals(cntrl
)) {
153 log
.println("Current control is equal to the object control" +
161 tRes
.tested("getCurrentControl()", res
) ;
165 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
168 private void shortWait() {
171 } catch (InterruptedException e
) {
172 System
.out
.println("While waiting :" + e
) ;