1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.sheet;
28 
29 import com.sun.star.sheet.XActivationBroadcaster;
30 import com.sun.star.sheet.XActivationEventListener;
31 import com.sun.star.sheet.XSpreadsheet;
32 import com.sun.star.sheet.XSpreadsheetView;
33 import com.sun.star.uno.UnoRuntime;
34 
35 import lib.MultiMethodTest;
36 import lib.Status;
37 import lib.StatusException;
38 
39 
40 public class _XActivationBroadcaster extends MultiMethodTest {
41     public XActivationBroadcaster oObj;
42     protected boolean listenerCalled = false;
43     protected XSpreadsheetView xSpreadsheetView = null;
44     protected XActivationEventListener listener = null;
45     protected XSpreadsheet two = null;
46 
47     public void _addActivationEventListener() {
48 
49         log.println("trying to add an invalid listener");
50         oObj.addActivationEventListener(listener);
51         log.println(".... OK");
52 
53         log.println("adding a valid listener");
54         listener = new MyListener();
55         oObj.addActivationEventListener(listener);
56 
57         XSpreadsheet org = xSpreadsheetView.getActiveSheet();
58         xSpreadsheetView.setActiveSheet(two);
59 
60         if (!listenerCalled) {
61             log.println("Listener wasn't called");
62         }
63 
64         xSpreadsheetView.setActiveSheet(org);
65         tRes.tested("addActivationEventListener()", listenerCalled);
66     }
67 
68     public void _removeActivationEventListener() {
69         requiredMethod("addActivationEventListener()");
70         listenerCalled = false;
71         oObj.removeActivationEventListener(listener);
72 
73         XSpreadsheet org = xSpreadsheetView.getActiveSheet();
74         xSpreadsheetView.setActiveSheet(two);
75 
76         if (listenerCalled) {
77             log.println("Listener was called eventhough it is removed");
78         }
79 
80         xSpreadsheetView.setActiveSheet(org);
81         tRes.tested("removeActivationEventListener()", !listenerCalled);
82     }
83 
84     public void before() {
85         xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(
86                                    XSpreadsheetView.class,
87                                    tEnv.getTestObject());
88 
89         two = (XSpreadsheet) tEnv.getObjRelation("Sheet");
90 
91         if ((xSpreadsheetView == null) || (two == null)) {
92             throw new StatusException(Status.failed(
93                                               "precondition for test is missing"));
94         }
95     }
96 
97     protected class MyListener implements XActivationEventListener {
98         public void activeSpreadsheetChanged(com.sun.star.sheet.ActivationEvent activationEvent) {
99             listenerCalled = true;
100         }
101 
102         public void disposing(com.sun.star.lang.EventObject eventObject) {
103         }
104     }
105 }