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 package ifc.sheet; 24 25 import com.sun.star.sheet.XActivationBroadcaster; 26 import com.sun.star.sheet.XActivationEventListener; 27 import com.sun.star.sheet.XSpreadsheet; 28 import com.sun.star.sheet.XSpreadsheetView; 29 import com.sun.star.uno.UnoRuntime; 30 31 import lib.MultiMethodTest; 32 import lib.Status; 33 import lib.StatusException; 34 35 36 public class _XActivationBroadcaster extends MultiMethodTest { 37 public XActivationBroadcaster oObj; 38 protected boolean listenerCalled = false; 39 protected XSpreadsheetView xSpreadsheetView = null; 40 protected XActivationEventListener listener = null; 41 protected XSpreadsheet two = null; 42 _addActivationEventListener()43 public void _addActivationEventListener() { 44 45 log.println("trying to add an invalid listener"); 46 oObj.addActivationEventListener(listener); 47 log.println(".... OK"); 48 49 log.println("adding a valid listener"); 50 listener = new MyListener(); 51 oObj.addActivationEventListener(listener); 52 53 XSpreadsheet org = xSpreadsheetView.getActiveSheet(); 54 xSpreadsheetView.setActiveSheet(two); 55 56 if (!listenerCalled) { 57 log.println("Listener wasn't called"); 58 } 59 60 xSpreadsheetView.setActiveSheet(org); 61 tRes.tested("addActivationEventListener()", listenerCalled); 62 } 63 _removeActivationEventListener()64 public void _removeActivationEventListener() { 65 requiredMethod("addActivationEventListener()"); 66 listenerCalled = false; 67 oObj.removeActivationEventListener(listener); 68 69 XSpreadsheet org = xSpreadsheetView.getActiveSheet(); 70 xSpreadsheetView.setActiveSheet(two); 71 72 if (listenerCalled) { 73 log.println("Listener was called even though it is removed"); 74 } 75 76 xSpreadsheetView.setActiveSheet(org); 77 tRes.tested("removeActivationEventListener()", !listenerCalled); 78 } 79 before()80 public void before() { 81 xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface( 82 XSpreadsheetView.class, 83 tEnv.getTestObject()); 84 85 two = (XSpreadsheet) tEnv.getObjRelation("Sheet"); 86 87 if ((xSpreadsheetView == null) || (two == null)) { 88 throw new StatusException(Status.failed( 89 "precondition for test is missing")); 90 } 91 } 92 93 protected class MyListener implements XActivationEventListener { activeSpreadsheetChanged(com.sun.star.sheet.ActivationEvent activationEvent)94 public void activeSpreadsheetChanged(com.sun.star.sheet.ActivationEvent activationEvent) { 95 listenerCalled = true; 96 } 97 disposing(com.sun.star.lang.EventObject eventObject)98 public void disposing(com.sun.star.lang.EventObject eventObject) { 99 } 100 } 101 }