1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.awt
.XControl
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.form
.XFormController
;
35 import com
.sun
.star
.form
.XFormControllerListener
;
36 import com
.sun
.star
.lang
.EventObject
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
40 * Testing <code>com.sun.star.form.XFormController</code>
43 * <li><code> getCurrentControl()</code></li>
44 * <li><code> addActivateListener()</code></li>
45 * <li><code> removeActivateListener()</code></li>
47 * This test needs the following object relations :
49 * <li> <code>'otherWindow'</code>
50 * (of type <code>com.sun.star.awt.XWindow</code>):
51 * The another window is used to activate it, causing deactivating
52 * of the component tested. </li>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.form.XFormController
57 public class _XFormController
extends MultiMethodTest
{
59 public static XFormController oObj
= null;
60 XWindow otherWind
= null;
63 * Listener which determines and stores events occurred.
65 protected class MyListener
implements XFormControllerListener
{
66 public boolean activated
= false ;
67 public boolean deactivated
= false ;
68 public void disposing ( EventObject oEvent
) {}
75 public void formActivated(EventObject ev
) {
79 public void formDeactivated(EventObject ev
) {
84 MyListener listener
= new MyListener() ;
87 * Adds a listener, then switches focus between two windows.
88 * The current controller must be deactivated and activated.<p>
90 * Has <b> OK </b> status if listener <code>deactivate</code>
91 * and <code>activate</code> methods was called. <p>
93 public void _addActivateListener() {
94 requiredMethod("getCurrentControl()");
95 oObj
.addActivateListener(listener
) ;
97 XWindow wind
= (XWindow
)UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
100 XWindow otherWind
= (XWindow
)tEnv
.getObjRelation("otherWindow");
101 otherWind
.setFocus();
103 log
.println("activated = " + listener
.activated
+
104 ", deactivated = " + listener
.deactivated
) ;
106 tRes
.tested("addActivateListener()",
107 listener
.deactivated
&& listener
.activated
) ;
111 * Removes the litener added before, then switches focus between two windows.
113 * Has <b> OK </b> status if no listener methods were called. <p>
115 public void _removeActivateListener() {
116 requiredMethod("addActivateListener()") ;
118 oObj
.removeActivateListener(listener
);
119 log
.println("ActiveListener removed");
122 XWindow wind
= (XWindow
)UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
125 XWindow otherWind
= (XWindow
)tEnv
.getObjRelation("otherWindow");
126 otherWind
.setFocus();
128 log
.println("activated = " + listener
.activated
+
129 ", deactivated = " + listener
.deactivated
) ;
131 tRes
.tested("removeActivateListener()",
132 !listener
.activated
&& !listener
.deactivated
);
138 * Retrieves current control and searches for it among child controls.
140 * Has <b>OK</b> status if the current control was found among component
143 public void _getCurrentControl() {
144 cntrl
= oObj
.getCurrentControl();
145 XControl
[] children
= oObj
.getControls() ;
148 for(int i
= 0; i
< children
.length
; i
++) {
149 if (children
[i
].equals(cntrl
)) {
150 log
.println("Current control is equal to the object control" +
158 tRes
.tested("getCurrentControl()", res
) ;
162 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
165 private void shortWait() {
168 } catch (InterruptedException e
) {
169 System
.out
.println("While waiting :" + e
) ;