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