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 mod._sch;
28 
29 import java.io.PrintWriter;
30 
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.AccessibilityTools;
36 import util.SOfficeFactory;
37 import util.utils;
38 
39 import com.sun.star.accessibility.AccessibleRole;
40 import com.sun.star.accessibility.XAccessible;
41 import com.sun.star.accessibility.XAccessibleComponent;
42 import com.sun.star.accessibility.XAccessibleContext;
43 import com.sun.star.awt.XWindow;
44 import com.sun.star.chart.XChartDocument;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 public class AccGrid extends TestCase {
51 
52     XChartDocument xChartDoc = null;
53 
54     protected TestEnvironment createTestEnvironment(
55         TestParameters Param, PrintWriter log) {
56 
57         if (xChartDoc != null) cleanup(Param, log);
58         log.println( "creating a chart document" );
59         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
60         try {
61             log.println( "creating a chartdocument" );
62             xChartDoc = SOF.createChartDoc(null);
63         } catch (com.sun.star.uno.Exception e) {
64             // Some exception occures.FAILED
65             e.printStackTrace( log );
66             throw new StatusException( "Couldn't create document", e );
67         }
68 
69         XInterface oObj = null;
70 
71         XModel aModel = (XModel)
72             UnoRuntime.queryInterface(XModel.class, xChartDoc);
73 
74         AccessibilityTools at = new AccessibilityTools();
75 
76         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
77         XAccessible xRoot = at.getAccessibleObject(xWindow);
78 
79         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
80 
81         XAccessibleContext cont = at.getAccessibleObjectForRole(
82                 xRoot, AccessibleRole.SHAPE, "", "AccGrid");
83 
84 
85         oObj = cont;
86 
87         log.println("ImplementationName " + utils.getImplName(oObj));
88         log.println("AccessibleName " + cont.getAccessibleName());
89 
90         TestEnvironment tEnv = new TestEnvironment(oObj);
91 
92         final XAccessibleComponent acc = (XAccessibleComponent)
93                 UnoRuntime.queryInterface(
94                     XAccessibleComponent.class,oObj);
95         tEnv.addObjRelation("EventProducer",
96             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
97                 public void fireEvent() {
98                         acc.grabFocus();
99                 }
100             });
101 
102         return tEnv;
103 
104     }
105 
106     /**
107     * Called while disposing a <code>TestEnvironment</code>.
108     * Disposes text document.
109     * @param tParam test parameters
110     * @param tEnv the environment to cleanup
111     * @param log writer to log information while testing
112     */
113     protected void cleanup( TestParameters Param, PrintWriter log) {
114         if( xChartDoc!=null ) {
115             log.println( "    closing xChartDoc" );
116             util.DesktopTools.closeDoc(xChartDoc);
117             xChartDoc = null;
118         }
119     }
120 
121 }
122