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