1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.form; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.awt.XControl; 29cdf0e10cSrcweir import com.sun.star.awt.XWindow; 30cdf0e10cSrcweir import com.sun.star.form.XFormController; 31cdf0e10cSrcweir import com.sun.star.form.XFormControllerListener; 32cdf0e10cSrcweir import com.sun.star.lang.EventObject; 33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * Testing <code>com.sun.star.form.XFormController</code> 37cdf0e10cSrcweir * interface methods : 38cdf0e10cSrcweir * <ul> 39cdf0e10cSrcweir * <li><code> getCurrentControl()</code></li> 40cdf0e10cSrcweir * <li><code> addActivateListener()</code></li> 41cdf0e10cSrcweir * <li><code> removeActivateListener()</code></li> 42cdf0e10cSrcweir * </ul> <p> 43cdf0e10cSrcweir * This test needs the following object relations : 44cdf0e10cSrcweir * <ul> 45cdf0e10cSrcweir * <li> <code>'otherWindow'</code> 46cdf0e10cSrcweir * (of type <code>com.sun.star.awt.XWindow</code>): 47cdf0e10cSrcweir * The another window is used to activate it, causing deactivating 48cdf0e10cSrcweir * of the component tested. </li> 49cdf0e10cSrcweir * <ul> <p> 50cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 51cdf0e10cSrcweir * @see com.sun.star.form.XFormController 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir public class _XFormController extends MultiMethodTest { 54cdf0e10cSrcweir 55cdf0e10cSrcweir public static XFormController oObj = null; 56cdf0e10cSrcweir XWindow otherWind = null; 57cdf0e10cSrcweir 58cdf0e10cSrcweir /** 59cdf0e10cSrcweir * Listener which determines and stores events occured. 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir protected class MyListener implements XFormControllerListener { 62cdf0e10cSrcweir public boolean activated = false ; 63cdf0e10cSrcweir public boolean deactivated = false ; disposing( EventObject oEvent )64cdf0e10cSrcweir public void disposing ( EventObject oEvent ) {} 65cdf0e10cSrcweir init()66cdf0e10cSrcweir public void init() { 67cdf0e10cSrcweir activated = false; 68cdf0e10cSrcweir deactivated = false; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir formActivated(EventObject ev)71cdf0e10cSrcweir public void formActivated(EventObject ev) { 72cdf0e10cSrcweir activated = true ; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir formDeactivated(EventObject ev)75cdf0e10cSrcweir public void formDeactivated(EventObject ev) { 76cdf0e10cSrcweir deactivated = true ; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir MyListener listener = new MyListener() ; 81cdf0e10cSrcweir 82cdf0e10cSrcweir /** 83cdf0e10cSrcweir * Adds a listener, then switches focus between two windows. 84cdf0e10cSrcweir * The current controller must be deactivated and activated.<p> 85cdf0e10cSrcweir * 86cdf0e10cSrcweir * Has <b> OK </b> status if listener <code>deactivate</code> 87cdf0e10cSrcweir * and <code>activate</code> methods was called. <p> 88cdf0e10cSrcweir */ _addActivateListener()89cdf0e10cSrcweir public void _addActivateListener() { 90cdf0e10cSrcweir requiredMethod("getCurrentControl()"); 91cdf0e10cSrcweir oObj.addActivateListener(listener) ; 92cdf0e10cSrcweir 93cdf0e10cSrcweir XWindow wind = (XWindow)UnoRuntime.queryInterface(XWindow.class, cntrl); 94cdf0e10cSrcweir wind.setFocus(); 95cdf0e10cSrcweir shortWait(); 96cdf0e10cSrcweir XWindow otherWind = (XWindow)tEnv.getObjRelation("otherWindow"); 97cdf0e10cSrcweir otherWind.setFocus(); 98cdf0e10cSrcweir shortWait(); 99cdf0e10cSrcweir log.println("activated = " + listener.activated + 100cdf0e10cSrcweir ", deactivated = " + listener.deactivated) ; 101cdf0e10cSrcweir 102cdf0e10cSrcweir tRes.tested("addActivateListener()", 103cdf0e10cSrcweir listener.deactivated && listener.activated) ; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir /** 107cdf0e10cSrcweir * Removes the litener added before, then switches focus between two windows. 108cdf0e10cSrcweir * 109cdf0e10cSrcweir * Has <b> OK </b> status if no listener methods were called. <p> 110cdf0e10cSrcweir */ _removeActivateListener()111cdf0e10cSrcweir public void _removeActivateListener() { 112cdf0e10cSrcweir requiredMethod("addActivateListener()") ; 113cdf0e10cSrcweir 114cdf0e10cSrcweir oObj.removeActivateListener(listener); 115cdf0e10cSrcweir log.println("ActiveListener removed"); 116cdf0e10cSrcweir listener.init(); 117cdf0e10cSrcweir 118cdf0e10cSrcweir XWindow wind = (XWindow)UnoRuntime.queryInterface(XWindow.class, cntrl); 119cdf0e10cSrcweir wind.setFocus(); 120cdf0e10cSrcweir shortWait(); 121cdf0e10cSrcweir XWindow otherWind = (XWindow)tEnv.getObjRelation("otherWindow"); 122cdf0e10cSrcweir otherWind.setFocus(); 123cdf0e10cSrcweir shortWait(); 124cdf0e10cSrcweir log.println("activated = " + listener.activated + 125cdf0e10cSrcweir ", deactivated = " + listener.deactivated) ; 126cdf0e10cSrcweir 127cdf0e10cSrcweir tRes.tested("removeActivateListener()", 128cdf0e10cSrcweir !listener.activated && !listener.deactivated); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir XControl cntrl; 132cdf0e10cSrcweir 133cdf0e10cSrcweir /** 134cdf0e10cSrcweir * Retrieves current control and searches for it among child controls. 135cdf0e10cSrcweir * 136cdf0e10cSrcweir * Has <b>OK</b> status if the current control was found among component 137cdf0e10cSrcweir * children. 138cdf0e10cSrcweir */ _getCurrentControl()139cdf0e10cSrcweir public void _getCurrentControl() { 140cdf0e10cSrcweir cntrl = oObj.getCurrentControl(); 141cdf0e10cSrcweir XControl[] children = oObj.getControls() ; 142cdf0e10cSrcweir 143cdf0e10cSrcweir boolean res = false; 144cdf0e10cSrcweir for(int i = 0; i < children.length; i++) { 145cdf0e10cSrcweir if (children[i].equals(cntrl)) { 146cdf0e10cSrcweir log.println("Current control is equal to the object control" + 147cdf0e10cSrcweir " #" + i + ":"); 148cdf0e10cSrcweir log.println(cntrl); 149cdf0e10cSrcweir res = true; 150cdf0e10cSrcweir break; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir tRes.tested("getCurrentControl()", res) ; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir /** 158cdf0e10cSrcweir * Sleeps for 0.2 sec. to allow StarOffice to react on <code> 159cdf0e10cSrcweir * reset</code> call. 160cdf0e10cSrcweir */ shortWait()161cdf0e10cSrcweir private void shortWait() { 162cdf0e10cSrcweir try { 163cdf0e10cSrcweir Thread.sleep(1000) ; 164cdf0e10cSrcweir } catch (InterruptedException e) { 165cdf0e10cSrcweir System.out.println("While waiting :" + e) ; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170