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 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.awt
.XControl
;
24 import com
.sun
.star
.awt
.XWindow
;
25 import com
.sun
.star
.form
.XFormController
;
26 import com
.sun
.star
.form
.XFormControllerListener
;
27 import com
.sun
.star
.lang
.EventObject
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
31 * Testing <code>com.sun.star.form.XFormController</code>
34 * <li><code> getCurrentControl()</code></li>
35 * <li><code> addActivateListener()</code></li>
36 * <li><code> removeActivateListener()</code></li>
38 * This test needs the following object relations :
40 * <li> <code>'otherWindow'</code>
41 * (of type <code>com.sun.star.awt.XWindow</code>):
42 * The another window is used to activate it, causing deactivating
43 * of the component tested. </li>
45 * Test is <b> NOT </b> multithread compliant. <p>
46 * @see com.sun.star.form.XFormController
48 public class _XFormController
extends MultiMethodTest
{
50 public static XFormController oObj
= null;
51 XWindow otherWind
= null;
54 * Listener which determines and stores events occurred.
56 protected class MyListener
implements XFormControllerListener
{
57 public boolean activated
= false ;
58 public boolean deactivated
= false ;
59 public void disposing ( EventObject oEvent
) {}
66 public void formActivated(EventObject ev
) {
70 public void formDeactivated(EventObject ev
) {
75 MyListener listener
= new MyListener() ;
78 * Adds a listener, then switches focus between two windows.
79 * The current controller must be deactivated and activated.<p>
81 * Has <b> OK </b> status if listener <code>deactivate</code>
82 * and <code>activate</code> methods was called. <p>
84 public void _addActivateListener() {
85 requiredMethod("getCurrentControl()");
86 oObj
.addActivateListener(listener
) ;
88 XWindow wind
= UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
90 util
.utils
.pause(1000);
91 XWindow otherWind
= (XWindow
)tEnv
.getObjRelation("otherWindow");
93 util
.utils
.pause(1000);
94 log
.println("activated = " + listener
.activated
+
95 ", deactivated = " + listener
.deactivated
) ;
97 tRes
.tested("addActivateListener()",
98 listener
.deactivated
&& listener
.activated
) ;
102 * Removes the listener added before, then switches focus between two windows.
104 * Has <b> OK </b> status if no listener methods were called. <p>
106 public void _removeActivateListener() {
107 requiredMethod("addActivateListener()") ;
109 oObj
.removeActivateListener(listener
);
110 log
.println("ActiveListener removed");
113 XWindow wind
= UnoRuntime
.queryInterface(XWindow
.class, cntrl
);
115 util
.utils
.pause(1000);
116 XWindow otherWind
= (XWindow
)tEnv
.getObjRelation("otherWindow");
117 otherWind
.setFocus();
118 util
.utils
.pause(1000);
119 log
.println("activated = " + listener
.activated
+
120 ", deactivated = " + listener
.deactivated
) ;
122 tRes
.tested("removeActivateListener()",
123 !listener
.activated
&& !listener
.deactivated
);
129 * Retrieves current control and searches for it among child controls.
131 * Has <b>OK</b> status if the current control was found among component
134 public void _getCurrentControl() {
135 cntrl
= oObj
.getCurrentControl();
136 XControl
[] children
= oObj
.getControls() ;
139 for(int i
= 0; i
< children
.length
; i
++) {
140 if (children
[i
].equals(cntrl
)) {
141 log
.println("Current control is equal to the object control" +
149 tRes
.tested("getCurrentControl()", res
) ;