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.document;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.document.XEventBroadcaster;
29 import com.sun.star.document.XEventListener;
30 import com.sun.star.frame.XController;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.uno.UnoRuntime;
33 
34 public class _XEventBroadcaster extends MultiMethodTest {
35 
36     public XEventBroadcaster oObj;
37     protected static boolean listenerCalled=false;
38     private static XEventListener listener=null;
39 
40     public class MyEventListener implements XEventListener {
41 
disposing(com.sun.star.lang.EventObject eventObject)42         public void disposing(com.sun.star.lang.EventObject eventObject) {
43         }
44 
notifyEvent(com.sun.star.document.EventObject eventObject)45         public void notifyEvent(com.sun.star.document.EventObject eventObject) {
46             System.out.println("EventObject "+eventObject.EventName);
47             listenerCalled = true;
48         }
49 
50     }
51 
switchFocus()52     private void switchFocus() {
53         XModel docModel = (XModel) UnoRuntime.queryInterface(
54                 XModel.class,tEnv.getTestObject());
55         docModel.getCurrentController().getFrame().getContainerWindow().setFocus();
56         util.utils.shortWait(1000);
57         XController xc = (XController) UnoRuntime.queryInterface(XController.class,tEnv.getObjRelation("CONT2"));
58         xc.getFrame().getContainerWindow().setFocus();
59     }
60 
_addEventListener()61     public void _addEventListener() {
62         listener = new MyEventListener();
63         listenerCalled = false;
64         oObj.addEventListener(listener);
65         switchFocus();
66         util.utils.shortWait(1000);
67         tRes.tested("addEventListener()",listenerCalled);
68     }
69 
_removeEventListener()70     public void _removeEventListener() {
71         requiredMethod("addEventListener()");
72         listenerCalled = false;
73         oObj.removeEventListener(listener);
74         switchFocus();
75         util.utils.shortWait(1000);
76         tRes.tested("removeEventListener()",!listenerCalled);
77     }
78 
79 }
80